3 * @copy 2012 MinGW.org project
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
24 /* Written by Filip Navara <xnavara@volny.cz> */
27 #pragma GCC system_header
32 * References (2003-08-25):
34 * http://www.winsnmp.com/docs/winsnmp.doc
36 * WinSNMP v2.0 Addendum
37 * http://www.winsnmp.com/docs/winsnmp2.txt
39 * WinSNMP v3.0 API Addendum
40 * http://www.winsnmp.com/docs/winsnmp3.htm
43 * http://msdn.microsoft.com/library/en-us/snmp/snmp/winsnmp_api_reference.asp
51 #define WINSNMPAPI WINAPI
58 #define MAXOBJIDSIZE 128
59 #define MAXOBJIDSTRSIZE 1408
60 #define MAXVENDORINFO 32
62 #ifndef _SNMP_ASN_DEFINED
63 #define _SNMP_ASN_DEFINED
64 #define ASN_UNIVERSAL 0x00
65 #define ASN_PRIMITIVE 0x00
66 #define ASN_CONSTRUCTOR 0x20
67 #define ASN_APPLICATION 0x40
68 #define ASN_CONTEXT 0x80
69 #define ASN_PRIVATE 0xC0
70 #define SNMP_PDU_GET (ASN_CONTEXT | ASN_CONSTRUCTOR | 0)
71 #define SNMP_PDU_GETNEXT (ASN_CONTEXT | ASN_CONSTRUCTOR | 1)
72 #define SNMP_PDU_RESPONSE (ASN_CONTEXT | ASN_CONSTRUCTOR | 2)
73 #define SNMP_PDU_SET (ASN_CONTEXT | ASN_CONSTRUCTOR | 3)
74 #define SNMP_PDU_GETBULK (ASN_CONTEXT | ASN_CONSTRUCTOR | 4)
75 #define SNMP_PDU_V1TRAP (ASN_CONTEXT | ASN_CONSTRUCTOR | 4)
76 #define SNMP_PDU_INFORM (ASN_CONTEXT | ASN_CONSTRUCTOR | 6)
77 #define SNMP_PDU_TRAP (ASN_CONTEXT | ASN_CONSTRUCTOR | 7)
78 #define SNMP_PDU_REPORT (ASN_CONTEXT | ASN_CONSTRUCTOR | 8)
79 #endif /* _SNMP_ASN_DEFINED */
81 #define SNMP_SYNTAX_SEQUENCE (ASN_UNIVERSAL | ASN_CONSTRUCTOR | 0x10)
82 #define SNMP_SYNTAX_INT (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x02)
83 #define SNMP_SYNTAX_BITS (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x03)
84 #define SNMP_SYNTAX_OCTETS (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x04)
85 #define SNMP_SYNTAX_NULL (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x05)
86 #define SNMP_SYNTAX_OID (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x06)
87 #define SNMP_SYNTAX_IPADDR (ASN_APPLICATION | ASN_PRIMITIVE | 0x00)
88 #define SNMP_SYNTAX_CNTR32 (ASN_APPLICATION | ASN_PRIMITIVE | 0x01)
89 #define SNMP_SYNTAX_GAUGE32 (ASN_APPLICATION | ASN_PRIMITIVE | 0x02)
90 #define SNMP_SYNTAX_TIMETICKS (ASN_APPLICATION | ASN_PRIMITIVE | 0x03)
91 #define SNMP_SYNTAX_OPAQUE (ASN_APPLICATION | ASN_PRIMITIVE | 0x04)
92 #define SNMP_SYNTAX_NSAPADDR (ASN_APPLICATION | ASN_PRIMITIVE | 0x05)
93 #define SNMP_SYNTAX_CNTR64 (ASN_APPLICATION | ASN_PRIMITIVE | 0x06)
94 #define SNMP_SYNTAX_UINT32 (ASN_APPLICATION | ASN_PRIMITIVE | 0x07)
95 #define SNMP_SYNTAX_NOSUCHOBJECT (ASN_CONTEXT | ASN_PRIMITIVE | 0x00)
96 #define SNMP_SYNTAX_NOSUCHINSTANCE (ASN_CONTEXT | ASN_PRIMITIVE | 0x01)
97 #define SNMP_SYNTAX_ENDOFMIBVIEW (ASN_CONTEXT | ASN_PRIMITIVE | 0x02)
98 #define SNMP_SYNTAX_INT32 SNMP_SYNTAX_INT
99 #define SNMP_TRAP_COLDSTART 0
100 #define SNMP_TRAP_WARMSTART 1
101 #define SNMP_TRAP_LINKDOWN 2
102 #define SNMP_TRAP_LINKUP 3
103 #define SNMP_TRAP_AUTHFAIL 4
104 #define SNMP_TRAP_EGPNEIGHBORLOSS 5
105 #define SNMP_TRAP_ENTERPRISESPECIFIC 6
106 #define SNMP_ERROR_NOERROR 0
107 #define SNMP_ERROR_TOOBIG 1
108 #define SNMP_ERROR_NOSUCHNAME 2
109 #define SNMP_ERROR_BADVALUE 3
110 #define SNMP_ERROR_READONLY 4
111 #define SNMP_ERROR_GENERR 5
112 #define SNMP_ERROR_NOACCESS 6
113 #define SNMP_ERROR_WRONGTYPE 7
114 #define SNMP_ERROR_WRONGLENGTH 8
115 #define SNMP_ERROR_WRONGENCODING 9
116 #define SNMP_ERROR_WRONGVALUE 10
117 #define SNMP_ERROR_NOCREATION 11
118 #define SNMP_ERROR_INCONSISTENTVALUE 12
119 #define SNMP_ERROR_RESOURCEUNAVAILABLE 13
120 #define SNMP_ERROR_COMMITFAILED 14
121 #define SNMP_ERROR_UNDOFAILED 15
122 #define SNMP_ERROR_AUTHORIZATIONERROR 16
123 #define SNMP_ERROR_NOTWRITABLE 17
124 #define SNMP_ERROR_INCONSISTENTNAME 18
125 #define SNMP_SEC_MODEL_V1 1
126 #define SNMP_SEC_MODEL_V2 2
127 #define SNMP_SEC_MODEL_USM 3
128 #define SNMP_NOAUTH_NOPRIV 0
129 #define SNMP_AUTH_NOPRIV 1
130 #define SNMP_AUTH_PRIV 3
131 #define SNMP_USM_NO_AUTH_PROTOCOL 1
132 #define SNMP_USM_HMACMD5_AUTH_PROTOCOL 2
133 #define SNMP_USM_HMACSHA_AUTH_PROTOCOL 3
134 #define SNMP_USM_NO_PRIV_PROTOCOL 1
135 #define SNMP_USM_DES_PRIV_PROTOCOL 2
136 #define SNMPAPI_TRANSLATED 0
137 #define SNMPAPI_UNTRANSLATED_V1 1
138 #define SNMPAPI_UNTRANSLATED_V2 2
139 #define SNMPAPI_UNTRANSLATED_V3 3
140 #define SNMPAPI_OFF 0
142 #define SNMPAPI_FAILURE 0
143 #define SNMPAPI_SUCCESS 1
144 #define SNMPAPI_NO_SUPPORT 0
145 #define SNMPAPI_V1_SUPPORT 1
146 #define SNMPAPI_V2_SUPPORT 2
147 #define SNMPAPI_M2M_SUPPORT 3
148 #define SNMPAPI_V3_SUPPORT 3
149 #define SNMPAPI_ALLOC_ERROR 2
150 #define SNMPAPI_CONTEXT_INVALID 3
151 #define SNMPAPI_CONTEXT_UNKNOWN 4
152 #define SNMPAPI_ENTITY_INVALID 5
153 #define SNMPAPI_ENTITY_UNKNOWN 6
154 #define SNMPAPI_INDEX_INVALID 7
155 #define SNMPAPI_NOOP 8
156 #define SNMPAPI_OID_INVALID 9
157 #define SNMPAPI_OPERATION_INVALID 10
158 #define SNMPAPI_OUTPUT_TRUNCATED 11
159 #define SNMPAPI_PDU_INVALID 12
160 #define SNMPAPI_SESSION_INVALID 13
161 #define SNMPAPI_SYNTAX_INVALID 14
162 #define SNMPAPI_VBL_INVALID 15
163 #define SNMPAPI_MODE_INVALID 16
164 #define SNMPAPI_SIZE_INVALID 17
165 #define SNMPAPI_NOT_INITIALIZED 18
166 #define SNMPAPI_MESSAGE_INVALID 19
167 #define SNMPAPI_HWND_INVALID 20
168 #define SNMPAPI_ENGINE_INVALID 30
169 #define SNMPAPI_ENGINE_DISCOVERY_FAILED 31
170 #define SNMPAPI_OTHER_ERROR 99
171 #define SNMPAPI_TL_NOT_INITIALIZED 100
172 #define SNMPAPI_TL_NOT_SUPPORTED 101
173 #define SNMPAPI_TL_NOT_AVAILABLE 102
174 #define SNMPAPI_TL_RESOURCE_ERROR 103
175 #define SNMPAPI_TL_UNDELIVERABLE 104
176 #define SNMPAPI_TL_SRC_INVALID 105
177 #define SNMPAPI_TL_INVALID_PARAM 106
178 #define SNMPAPI_TL_IN_USE 107
179 #define SNMPAPI_TL_TIMEOUT 108
180 #define SNMPAPI_TL_PDU_TOO_BIG 109
181 #define SNMPAPI_TL_OTHER 199
182 #define SNMPAPI_RPT_INVALIDMSG 200
183 #define SNMPAPI_RPT_INASNPARSEERR 201
184 #define SNMPAPI_RPT_UNKNOWNSECMODEL 202
185 #define SNMPAPI_RPT_UNKNOWNENGINEID 203
186 #define SNMPAPI_RPT_UNSUPPSECLEVEL 204
187 #define SNMPAPI_RPT_UNKNOWNUSERNAME 205
188 #define SNMPAPI_RPT_WRONGDIGEST 206
189 #define SNMPAPI_RPT_NOTINTIMEWINDOW 207
190 #define SNMPAPI_RPT_DECRYPTIONERROR 208
191 #define SNMPAPI_RPT_OTHER 299
195 typedef HANDLE HSNMP_SESSION, *LPHSNMP_SESSION;
196 typedef HANDLE HSNMP_CONTEXT, *LPHSNMP_CONTEXT;
197 typedef HANDLE HSNMP_VBL, *LPHSNMP_VBL;
198 typedef HANDLE HSNMP_PDU, *LPHSNMP_PDU;
199 typedef HANDLE HSNMP_ENTITY, *LPHSNMP_ENTITY;
200 typedef unsigned char smiBYTE, *smiLPBYTE;
201 typedef signed int smiINT, *smiLPINT;
202 typedef signed int smiINT32, *smiLPINT32;
203 typedef unsigned int smiUINT32, *smiLPUINT32;
204 typedef smiUINT32 smiCNTR32, *smiLPCNTR32;
205 typedef smiUINT32 smiGAUGE32, *smiLPGAUGE32;
206 typedef smiUINT32 smiTIMETICKS, *smiLPTIMETICKS;
207 typedef smiUINT32 SNMPAPI_STATUS;
211 } smiOCTETS, *smiLPOCTETS, smiOPAQUE, *smiLPOPAQUE, smiBITS, *smiLPBITS, smiIPADDR, *smiLPIPADDR, smiNSAPADDR, *smiLPNSAPADDR;
212 typedef const smiLPOCTETS smiLPCOCTETS;
217 typedef const smiLPOID smiLPCOID;
221 } smiCNTR64, *smiLPCNTR64;
232 } smiVALUE, *smiLPVALUE;
233 typedef const smiLPVALUE smiLPCVALUE;
235 CHAR vendorName[MAXVENDORINFO*2];
236 CHAR vendorContact[MAXVENDORINFO*2];
237 CHAR vendorVersionId[MAXVENDORINFO];
238 CHAR vendorVersionDate[MAXVENDORINFO];
239 smiUINT32 vendorEnterprise;
240 } smiVENDORINFO, FAR *smiLPVENDORINFO;
241 typedef SNMPAPI_STATUS (CALLBACK *SNMPAPI_CALLBACK)(HSNMP_SESSION,HWND,UINT,WPARAM,LPARAM,LPVOID);
244 HSNMP_ENTITY hEntity;
245 HSNMP_SESSION hSession;
246 smiUINT32 nTranslateMode;
247 smiUINT32 nSnmpVersion;
248 smiOCTETS dFriendlyName;
249 smiUINT32 nAddressFamily;
250 smiOCTETS dAddressString;
251 smiUINT32 nRequestPort;
252 smiUINT32 nNotificationPort;
253 smiUINT32 nMaxMsgSize;
255 smiUINT32 nEngineBoots;
256 smiUINT32 nEngineTime;
257 smiUINT32 nEngineSeconds;
258 smiUINT32 nRetransmitMode;
259 smiTIMETICKS nPolicyTimeout;
260 smiUINT32 nPolicyRetry;
261 smiTIMETICKS nActualTimeout;
262 smiUINT32 nActualRetry;
263 } smiENTITYINFO, *smiLPENTITYINFO;
266 HSNMP_CONTEXT hContext;
267 HSNMP_SESSION hSession;
268 smiUINT32 nTranslateMode;
269 smiUINT32 nSnmpVersion;
270 smiOCTETS dFriendlyName;
271 smiOCTETS dContextEngineID;
272 smiOCTETS dContextName;
273 smiOCTETS dSecurityName;
274 smiUINT32 nSecurityModel;
275 smiUINT32 nSecurityLevel;
276 smiUINT32 nSecurityAuthProtocol;
277 smiOCTETS dSecurityAuthKey;
278 smiUINT32 nSecurityPrivProtocol;
279 smiOCTETS dSecurityPrivKey;
280 } smiCONTEXTINFO, *smiLPCONTEXTINFO;
282 SNMPAPI_STATUS WINSNMPAPI SnmpCancelMsg(HSNMP_SESSION,smiINT32);
283 SNMPAPI_STATUS WINSNMPAPI SnmpCleanup(VOID);
284 SNMPAPI_STATUS WINSNMPAPI SnmpClose(HSNMP_SESSION);
285 SNMPAPI_STATUS WINSNMPAPI SnmpContextToStr(HSNMP_CONTEXT,smiLPOCTETS);
286 SNMPAPI_STATUS WINSNMPAPI SnmpCountVbl(HSNMP_VBL);
287 HSNMP_PDU WINSNMPAPI SnmpCreatePdu(HSNMP_SESSION,smiINT,smiINT32,smiINT,smiINT,HSNMP_VBL);
288 HSNMP_SESSION WINSNMPAPI SnmpCreateSession(HWND,UINT,SNMPAPI_CALLBACK,LPVOID);
289 HSNMP_VBL WINSNMPAPI SnmpCreateVbl(HSNMP_SESSION,smiLPCOID,smiLPCVALUE);
290 SNMPAPI_STATUS WINSNMPAPI SnmpDecodeMsg(HSNMP_SESSION,LPHSNMP_ENTITY,LPHSNMP_ENTITY,LPHSNMP_CONTEXT,LPHSNMP_PDU,smiLPCOCTETS);
291 SNMPAPI_STATUS WINSNMPAPI SnmpDeleteVb(HSNMP_VBL,smiUINT32);
292 HSNMP_PDU WINSNMPAPI SnmpDuplicatePdu(HSNMP_SESSION,HSNMP_PDU);
293 HSNMP_VBL WINSNMPAPI SnmpDuplicateVbl(HSNMP_SESSION,HSNMP_VBL);
294 SNMPAPI_STATUS WINSNMPAPI SnmpEncodeMsg(HSNMP_SESSION,HSNMP_ENTITY,HSNMP_ENTITY,HSNMP_CONTEXT,HSNMP_PDU,smiLPOCTETS);
295 SNMPAPI_STATUS WINSNMPAPI SnmpEntityToStr(HSNMP_ENTITY,smiUINT32,LPSTR);
296 SNMPAPI_STATUS WINSNMPAPI SnmpFreeContext(HSNMP_CONTEXT);
297 SNMPAPI_STATUS WINSNMPAPI SnmpFreeDescriptor(smiUINT32,smiLPOPAQUE);
298 SNMPAPI_STATUS WINSNMPAPI SnmpFreeEntity(HSNMP_ENTITY);
299 SNMPAPI_STATUS WINSNMPAPI SnmpFreePdu(HSNMP_PDU);
300 SNMPAPI_STATUS WINSNMPAPI SnmpFreeVbl(HSNMP_VBL);
301 SNMPAPI_STATUS WINSNMPAPI SnmpGetLastError(HSNMP_SESSION);
302 SNMPAPI_STATUS WINSNMPAPI SnmpGetPduData(HSNMP_PDU,smiLPINT,smiLPINT32,smiLPINT,smiLPINT,LPHSNMP_VBL);
303 SNMPAPI_STATUS WINSNMPAPI SnmpGetRetransmitMode(smiLPUINT32);
304 SNMPAPI_STATUS WINSNMPAPI SnmpGetRetry(HSNMP_ENTITY,smiLPUINT32,smiLPUINT32);
305 SNMPAPI_STATUS WINSNMPAPI SnmpGetTimeout(HSNMP_ENTITY,smiLPTIMETICKS,smiLPTIMETICKS);
306 SNMPAPI_STATUS WINSNMPAPI SnmpGetTranslateMode(smiLPUINT32);
307 SNMPAPI_STATUS WINSNMPAPI SnmpGetVb(HSNMP_VBL,smiUINT32,smiLPOID,smiLPVALUE);
308 SNMPAPI_STATUS WINSNMPAPI SnmpGetVendorInfo(smiLPVENDORINFO);
309 SNMPAPI_STATUS WINSNMPAPI SnmpListen(HSNMP_ENTITY,SNMPAPI_STATUS);
310 SNMPAPI_STATUS WINSNMPAPI SnmpOidCompare(smiLPCOID,smiLPCOID,smiUINT32,smiLPINT);
311 SNMPAPI_STATUS WINSNMPAPI SnmpOidCopy(smiLPCOID,smiLPOID);
312 SNMPAPI_STATUS WINSNMPAPI SnmpOidToStr(smiLPCOID,smiUINT32,LPSTR);
313 HSNMP_SESSION WINSNMPAPI SnmpOpen(HWND,UINT);
314 SNMPAPI_STATUS WINSNMPAPI SnmpRecvMsg(HSNMP_SESSION,LPHSNMP_ENTITY,LPHSNMP_ENTITY,LPHSNMP_CONTEXT,LPHSNMP_PDU);
315 SNMPAPI_STATUS WINSNMPAPI SnmpRegister(HSNMP_SESSION,HSNMP_ENTITY,HSNMP_ENTITY,HSNMP_CONTEXT,smiLPCOID,smiUINT32);
316 SNMPAPI_STATUS WINSNMPAPI SnmpSendMsg(HSNMP_SESSION,HSNMP_ENTITY,HSNMP_ENTITY,HSNMP_CONTEXT,HSNMP_PDU);
317 SNMPAPI_STATUS WINSNMPAPI SnmpSetPduData(HSNMP_PDU,const smiINT *,const smiINT32 *,const smiINT *,const smiINT *,const HSNMP_VBL *);
318 SNMPAPI_STATUS WINSNMPAPI SnmpSetPort(HSNMP_ENTITY,UINT);
319 SNMPAPI_STATUS WINSNMPAPI SnmpSetRetransmitMode(smiUINT32);
320 SNMPAPI_STATUS WINSNMPAPI SnmpSetRetry(HSNMP_ENTITY,smiUINT32);
321 SNMPAPI_STATUS WINSNMPAPI SnmpSetTimeout(HSNMP_ENTITY,smiTIMETICKS);
322 SNMPAPI_STATUS WINSNMPAPI SnmpSetTranslateMode(smiUINT32);
323 SNMPAPI_STATUS WINSNMPAPI SnmpSetVb(HSNMP_VBL,smiUINT32,smiLPCOID,smiLPCVALUE);
324 SNMPAPI_STATUS WINSNMPAPI SnmpStartup(smiLPUINT32,smiLPUINT32,smiLPUINT32,smiLPUINT32,smiLPUINT32);
325 HSNMP_CONTEXT WINSNMPAPI SnmpStrToContext(HSNMP_SESSION,smiLPCOCTETS);
326 HSNMP_ENTITY WINSNMPAPI SnmpStrToEntity(HSNMP_SESSION,LPCSTR);
327 SNMPAPI_STATUS WINSNMPAPI SnmpStrToOid(LPCSTR,smiLPOID);
328 /* Added in WinSNMP v3.0, not present in some (all?) versions of MS wsnmp32.dll */
329 HSNMP_ENTITY WINSNMPAPI SnmpCreateEntity(HSNMP_SESSION,smiLPENTITYINFO);
330 SNMPAPI_STATUS WINSNMPAPI SnmpGetEntityInfo(HSNMP_ENTITY,smiLPENTITYINFO);
331 SNMPAPI_STATUS WINSNMPAPI SnmpSetEntityInfo(HSNMP_ENTITY,smiLPENTITYINFO);
332 SNMPAPI_STATUS WINSNMPAPI SnmpFreeEntityInfo(smiLPENTITYINFO);
333 HSNMP_CONTEXT WINSNMPAPI SnmpCreateContext(HSNMP_SESSION,smiLPCONTEXTINFO);
334 SNMPAPI_STATUS WINSNMPAPI SnmpGetContextInfo(HSNMP_CONTEXT,smiLPCONTEXTINFO);
335 SNMPAPI_STATUS WINSNMPAPI SnmpSetContextInfo(HSNMP_CONTEXT,smiLPCONTEXTINFO);
336 SNMPAPI_STATUS WINSNMPAPI SnmpFreeContextInfo(smiLPCONTEXTINFO);
337 SNMPAPI_STATUS WINSNMPAPI SnmpPasswordToKey(smiLPOCTETS,smiINT32,smiLPOCTETS);
339 #endif /* RC_INVOKED */