1 /***********************************************************************\ 2 * snmp.d * 3 * * 4 * Windows API header module * 5 * * 6 * Translated from MinGW Windows headers * 7 * by Stewart Gordon * 8 * * 9 * Placed into public domain * 10 \***********************************************************************/ 11 module windows.snmp; 12 nothrow: 13 private import windows.windows; 14 15 // These are not documented on MSDN 16 enum { 17 DEFAULT_SNMP_PORT_UDP = 161, 18 DEFAULT_SNMP_PORT_IPX = 36879, 19 DEFAULT_SNMPTRAP_PORT_UDP = 162, 20 DEFAULT_SNMPTRAP_PORT_IPX = 36880 21 } 22 23 enum : BYTE { 24 ASN_UNIVERSAL = 0x00, 25 ASN_PRIMITIVE = 0x00, 26 ASN_CONSTRUCTOR = 0x20, 27 ASN_APPLICATION = 0x40, 28 ASN_CONTEXT = 0x80, 29 ASN_PRIVATE = 0xC0, 30 31 SNMP_PDU_GET = ASN_CONTEXT | ASN_CONSTRUCTOR, 32 SNMP_PDU_GETNEXT, 33 SNMP_PDU_RESPONSE, 34 SNMP_PDU_SET, 35 SNMP_PDU_GETBULK, // = ASN_CONTEXT | ASN_CONSTRUCTOR | 4 36 SNMP_PDU_V1TRAP = ASN_CONTEXT | ASN_CONSTRUCTOR | 4, 37 SNMP_PDU_INFORM = ASN_CONTEXT | ASN_CONSTRUCTOR | 6, 38 SNMP_PDU_TRAP, 39 SNMP_PDU_REPORT, 40 ASN_INTEGER = ASN_UNIVERSAL | ASN_PRIMITIVE | 2, 41 ASN_BITS, 42 ASN_OCTETSTRING, 43 ASN_NULL, 44 ASN_OBJECTIDENTIFIER, // = ASN_UNIVERSAL | ASN_PRIMITIVE | 6 45 ASN_INTEGER32 = ASN_INTEGER, 46 ASN_SEQUENCE = ASN_UNIVERSAL | ASN_CONSTRUCTOR | 0x10, 47 ASN_SEQUENCEOF = ASN_SEQUENCE, 48 ASN_IPADDRESS = ASN_APPLICATION | ASN_PRIMITIVE, 49 ASN_COUNTER32, 50 ASN_GAUGE32, 51 ASN_TIMETICKS, 52 ASN_OPAQUE, // = ASN_APPLICATION | ASN_PRIMITIVE | 4 53 ASN_COUNTER64 = ASN_APPLICATION | ASN_PRIMITIVE | 6, 54 ASN_UNSIGNED32, // = ASN_APPLICATION | ASN_PRIMITIVE | 7 55 SNMP_EXCEPTION_NOSUCHOBJECT = ASN_CONTEXT | ASN_PRIMITIVE, 56 SNMP_EXCEPTION_NOSUCHINSTANCE, 57 SNMP_EXCEPTION_ENDOFMIBVIEW, 58 SNMP_EXTENSION_GET = SNMP_PDU_GET, 59 SNMP_EXTENSION_GET_NEXT = SNMP_PDU_GETNEXT, 60 SNMP_EXTENSION_GET_BULK = SNMP_PDU_GETBULK, 61 SNMP_EXTENSION_SET_TEST = ASN_PRIVATE | ASN_CONSTRUCTOR, 62 SNMP_EXTENSION_SET_COMMIT = SNMP_PDU_SET, 63 SNMP_EXTENSION_SET_UNDO = ASN_PRIVATE | ASN_CONSTRUCTOR | 1, 64 SNMP_EXTENSION_SET_CLEANUP 65 } 66 67 68 enum : AsnInteger { 69 SNMP_ERRORSTATUS_NOERROR, 70 SNMP_ERRORSTATUS_TOOBIG, 71 SNMP_ERRORSTATUS_NOSUCHNAME, 72 SNMP_ERRORSTATUS_BADVALUE, 73 SNMP_ERRORSTATUS_READONLY, 74 SNMP_ERRORSTATUS_GENERR, 75 SNMP_ERRORSTATUS_NOACCESS, 76 SNMP_ERRORSTATUS_WRONGTYPE, 77 SNMP_ERRORSTATUS_WRONGLENGTH, 78 SNMP_ERRORSTATUS_WRONGENCODING, 79 SNMP_ERRORSTATUS_WRONGVALUE, 80 SNMP_ERRORSTATUS_NOCREATION, 81 SNMP_ERRORSTATUS_INCONSISTENTVALUE, 82 SNMP_ERRORSTATUS_RESOURCEUNAVAILABLE, 83 SNMP_ERRORSTATUS_COMMITFAILED, 84 SNMP_ERRORSTATUS_UNDOFAILED, 85 SNMP_ERRORSTATUS_AUTHORIZATIONERROR, 86 SNMP_ERRORSTATUS_NOTWRITABLE, 87 SNMP_ERRORSTATUS_INCONSISTENTNAME 88 } 89 90 enum : AsnInteger { 91 SNMP_GENERICTRAP_COLDSTART, 92 SNMP_GENERICTRAP_WARMSTART, 93 SNMP_GENERICTRAP_LINKDOWN, 94 SNMP_GENERICTRAP_LINKUP, 95 SNMP_GENERICTRAP_AUTHFAILURE, 96 SNMP_GENERICTRAP_EGPNEIGHLOSS, 97 SNMP_GENERICTRAP_ENTERSPECIFIC 98 } 99 100 // These are not documented on MSDN 101 enum { 102 SNMP_ACCESS_NONE, 103 SNMP_ACCESS_NOTIFY, 104 SNMP_ACCESS_READ_ONLY, 105 SNMP_ACCESS_READ_WRITE, 106 SNMP_ACCESS_READ_CREATE 107 } 108 109 enum : BOOL { 110 SNMPAPI_ERROR = false, 111 SNMPAPI_NOERROR = true 112 } 113 114 enum : INT { 115 SNMP_LOG_SILENT, 116 SNMP_LOG_FATAL, 117 SNMP_LOG_ERROR, 118 SNMP_LOG_WARNING, 119 SNMP_LOG_TRACE, 120 SNMP_LOG_VERBOSE 121 } 122 123 const INT 124 SNMP_OUTPUT_TO_CONSOLE = 1, 125 SNMP_OUTPUT_TO_LOGFILE = 2, 126 SNMP_OUTPUT_TO_EVENTLOG = 4, 127 SNMP_OUTPUT_TO_DEBUGGER = 8; 128 129 const size_t SNMP_MAX_OID_LEN = 128; 130 131 enum : DWORD { 132 SNMP_MEM_ALLOC_ERROR = 1, 133 SNMP_BERAPI_INVALID_LENGTH = 10, 134 SNMP_BERAPI_INVALID_TAG, 135 SNMP_BERAPI_OVERFLOW, 136 SNMP_BERAPI_SHORT_BUFFER, 137 SNMP_BERAPI_INVALID_OBJELEM, 138 SNMP_PDUAPI_UNRECOGNIZED_PDU = 20, 139 SNMP_PDUAPI_INVALID_ES, 140 SNMP_PDUAPI_INVALID_GT, 141 SNMP_AUTHAPI_INVALID_VERSION = 30, 142 SNMP_AUTHAPI_INVALID_MSG_TYPE, 143 SNMP_AUTHAPI_TRIV_AUTH_FAILED, 144 } 145 146 alias INT SNMPAPI; 147 alias LONG AsnInteger32; 148 alias ULONG AsnUnsigned32, AsnCounter32, AsnGauge32, AsnTimeticks; 149 alias ULARGE_INTEGER AsnCounter64; 150 151 align (4): 152 153 struct AsnOctetString { 154 BYTE* stream; 155 UINT length; 156 BOOL dynamic; 157 } 158 alias AsnOctetString AsnBits, AsnSequence, AsnImplicitSequence, 159 AsnIPAddress, AsnNetworkAddress, AsnDisplayString, AsnOpaque; 160 161 struct AsnObjectIdentifier { 162 UINT idLength; 163 UINT* ids; 164 } 165 alias AsnObjectIdentifier AsnObjectName; 166 167 struct AsnAny { 168 BYTE asnType; 169 union _asnValue { 170 AsnInteger32 number; 171 AsnUnsigned32 unsigned32; 172 AsnCounter64 counter64; 173 AsnOctetString string; 174 AsnBits bits; 175 AsnObjectIdentifier object; 176 AsnSequence sequence; 177 AsnIPAddress address; 178 AsnCounter32 counter; 179 AsnGauge32 gauge; 180 AsnTimeticks ticks; 181 AsnOpaque arbitrary; 182 } 183 _asnValue asnValue; 184 } 185 alias AsnAny AsnObjectSyntax; 186 187 struct SnmpVarBind { 188 AsnObjectName name; 189 AsnObjectSyntax value; 190 } 191 192 struct SnmpVarBindList { 193 SnmpVarBind* list; 194 UINT len; 195 } 196 197 extern (Windows) { 198 VOID SnmpExtensionClose(); 199 BOOL SnmpExtensionInit(DWORD, HANDLE*, AsnObjectIdentifier*); 200 BOOL SnmpExtensionInitEx(AsnObjectIdentifier*); 201 BOOL SnmpExtensionMonitor(LPVOID); 202 BOOL SnmpExtensionQuery(BYTE, SnmpVarBindList*, AsnInteger32*, 203 AsnInteger32*); 204 BOOL SnmpExtensionQueryEx(DWORD, DWORD, SnmpVarBindList*, AsnOctetString*, 205 AsnInteger32*, AsnInteger32*); 206 BOOL SnmpExtensionTrap(AsnObjectIdentifier*, AsnInteger32*, AsnInteger32*, 207 AsnTimeticks*, SnmpVarBindList*); 208 DWORD SnmpSvcGetUptime(); 209 VOID SnmpSvcSetLogLevel(INT); 210 VOID SnmpSvcSetLogType(INT); 211 SNMPAPI SnmpUtilAsnAnyCpy(AsnAny*, AsnAny*); 212 VOID SnmpUtilAsnAnyFree(AsnAny*); 213 VOID SnmpUtilDbgPrint(INT, LPSTR, ...); 214 LPSTR SnmpUtilIdsToA(UINT*, UINT); 215 LPVOID SnmpUtilMemAlloc(UINT); 216 VOID SnmpUtilMemFree(LPVOID); 217 LPVOID SnmpUtilMemReAlloc(LPVOID, UINT); 218 SNMPAPI SnmpUtilOctetsCmp(AsnOctetString*, AsnOctetString*); 219 SNMPAPI SnmpUtilOctetsCpy(AsnOctetString*, AsnOctetString*); 220 VOID SnmpUtilOctetsFree(AsnOctetString*); 221 SNMPAPI SnmpUtilOctetsNCmp(AsnOctetString*, AsnOctetString*, UINT); 222 SNMPAPI SnmpUtilOidAppend(AsnObjectIdentifier*, AsnObjectIdentifier*); 223 SNMPAPI SnmpUtilOidCmp(AsnObjectIdentifier*, AsnObjectIdentifier*); 224 SNMPAPI SnmpUtilOidCpy(AsnObjectIdentifier*, AsnObjectIdentifier*); 225 VOID SnmpUtilOidFree(AsnObjectIdentifier*); 226 SNMPAPI SnmpUtilOidNCmp(AsnObjectIdentifier*, AsnObjectIdentifier*, UINT); 227 LPSTR SnmpUtilOidToA(AsnObjectIdentifier*); 228 VOID SnmpUtilPrintAsnAny(AsnAny*); 229 VOID SnmpUtilPrintOid(AsnObjectIdentifier*); 230 SNMPAPI SnmpUtilVarBindCpy(SnmpVarBind*, SnmpVarBind*); 231 SNMPAPI SnmpUtilVarBindListCpy(SnmpVarBindList*, SnmpVarBindList*); 232 VOID SnmpUtilVarBindFree(SnmpVarBind*); 233 VOID SnmpUtilVarBindListFree(SnmpVarBindList*); 234 } 235 236 alias SnmpUtilMemAlloc SNMP_malloc; 237 alias SnmpUtilMemFree SNMP_free; 238 alias SnmpUtilMemReAlloc SNMP_realloc; 239 alias SnmpUtilMemAlloc SNMP_DBG_malloc; 240 alias SnmpUtilMemFree SNMP_DBG_free; 241 alias SnmpUtilMemReAlloc SNMP_DBG_realloc; 242 alias SnmpUtilOidAppend SNMP_oidappend; 243 alias SnmpUtilOidCmp SNMP_oidcmp; 244 alias SnmpUtilOidCpy SNMP_oidcpy; 245 alias SnmpUtilOidFree SNMP_oidfree; 246 alias SnmpUtilOidNCmp SNMP_oidncmp; 247 alias SnmpUtilPrintAsnAny SNMP_printany; 248 alias SnmpUtilVarBindCpy SNMP_CopyVarBind; 249 alias SnmpUtilVarBindListCpy SNMP_CopyVarBindList; 250 alias SnmpUtilVarBindFree SNMP_FreeVarBind; 251 alias SnmpUtilVarBindListFree SNMP_FreeVarBindList; 252 alias ASN_IPADDRESS ASN_RFC1155_IPADDRESS; 253 alias ASN_COUNTER32 ASN_RFC1155_COUNTER; 254 alias ASN_GAUGE32 ASN_RFC1155_GAUGE; 255 alias ASN_TIMETICKS ASN_RFC1155_TIMETICKS; 256 alias ASN_OPAQUE ASN_RFC1155_OPAQUE; 257 alias ASN_OCTETSTRING ASN_RFC1213_DISPSTRING; 258 alias SNMP_PDU_GET ASN_RFC1157_GETREQUEST; 259 alias SNMP_PDU_GETNEXT ASN_RFC1157_GETNEXTREQUEST; 260 alias SNMP_PDU_RESPONSE ASN_RFC1157_GETRESPONSE; 261 alias SNMP_PDU_SET ASN_RFC1157_SETREQUEST; 262 alias SNMP_PDU_V1TRAP ASN_RFC1157_TRAP; 263 alias ASN_CONTEXT ASN_CONTEXTSPECIFIC; 264 alias ASN_PRIMITIVE ASN_PRIMATIVE; 265 alias SnmpVarBindList RFC1157VarBindList; 266 alias SnmpVarBind RFC1157VarBind; 267 alias AsnInteger32 AsnInteger; 268 alias AsnCounter32 AsnCounter; 269 alias AsnGauge32 AsnGauge;