1#![allow(non_camel_case_types,non_snake_case,non_upper_case_globals)]
2extern crate libc;
3
4use std::os::raw;
5use std::sync::{Once, ONCE_INIT};
6
7pub const MAX_OID_LEN: libc::size_t = 128;
8
9pub const STAT_SUCCESS: raw::c_int = 0;
10pub const STAT_ERROR: raw::c_int = 1;
11pub const STAT_TIMEOUT: raw::c_int = 2;
12
13pub const SNMP_VERSION_1: raw::c_long = 0;
14pub const SNMP_VERSION_2c: raw::c_long = 1;
15pub const SNMP_VERSION_3: raw::c_long = 3;
16
17pub const SNMP_SEC_LEVEL_NOAUTH: raw::c_int = 1;
18pub const SNMP_SEC_LEVEL_AUTHNOPRIV: raw::c_int = 2;
19pub const SNMP_SEC_LEVEL_AUTHPRIV: raw::c_int = 3;
20
21pub const SNMP_MSG_GET: raw::c_int = 160;
22pub const SNMP_MSG_GETNEXT: raw::c_int = 161;
23pub const SNMP_MSG_RESPONSE: raw::c_int = 162;
24pub const SNMP_MSG_SET: raw::c_int = 163;
25pub const SNMP_MSG_TRAP: raw::c_int = 164;
26pub const SNMP_MSG_GETBULK: raw::c_int = 165;
27pub const SNMP_MSG_INFORM: raw::c_int = 166;
28pub const SNMP_MSG_TRAP2: raw::c_int = 167;
29pub const SNMP_MSG_REPORT: raw::c_int = 168;
30
31pub const SNMP_NOSUCHOBJECT: raw::c_uchar = (ASN_CONTEXT | ASN_PRIMITIVE | 0x0);
32pub const SNMP_NOSUCHINSTANCE: raw::c_uchar = (ASN_CONTEXT | ASN_PRIMITIVE | 0x1);
33pub const SNMP_ENDOFMIBVIEW: raw::c_uchar = (ASN_CONTEXT | ASN_PRIMITIVE | 0x2);
34
35pub const SNMP_ERR_NOERROR: raw::c_long = 0;
36pub const SNMP_ERR_TOOBIG: raw::c_long = 1;
37pub const SNMP_ERR_NOSUCHNAME: raw::c_long = 2;
38pub const SNMP_ERR_BADVALUE: raw::c_long = 3;
39pub const SNMP_ERR_READONLY: raw::c_long = 4;
40pub const SNMP_ERR_GENERR: raw::c_long = 5;
41pub const SNMP_ERR_NOACCESS: raw::c_long = 6;
42pub const SNMP_ERR_WRONGTYPE: raw::c_long = 7;
43pub const SNMP_ERR_WRONGLENGTH: raw::c_long = 8;
44pub const SNMP_ERR_WRONGENCODING: raw::c_long = 9;
45pub const SNMP_ERR_WRONGVALUE: raw::c_long = 10;
46pub const SNMP_ERR_NOCREATION: raw::c_long = 11;
47pub const SNMP_ERR_INCONSISTENTVALUE: raw::c_long = 12;
48pub const SNMP_ERR_RESOURCEUNAVAILABLE: raw::c_long = 13;
49pub const SNMP_ERR_COMMITFAILED: raw::c_long = 14;
50pub const SNMP_ERR_UNDOFAILED: raw::c_long = 15;
51pub const SNMP_ERR_AUTHORIZATIONERROR: raw::c_long = 16;
52pub const SNMP_ERR_NOTWRITABLE: raw::c_long = 17;
53pub const SNMP_ERR_INCONSISTENTNAME: raw::c_long = 18;
54
55pub const SNMPERR_SUCCESS: raw::c_int = 0; pub const SNMPERR_GENERR: raw::c_int = -1;
57pub const SNMPERR_BAD_LOCPORT: raw::c_int = -2;
58pub const SNMPERR_BAD_ADDRESS: raw::c_int = -3;
59pub const SNMPERR_BAD_SESSION: raw::c_int = -4;
60pub const SNMPERR_TOO_LONG: raw::c_int = -5;
61pub const SNMPERR_NO_SOCKET: raw::c_int = -6;
62pub const SNMPERR_V2_IN_V1: raw::c_int = -7;
63pub const SNMPERR_V1_IN_V2: raw::c_int = -8;
64pub const SNMPERR_BAD_REPEATERS: raw::c_int = -9;
65pub const SNMPERR_BAD_REPETITIONS: raw::c_int = -10;
66pub const SNMPERR_BAD_ASN1_BUILD: raw::c_int = -11;
67pub const SNMPERR_BAD_SENDTO: raw::c_int = -12;
68pub const SNMPERR_BAD_PARSE: raw::c_int = -13;
69pub const SNMPERR_BAD_VERSION: raw::c_int = -14;
70pub const SNMPERR_BAD_SRC_PARTY: raw::c_int = -15;
71pub const SNMPERR_BAD_DST_PARTY: raw::c_int = -16;
72pub const SNMPERR_BAD_CONTEXT: raw::c_int = -17;
73pub const SNMPERR_BAD_COMMUNITY: raw::c_int = -18;
74pub const SNMPERR_NOAUTH_DESPRIV: raw::c_int = -19;
75pub const SNMPERR_BAD_ACL: raw::c_int = -20;
76pub const SNMPERR_BAD_PARTY: raw::c_int = -21;
77pub const SNMPERR_ABORT: raw::c_int = -22;
78pub const SNMPERR_UNKNOWN_PDU: raw::c_int = -23;
79pub const SNMPERR_TIMEOUT: raw::c_int = -24;
80pub const SNMPERR_BAD_RECVFROM: raw::c_int = -25;
81pub const SNMPERR_BAD_ENG_ID: raw::c_int = -26;
82pub const SNMPERR_BAD_SEC_NAME: raw::c_int = -27;
83pub const SNMPERR_BAD_SEC_LEVEL: raw::c_int = -28;
84pub const SNMPERR_ASN_PARSE_ERR: raw::c_int = -29;
85pub const SNMPERR_UNKNOWN_SEC_MODEL: raw::c_int = -30;
86pub const SNMPERR_INVALID_MSG: raw::c_int = -31;
87pub const SNMPERR_UNKNOWN_ENG_ID: raw::c_int = -32;
88pub const SNMPERR_UNKNOWN_USER_NAME: raw::c_int = -33;
89pub const SNMPERR_UNSUPPORTED_SEC_LEVEL: raw::c_int = -34;
90pub const SNMPERR_AUTHENTICATION_FAILURE: raw::c_int = -35;
91pub const SNMPERR_NOT_IN_TIME_WINDOW: raw::c_int = -36;
92pub const SNMPERR_DECRYPTION_ERR: raw::c_int = -37;
93pub const SNMPERR_SC_GENERAL_FAILURE: raw::c_int = -38;
94pub const SNMPERR_SC_NOT_CONFIGURED: raw::c_int = -39;
95pub const SNMPERR_KT_NOT_AVAILABLE: raw::c_int = -40;
96pub const SNMPERR_UNKNOWN_REPORT: raw::c_int = -41;
97pub const SNMPERR_USM_GENERICERROR: raw::c_int = -42;
98pub const SNMPERR_USM_UNKNOWNSECURITYNAME: raw::c_int = -43;
99pub const SNMPERR_USM_UNSUPPORTEDSECURITYLEVEL: raw::c_int = -44;
100pub const SNMPERR_USM_ENCRYPTIONERROR: raw::c_int = -45;
101pub const SNMPERR_USM_AUTHENTICATIONFAILURE: raw::c_int = -46;
102pub const SNMPERR_USM_PARSEERROR: raw::c_int = -47;
103pub const SNMPERR_USM_UNKNOWNENGINEID: raw::c_int = -48;
104pub const SNMPERR_USM_NOTINTIMEWINDOW: raw::c_int = -49;
105pub const SNMPERR_USM_DECRYPTIONERROR: raw::c_int = -50;
106pub const SNMPERR_NOMIB: raw::c_int = -51;
107pub const SNMPERR_RANGE: raw::c_int = -52;
108pub const SNMPERR_MAX_SUBID: raw::c_int = -53;
109pub const SNMPERR_BAD_SUBID: raw::c_int = -54;
110pub const SNMPERR_LONG_OID: raw::c_int = -55;
111pub const SNMPERR_BAD_NAME: raw::c_int = -56;
112pub const SNMPERR_VALUE: raw::c_int = -57;
113pub const SNMPERR_UNKNOWN_OBJID: raw::c_int = -58;
114pub const SNMPERR_NULL_PDU: raw::c_int = -59;
115pub const SNMPERR_NO_VARS: raw::c_int = -60;
116pub const SNMPERR_VAR_TYPE: raw::c_int = -61;
117pub const SNMPERR_MALLOC: raw::c_int = -62;
118pub const SNMPERR_KRB5: raw::c_int = -63;
119pub const SNMPERR_PROTOCOL: raw::c_int = -64;
120pub const SNMPERR_OID_NONINCREASING: raw::c_int = -65;
121pub const SNMPERR_JUST_A_CONTEXT_PROBE: raw::c_int = -66;
122pub const SNMPERR_TRANSPORT_NO_CONFIG: raw::c_int = -67;
123pub const SNMPERR_TRANSPORT_CONFIG_ERROR: raw::c_int = -68;
124pub const SNMPERR_TLS_NO_CERTIFICATE: raw::c_int = -69;
125pub const SNMPERR_MAX: raw::c_int = -69;
126
127pub const ASN_BOOLEAN: raw::c_uchar = 0x01;
128pub const ASN_INTEGER: raw::c_uchar = 0x02;
129pub const ASN_BIT_STR: raw::c_uchar = 0x03;
130pub const ASN_OCTET_STR: raw::c_uchar = 0x04;
131pub const ASN_NULL: raw::c_uchar = 0x05;
132pub const ASN_OBJECT_ID: raw::c_uchar = 0x06;
133pub const ASN_SEQUENCE: raw::c_uchar = 0x10;
134pub const ASN_SET: raw::c_uchar = 0x11;
135pub const ASN_UNIVERSAL: raw::c_uchar = 0x00;
136pub const ASN_APPLICATION: raw::c_uchar = 0x40;
137pub const ASN_CONTEXT: raw::c_uchar = 0x80;
138pub const ASN_PRIVATE: raw::c_uchar = 0xC0;
139pub const ASN_PRIMITIVE: raw::c_uchar = 0x00;
140pub const ASN_CONSTRUCTOR: raw::c_uchar = 0x20;
141
142pub const ASN_IPADDRESS: raw::c_uchar = (ASN_APPLICATION | 0);
143pub const ASN_COUNTER: raw::c_uchar = (ASN_APPLICATION | 1);
144pub const ASN_GAUGE: raw::c_uchar = (ASN_APPLICATION | 2);
145pub const ASN_UNSIGNED: raw::c_uchar = (ASN_APPLICATION | 2); pub const ASN_TIMETICKS: raw::c_uchar = (ASN_APPLICATION | 3);
147pub const ASN_OPAQUE: raw::c_uchar = (ASN_APPLICATION | 4); pub const ASN_NSAP: raw::c_uchar = (ASN_APPLICATION | 5); pub const ASN_COUNTER64: raw::c_uchar = (ASN_APPLICATION | 6);
150pub const ASN_UINTEGER: raw::c_uchar = (ASN_APPLICATION | 7); pub const ASN_FLOAT: raw::c_uchar = (ASN_APPLICATION | 8);
152pub const ASN_DOUBLE: raw::c_uchar = (ASN_APPLICATION | 9);
153pub const ASN_INTEGER64: raw::c_uchar = (ASN_APPLICATION | 10);
154pub const ASN_UNSIGNED64: raw::c_uchar = (ASN_APPLICATION | 11);
155
156pub const USM_AUTH_KU_LEN: usize = 32;
157pub const USM_PRIV_KU_LEN: usize = 32;
158
159mod auto;
160pub use auto::*;
161
162static INIT: Once = ONCE_INIT;
163
164pub fn init(typ: &[u8]) {
165 let mut type_dup = [0u8; 256];
166 type_dup[..typ.len()].clone_from_slice(typ);
167 unsafe {
168 INIT.call_once(||{
169 init_snmp(type_dup.as_ptr() as *mut raw::c_char);
170 netsnmp_init_mib();
171 })
172 }
173}
174
175#[cfg(test)]
176mod tests;