Skip to content

Commit

Permalink
refactored in concern of #33 PR
Browse files Browse the repository at this point in the history
  • Loading branch information
Deer-WarLord committed Jun 21, 2023
1 parent 569c934 commit ac70602
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions pynetsnmp/netsnmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,22 @@ class netsnmp_transport(Structure):
pass


# +++ types.h
class netsnmp_trap_stats(Structure):
_fields_ = [
("sent_count", c_ulong),
("sent_last_sent", c_ulong),
("sent_fail_count", c_ulong),
("sent_last_fail", c_ulong),
("ack_count", c_ulong),
("ack_last_rcvd", c_ulong),
("sec_err_count", c_ulong),
("sec_err_last", c_ulong),
("timeouts", c_ulong),
("sent_last_timeout", c_ulong),
]


# --- types.h int (*netsnmp_callback) (int, netsnmp_session *, int, netsnmp_pdu *, void *);
# the first argument is self ??? Without it, callback function throws an error with not enough args, 4 from 5
netsnmp_callback = CFUNCTYPE(
Expand All @@ -177,6 +193,8 @@ class netsnmp_transport(Structure):
localname = []
paramName = []
transportConfig = []
trapStats = []
msgMaxSize = []
if float_version < 5.099:
raise ImportError("netsnmp version 5.1 or greater is required")
if float_version > 5.199:
Expand All @@ -198,6 +216,14 @@ class netsnmp_container_s(Structure):
transportConfig = [
("transport_configuration", POINTER(netsnmp_container_s))
]
if _netsnmp_str_version >= ('5','8'):
# Version >= 5.8 broke binary compatibility, adding the trap_stats member to the netsnmp_session struct
trapStats = [('trap_stats', POINTER(netsnmp_trap_stats))]
# Version >= 5.8 broke binary compatibility, adding the msgMaxSize member to the snmp_pdu struct
msgMaxSize = [('msgMaxSize', c_long)]
# Version >= 5.8 broke binary compatibility, doubling the size of these constants used for struct sizes
USM_AUTH_KU_LEN = 64
USM_PRIV_KU_LEN = 64


SNMP_VERSION_MAP = {
Expand All @@ -211,7 +237,7 @@ class netsnmp_container_s(Structure):
}


# Version +++ types.h
# Version --- types.h
netsnmp_session._fields_ = (
[
("version", c_long),
Expand Down Expand Up @@ -262,7 +288,7 @@ class netsnmp_container_s(Structure):
("securityModel", c_int),
("securityLevel", c_int),
]
+ paramName
+ paramName + trapStats
+ [
("securityInfo", c_void_p),
]
Expand Down Expand Up @@ -327,7 +353,7 @@ class netsnmp_variable_list(Structure):
("securityModel", c_int),
("securityLevel", c_int),
("msgParseModel", c_int),
("msgMaxSize", c_long),
] + msgMaxSize + [
("transport_data", c_void_p),
("transport_data_length", c_int),
("tDomain", POINTER(oid)),
Expand Down

0 comments on commit ac70602

Please sign in to comment.