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.
26 #pragma GCC system_header
31 * References (2003-08-25):
33 * http://www.winsnmp.com/docs/winsnmp.doc
35 * WinSNMP v2.0 Addendum
36 * http://www.winsnmp.com/docs/winsnmp2.txt
38 * WinSNMP v3.0 API Addendum
39 * http://www.winsnmp.com/docs/winsnmp3.htm
42 * http://msdn.microsoft.com/library/en-us/snmp/snmp/winsnmp_api_reference.asp
50 #define WINSNMPAPI WINAPI
57 #define MAXOBJIDSIZE 128
58 #define MAXOBJIDSTRSIZE 1408
59 #define MAXVENDORINFO 32
61 #ifndef _SNMP_ASN_DEFINED
62 #define _SNMP_ASN_DEFINED
63 #define ASN_UNIVERSAL 0x00
64 #define ASN_PRIMITIVE 0x00
65 #define ASN_CONSTRUCTOR 0x20
66 #define ASN_APPLICATION 0x40
67 #define ASN_CONTEXT 0x80
68 #define ASN_PRIVATE 0xC0
69 #define SNMP_PDU_GET (ASN_CONTEXT | ASN_CONSTRUCTOR | 0)
70 #define SNMP_PDU_GETNEXT (ASN_CONTEXT | ASN_CONSTRUCTOR | 1)
71 #define SNMP_PDU_RESPONSE (ASN_CONTEXT | ASN_CONSTRUCTOR | 2)
72 #define SNMP_PDU_SET (ASN_CONTEXT | ASN_CONSTRUCTOR | 3)
73 #define SNMP_PDU_GETBULK (ASN_CONTEXT | ASN_CONSTRUCTOR | 4)
74 #define SNMP_PDU_V1TRAP (ASN_CONTEXT | ASN_CONSTRUCTOR | 4)
75 #define SNMP_PDU_INFORM (ASN_CONTEXT | ASN_CONSTRUCTOR | 6)
76 #define SNMP_PDU_TRAP (ASN_CONTEXT | ASN_CONSTRUCTOR | 7)
77 #define SNMP_PDU_REPORT (ASN_CONTEXT | ASN_CONSTRUCTOR | 8)
78 #endif /* _SNMP_ASN_DEFINED */
80 #define SNMP_SYNTAX_SEQUENCE (ASN_UNIVERSAL | ASN_CONSTRUCTOR | 0x10)
81 #define SNMP_SYNTAX_INT (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x02)
82 #define SNMP_SYNTAX_BITS (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x03)
83 #define SNMP_SYNTAX_OCTETS (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x04)
84 #define SNMP_SYNTAX_NULL (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x05)
85 #define SNMP_SYNTAX_OID (ASN_UNIVERSAL | ASN_PRIMITIVE | 0x06)
86 #define SNMP_SYNTAX_IPADDR (ASN_APPLICATION | ASN_PRIMITIVE | 0x00)
87 #define SNMP_SYNTAX_CNTR32 (ASN_APPLICATION | ASN_PRIMITIVE | 0x01)
88 #define SNMP_SYNTAX_GAUGE32 (ASN_APPLICATION | ASN_PRIMITIVE | 0x02)
89 #define SNMP_SYNTAX_TIMETICKS (ASN_APPLICATION | ASN_PRIMITIVE | 0x03)
90 #define SNMP_SYNTAX_OPAQUE (ASN_APPLICATION | ASN_PRIMITIVE | 0x04)
91 #define SNMP_SYNTAX_NSAPADDR (ASN_APPLICATION | ASN_PRIMITIVE | 0x05)
92 #define SNMP_SYNTAX_CNTR64 (ASN_APPLICATION | ASN_PRIMITIVE | 0x06)
93 #define SNMP_SYNTAX_UINT32 (ASN_APPLICATION | ASN_PRIMITIVE | 0x07)
94 #define SNMP_SYNTAX_NOSUCHOBJECT (ASN_CONTEXT | ASN_PRIMITIVE | 0x00)
95 #define SNMP_SYNTAX_NOSUCHINSTANCE (ASN_CONTEXT | ASN_PRIMITIVE | 0x01)
96 #define SNMP_SYNTAX_ENDOFMIBVIEW (ASN_CONTEXT | ASN_PRIMITIVE | 0x02)
97 #define SNMP_SYNTAX_INT32 SNMP_SYNTAX_INT
98 #define SNMP_TRAP_COLDSTART 0
99 #define SNMP_TRAP_WARMSTART 1
100 #define SNMP_TRAP_LINKDOWN 2
101 #define SNMP_TRAP_LINKUP 3
102 #define SNMP_TRAP_AUTHFAIL 4
103 #define SNMP_TRAP_EGPNEIGHBORLOSS 5
104 #define SNMP_TRAP_ENTERPRISESPECIFIC 6
105 #define SNMP_ERROR_NOERROR 0
106 #define SNMP_ERROR_TOOBIG 1
107 #define SNMP_ERROR_NOSUCHNAME 2
108 #define SNMP_ERROR_BADVALUE 3
109 #define SNMP_ERROR_READONLY 4
110 #define SNMP_ERROR_GENERR 5
111 #define SNMP_ERROR_NOACCESS 6
112 #define SNMP_ERROR_WRONGTYPE 7
113 #define SNMP_ERROR_WRONGLENGTH 8
114 #define SNMP_ERROR_WRONGENCODING 9
115 #define SNMP_ERROR_WRONGVALUE 10
116 #define SNMP_ERROR_NOCREATION 11
117 #define SNMP_ERROR_INCONSISTENTVALUE 12
118 #define SNMP_ERROR_RESOURCEUNAVAILABLE 13
119 #define SNMP_ERROR_COMMITFAILED 14
120 #define SNMP_ERROR_UNDOFAILED 15
121 #define SNMP_ERROR_AUTHORIZATIONERROR 16
122 #define SNMP_ERROR_NOTWRITABLE 17
123 #define SNMP_ERROR_INCONSISTENTNAME 18
124 #define SNMP_SEC_MODEL_V1 1
125 #define SNMP_SEC_MODEL_V2 2
126 #define SNMP_SEC_MODEL_USM 3
127 #define SNMP_NOAUTH_NOPRIV 0
128 #define SNMP_AUTH_NOPRIV 1
129 #define SNMP_AUTH_PRIV 3
130 #define SNMP_USM_NO_AUTH_PROTOCOL 1
131 #define SNMP_USM_HMACMD5_AUTH_PROTOCOL 2
132 #define SNMP_USM_HMACSHA_AUTH_PROTOCOL 3
133 #define SNMP_USM_NO_PRIV_PROTOCOL 1
134 #define SNMP_USM_DES_PRIV_PROTOCOL 2
135 #define SNMPAPI_TRANSLATED 0
136 #define SNMPAPI_UNTRANSLATED_V1 1
137 #define SNMPAPI_UNTRANSLATED_V2 2
138 #define SNMPAPI_UNTRANSLATED_V3 3
139 #define SNMPAPI_OFF 0
141 #define SNMPAPI_FAILURE 0
142 #define SNMPAPI_SUCCESS 1
143 #define SNMPAPI_NO_SUPPORT 0
144 #define SNMPAPI_V1_SUPPORT 1
145 #define SNMPAPI_V2_SUPPORT 2
146 #define SNMPAPI_M2M_SUPPORT 3
147 #define SNMPAPI_V3_SUPPORT 3
148 #define SNMPAPI_ALLOC_ERROR 2
149 #define SNMPAPI_CONTEXT_INVALID 3
150 #define SNMPAPI_CONTEXT_UNKNOWN 4
151 #define SNMPAPI_ENTITY_INVALID 5
152 #define SNMPAPI_ENTITY_UNKNOWN 6
153 #define SNMPAPI_INDEX_INVALID 7
154 #define SNMPAPI_NOOP 8
155 #define SNMPAPI_OID_INVALID 9
156 #define SNMPAPI_OPERATION_INVALID 10
157 #define SNMPAPI_OUTPUT_TRUNCATED 11
158 #define SNMPAPI_PDU_INVALID 12
159 #define SNMPAPI_SESSION_INVALID 13
160 #define SNMPAPI_SYNTAX_INVALID 14
161 #define SNMPAPI_VBL_INVALID 15
162 #define SNMPAPI_MODE_INVALID 16
163 #define SNMPAPI_SIZE_INVALID 17
164 #define SNMPAPI_NOT_INITIALIZED 18
165 #define SNMPAPI_MESSAGE_INVALID 19
166 #define SNMPAPI_HWND_INVALID 20
167 #define SNMPAPI_ENGINE_INVALID 30
168 #define SNMPAPI_ENGINE_DISCOVERY_FAILED 31
169 #define SNMPAPI_OTHER_ERROR 99
170 #define SNMPAPI_TL_NOT_INITIALIZED 100
171 #define SNMPAPI_TL_NOT_SUPPORTED 101
172 #define SNMPAPI_TL_NOT_AVAILABLE 102
173 #define SNMPAPI_TL_RESOURCE_ERROR 103
174 #define SNMPAPI_TL_UNDELIVERABLE 104
175 #define SNMPAPI_TL_SRC_INVALID 105
176 #define SNMPAPI_TL_INVALID_PARAM 106
177 #define SNMPAPI_TL_IN_USE 107
178 #define SNMPAPI_TL_TIMEOUT 108
179 #define SNMPAPI_TL_PDU_TOO_BIG 109
180 #define SNMPAPI_TL_OTHER 199
181 #define SNMPAPI_RPT_INVALIDMSG 200
182 #define SNMPAPI_RPT_INASNPARSEERR 201
183 #define SNMPAPI_RPT_UNKNOWNSECMODEL 202
184 #define SNMPAPI_RPT_UNKNOWNENGINEID 203
185 #define SNMPAPI_RPT_UNSUPPSECLEVEL 204
186 #define SNMPAPI_RPT_UNKNOWNUSERNAME 205
187 #define SNMPAPI_RPT_WRONGDIGEST 206
188 #define SNMPAPI_RPT_NOTINTIMEWINDOW 207
189 #define SNMPAPI_RPT_DECRYPTIONERROR 208
190 #define SNMPAPI_RPT_OTHER 299
194 typedef HANDLE HSNMP_SESSION, *LPHSNMP_SESSION;
195 typedef HANDLE HSNMP_CONTEXT, *LPHSNMP_CONTEXT;
196 typedef HANDLE HSNMP_VBL, *LPHSNMP_VBL;
197 typedef HANDLE HSNMP_PDU, *LPHSNMP_PDU;
198 typedef HANDLE HSNMP_ENTITY, *LPHSNMP_ENTITY;
199 typedef unsigned char smiBYTE, *smiLPBYTE;
200 typedef signed int smiINT, *smiLPINT;
201 typedef signed int smiINT32, *smiLPINT32;
202 typedef unsigned int smiUINT32, *smiLPUINT32;
203 typedef smiUINT32 smiCNTR32, *smiLPCNTR32;
204 typedef smiUINT32 smiGAUGE32, *smiLPGAUGE32;
205 typedef smiUINT32 smiTIMETICKS, *smiLPTIMETICKS;
206 typedef smiUINT32 SNMPAPI_STATUS;
210 } smiOCTETS, *smiLPOCTETS, smiOPAQUE, *smiLPOPAQUE, smiBITS, *smiLPBITS, smiIPADDR, *smiLPIPADDR, smiNSAPADDR, *smiLPNSAPADDR;
211 typedef const smiLPOCTETS smiLPCOCTETS;
216 typedef const smiLPOID smiLPCOID;
220 } smiCNTR64, *smiLPCNTR64;
231 } smiVALUE, *smiLPVALUE;
232 typedef const smiLPVALUE smiLPCVALUE;
234 CHAR vendorName[MAXVENDORINFO*2];
235 CHAR vendorContact[MAXVENDORINFO*2];
236 CHAR vendorVersionId[MAXVENDORINFO];
237 CHAR vendorVersionDate[MAXVENDORINFO];
238 smiUINT32 vendorEnterprise;
239 } smiVENDORINFO, FAR *smiLPVENDORINFO;
240 typedef SNMPAPI_STATUS (CALLBACK *SNMPAPI_CALLBACK)(HSNMP_SESSION,HWND,UINT,WPARAM,LPARAM,LPVOID);
243 HSNMP_ENTITY hEntity;
244 HSNMP_SESSION hSession;
245 smiUINT32 nTranslateMode;
246 smiUINT32 nSnmpVersion;
247 smiOCTETS dFriendlyName;
248 smiUINT32 nAddressFamily;
249 smiOCTETS dAddressString;
250 smiUINT32 nRequestPort;
251 smiUINT32 nNotificationPort;
252 smiUINT32 nMaxMsgSize;
254 smiUINT32 nEngineBoots;
255 smiUINT32 nEngineTime;
256 smiUINT32 nEngineSeconds;
257 smiUINT32 nRetransmitMode;
258 smiTIMETICKS nPolicyTimeout;
259 smiUINT32 nPolicyRetry;
260 smiTIMETICKS nActualTimeout;
261 smiUINT32 nActualRetry;
262 } smiENTITYINFO, *smiLPENTITYINFO;
265 HSNMP_CONTEXT hContext;
266 HSNMP_SESSION hSession;
267 smiUINT32 nTranslateMode;
268 smiUINT32 nSnmpVersion;
269 smiOCTETS dFriendlyName;
270 smiOCTETS dContextEngineID;
271 smiOCTETS dContextName;
272 smiOCTETS dSecurityName;
273 smiUINT32 nSecurityModel;
274 smiUINT32 nSecurityLevel;
275 smiUINT32 nSecurityAuthProtocol;
276 smiOCTETS dSecurityAuthKey;
277 smiUINT32 nSecurityPrivProtocol;
278 smiOCTETS dSecurityPrivKey;
279 } smiCONTEXTINFO, *smiLPCONTEXTINFO;
281 SNMPAPI_STATUS WINSNMPAPI SnmpCancelMsg(HSNMP_SESSION,smiINT32);
282 SNMPAPI_STATUS WINSNMPAPI SnmpCleanup(VOID);
283 SNMPAPI_STATUS WINSNMPAPI SnmpClose(HSNMP_SESSION);
284 SNMPAPI_STATUS WINSNMPAPI SnmpContextToStr(HSNMP_CONTEXT,smiLPOCTETS);
285 SNMPAPI_STATUS WINSNMPAPI SnmpCountVbl(HSNMP_VBL);
286 HSNMP_PDU WINSNMPAPI SnmpCreatePdu(HSNMP_SESSION,smiINT,smiINT32,smiINT,smiINT,HSNMP_VBL);
287 HSNMP_SESSION WINSNMPAPI SnmpCreateSession(HWND,UINT,SNMPAPI_CALLBACK,LPVOID);
288 HSNMP_VBL WINSNMPAPI SnmpCreateVbl(HSNMP_SESSION,smiLPCOID,smiLPCVALUE);
289 SNMPAPI_STATUS WINSNMPAPI SnmpDecodeMsg(HSNMP_SESSION,LPHSNMP_ENTITY,LPHSNMP_ENTITY,LPHSNMP_CONTEXT,LPHSNMP_PDU,smiLPCOCTETS);
290 SNMPAPI_STATUS WINSNMPAPI SnmpDeleteVb(HSNMP_VBL,smiUINT32);
291 HSNMP_PDU WINSNMPAPI SnmpDuplicatePdu(HSNMP_SESSION,HSNMP_PDU);
292 HSNMP_VBL WINSNMPAPI SnmpDuplicateVbl(HSNMP_SESSION,HSNMP_VBL);
293 SNMPAPI_STATUS WINSNMPAPI SnmpEncodeMsg(HSNMP_SESSION,HSNMP_ENTITY,HSNMP_ENTITY,HSNMP_CONTEXT,HSNMP_PDU,smiLPOCTETS);
294 SNMPAPI_STATUS WINSNMPAPI SnmpEntityToStr(HSNMP_ENTITY,smiUINT32,LPSTR);
295 SNMPAPI_STATUS WINSNMPAPI SnmpFreeContext(HSNMP_CONTEXT);
296 SNMPAPI_STATUS WINSNMPAPI SnmpFreeDescriptor(smiUINT32,smiLPOPAQUE);
297 SNMPAPI_STATUS WINSNMPAPI SnmpFreeEntity(HSNMP_ENTITY);
298 SNMPAPI_STATUS WINSNMPAPI SnmpFreePdu(HSNMP_PDU);
299 SNMPAPI_STATUS WINSNMPAPI SnmpFreeVbl(HSNMP_VBL);
300 SNMPAPI_STATUS WINSNMPAPI SnmpGetLastError(HSNMP_SESSION);
301 SNMPAPI_STATUS WINSNMPAPI SnmpGetPduData(HSNMP_PDU,smiLPINT,smiLPINT32,smiLPINT,smiLPINT,LPHSNMP_VBL);
302 SNMPAPI_STATUS WINSNMPAPI SnmpGetRetransmitMode(smiLPUINT32);
303 SNMPAPI_STATUS WINSNMPAPI SnmpGetRetry(HSNMP_ENTITY,smiLPUINT32,smiLPUINT32);
304 SNMPAPI_STATUS WINSNMPAPI SnmpGetTimeout(HSNMP_ENTITY,smiLPTIMETICKS,smiLPTIMETICKS);
305 SNMPAPI_STATUS WINSNMPAPI SnmpGetTranslateMode(smiLPUINT32);
306 SNMPAPI_STATUS WINSNMPAPI SnmpGetVb(HSNMP_VBL,smiUINT32,smiLPOID,smiLPVALUE);
307 SNMPAPI_STATUS WINSNMPAPI SnmpGetVendorInfo(smiLPVENDORINFO);
308 SNMPAPI_STATUS WINSNMPAPI SnmpListen(HSNMP_ENTITY,SNMPAPI_STATUS);
309 SNMPAPI_STATUS WINSNMPAPI SnmpOidCompare(smiLPCOID,smiLPCOID,smiUINT32,smiLPINT);
310 SNMPAPI_STATUS WINSNMPAPI SnmpOidCopy(smiLPCOID,smiLPOID);
311 SNMPAPI_STATUS WINSNMPAPI SnmpOidToStr(smiLPCOID,smiUINT32,LPSTR);
312 HSNMP_SESSION WINSNMPAPI SnmpOpen(HWND,UINT);
313 SNMPAPI_STATUS WINSNMPAPI SnmpRecvMsg(HSNMP_SESSION,LPHSNMP_ENTITY,LPHSNMP_ENTITY,LPHSNMP_CONTEXT,LPHSNMP_PDU);
314 SNMPAPI_STATUS WINSNMPAPI SnmpRegister(HSNMP_SESSION,HSNMP_ENTITY,HSNMP_ENTITY,HSNMP_CONTEXT,smiLPCOID,smiUINT32);
315 SNMPAPI_STATUS WINSNMPAPI SnmpSendMsg(HSNMP_SESSION,HSNMP_ENTITY,HSNMP_ENTITY,HSNMP_CONTEXT,HSNMP_PDU);
316 SNMPAPI_STATUS WINSNMPAPI SnmpSetPduData(HSNMP_PDU,const smiINT *,const smiINT32 *,const smiINT *,const smiINT *,const HSNMP_VBL *);
317 SNMPAPI_STATUS WINSNMPAPI SnmpSetPort(HSNMP_ENTITY,UINT);
318 SNMPAPI_STATUS WINSNMPAPI SnmpSetRetransmitMode(smiUINT32);
319 SNMPAPI_STATUS WINSNMPAPI SnmpSetRetry(HSNMP_ENTITY,smiUINT32);
320 SNMPAPI_STATUS WINSNMPAPI SnmpSetTimeout(HSNMP_ENTITY,smiTIMETICKS);
321 SNMPAPI_STATUS WINSNMPAPI SnmpSetTranslateMode(smiUINT32);
322 SNMPAPI_STATUS WINSNMPAPI SnmpSetVb(HSNMP_VBL,smiUINT32,smiLPCOID,smiLPCVALUE);
323 SNMPAPI_STATUS WINSNMPAPI SnmpStartup(smiLPUINT32,smiLPUINT32,smiLPUINT32,smiLPUINT32,smiLPUINT32);
324 HSNMP_CONTEXT WINSNMPAPI SnmpStrToContext(HSNMP_SESSION,smiLPCOCTETS);
325 HSNMP_ENTITY WINSNMPAPI SnmpStrToEntity(HSNMP_SESSION,LPCSTR);
326 SNMPAPI_STATUS WINSNMPAPI SnmpStrToOid(LPCSTR,smiLPOID);
327 /* Added in WinSNMP v3.0, not present in some (all?) versions of MS wsnmp32.dll */
328 HSNMP_ENTITY WINSNMPAPI SnmpCreateEntity(HSNMP_SESSION,smiLPENTITYINFO);
329 SNMPAPI_STATUS WINSNMPAPI SnmpGetEntityInfo(HSNMP_ENTITY,smiLPENTITYINFO);
330 SNMPAPI_STATUS WINSNMPAPI SnmpSetEntityInfo(HSNMP_ENTITY,smiLPENTITYINFO);
331 SNMPAPI_STATUS WINSNMPAPI SnmpFreeEntityInfo(smiLPENTITYINFO);
332 HSNMP_CONTEXT WINSNMPAPI SnmpCreateContext(HSNMP_SESSION,smiLPCONTEXTINFO);
333 SNMPAPI_STATUS WINSNMPAPI SnmpGetContextInfo(HSNMP_CONTEXT,smiLPCONTEXTINFO);
334 SNMPAPI_STATUS WINSNMPAPI SnmpSetContextInfo(HSNMP_CONTEXT,smiLPCONTEXTINFO);
335 SNMPAPI_STATUS WINSNMPAPI SnmpFreeContextInfo(smiLPCONTEXTINFO);
336 SNMPAPI_STATUS WINSNMPAPI SnmpPasswordToKey(smiLPOCTETS,smiINT32,smiLPOCTETS);
338 #endif /* RC_INVOKED */