home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / sdk / winh / snmp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-11  |  8.8 KB  |  347 lines

  1. /*++
  2.  
  3. Copyright (C) 1992 - 1995 Microsoft Corporation
  4.  
  5. Module Name:
  6.  
  7.     snmp.h
  8.  
  9. Abstract:
  10.  
  11.     Type definitions for SNMP Extension Agent Development.
  12.  
  13. --*/
  14.  
  15. #ifndef snmp_h
  16. #define snmp_h
  17.  
  18. #include <windows.h>
  19.  
  20.  
  21. //
  22. // SNMP API Constant Definitions
  23. //
  24.  
  25. // Purely for code readability
  26. #define IN
  27. #define OUT
  28.  
  29.  
  30. // API return type
  31.  
  32. #define SNMPAPI          int
  33.  
  34. #if (_MSC_VER >= 800) || defined(_STDCALL_SUPPORTED)
  35. #define SNMP_FUNC_TYPE   __stdcall
  36. #else
  37. #define SNMP_FUNC_TYPE
  38. #endif
  39.  
  40.  
  41. // API return codes
  42. #define SNMPAPI_NOERROR TRUE
  43. #define SNMPAPI_ERROR   FALSE
  44.  
  45.  
  46. // class field of BER tag
  47. #define ASN_UNIVERSAL         0x00
  48. #define ASN_APPLICATION       0x40
  49. #define ASN_CONTEXTSPECIFIC   0x80
  50. #define ASN_PRIVATE           0xC0
  51.  
  52. // primative/constructed field of BER tag
  53. #define ASN_PRIMATIVE         0x00
  54. #define ASN_CONSTRUCTOR       0x20
  55.  
  56.  
  57. // ASN.1 simple types
  58. #define ASN_INTEGER           (ASN_UNIVERSAL | ASN_PRIMATIVE | 0x02)
  59. #define ASN_OCTETSTRING       (ASN_UNIVERSAL | ASN_PRIMATIVE | 0x04)
  60. #define ASN_NULL              (ASN_UNIVERSAL | ASN_PRIMATIVE | 0x05)
  61. #define ASN_OBJECTIDENTIFIER  (ASN_UNIVERSAL | ASN_PRIMATIVE | 0x06)
  62.  
  63. // ASN.1 constructor types
  64. #define ASN_SEQUENCE          (ASN_UNIVERSAL | ASN_CONSTRUCTOR | 0x10)
  65. #define ASN_SEQUENCEOF        ASN_SEQUENCE
  66.  
  67. // ASN.1 application specific primatives
  68. #define ASN_RFC1155_IPADDRESS  (ASN_APPLICATION | ASN_PRIMATIVE | 0x00)
  69. #define ASN_RFC1155_COUNTER    (ASN_APPLICATION | ASN_PRIMATIVE | 0x01)
  70. #define ASN_RFC1155_GAUGE      (ASN_APPLICATION | ASN_PRIMATIVE | 0x02)
  71. #define ASN_RFC1155_TIMETICKS  (ASN_APPLICATION | ASN_PRIMATIVE | 0x03)
  72. #define ASN_RFC1155_OPAQUE     (ASN_APPLICATION | ASN_PRIMATIVE | 0x04)
  73. #define ASN_RFC1213_DISPSTRING ASN_OCTETSTRING
  74.  
  75. // ASN.1 application specific constructors
  76. #define ASN_RFC1157_GETREQUEST     \
  77.             (ASN_CONTEXTSPECIFIC | ASN_CONSTRUCTOR | 0x00)
  78. #define ASN_RFC1157_GETNEXTREQUEST \
  79.             (ASN_CONTEXTSPECIFIC | ASN_CONSTRUCTOR | 0x01)
  80. #define ASN_RFC1157_GETRESPONSE    \
  81.             (ASN_CONTEXTSPECIFIC | ASN_CONSTRUCTOR | 0x02)
  82. #define ASN_RFC1157_SETREQUEST     \
  83.             (ASN_CONTEXTSPECIFIC | ASN_CONSTRUCTOR | 0x03)
  84. #define ASN_RFC1157_TRAP           \
  85.             (ASN_CONTEXTSPECIFIC | ASN_CONSTRUCTOR | 0x04)
  86.  
  87.  
  88. // PDU error status
  89. #define SNMP_ERRORSTATUS_NOERROR        0
  90. #define SNMP_ERRORSTATUS_TOOBIG         1
  91. #define SNMP_ERRORSTATUS_NOSUCHNAME     2
  92. #define SNMP_ERRORSTATUS_BADVALUE       3
  93. #define SNMP_ERRORSTATUS_READONLY       4
  94. #define SNMP_ERRORSTATUS_GENERR         5
  95.  
  96.  
  97. // PDU generic traps
  98. #define SNMP_GENERICTRAP_COLDSTART      0
  99. #define SNMP_GENERICTRAP_WARMSTART      1
  100. #define SNMP_GENERICTRAP_LINKDOWN       2
  101. #define SNMP_GENERICTRAP_LINKUP         3
  102. #define SNMP_GENERICTRAP_AUTHFAILURE    4
  103. #define SNMP_GENERICTRAP_EGPNEIGHLOSS   5
  104. #define SNMP_GENERICTRAP_ENTERSPECIFIC  6
  105.  
  106.  
  107.  
  108. //
  109. // SNMP Error codes
  110. //
  111.  
  112. // General error codes
  113. #define SNMP_MEM_ALLOC_ERROR          1
  114.  
  115. // BER API error codes (using Get/Set LastError)
  116. #define SNMP_BERAPI_INVALID_LENGTH    10
  117. #define SNMP_BERAPI_INVALID_TAG       11
  118. #define SNMP_BERAPI_OVERFLOW          12
  119. #define SNMP_BERAPI_SHORT_BUFFER      13
  120. #define SNMP_BERAPI_INVALID_OBJELEM   14
  121.  
  122. // PDU API Error Codes
  123. #define SNMP_PDUAPI_UNRECOGNIZED_PDU  20
  124. #define SNMP_PDUAPI_INVALID_ES        21
  125. #define SNMP_PDUAPI_INVALID_GT        22
  126.  
  127. // AUTHENTICATION API Error Codes
  128. #define SNMP_AUTHAPI_INVALID_VERSION  30
  129. #define SNMP_AUTHAPI_INVALID_MSG_TYPE 31
  130. #define SNMP_AUTHAPI_TRIV_AUTH_FAILED 32
  131.  
  132.  
  133.  
  134. //
  135. // SNMP API Type Definitions
  136. //
  137.  
  138. typedef long           AsnInteger;
  139. typedef struct {
  140.     BYTE *stream;
  141.     UINT  length;
  142.     BOOL dynamic;
  143. }                      AsnOctetString;
  144. typedef struct {
  145.     UINT idLength;
  146.     UINT *ids;
  147. }                      AsnObjectIdentifier;
  148.  
  149. typedef AsnOctetString AsnSequence;
  150. typedef AsnSequence    AsnImplicitSequence;
  151.  
  152. typedef AsnOctetString AsnIPAddress;
  153. typedef AsnOctetString AsnDisplayString;
  154. typedef DWORD          AsnCounter;
  155. typedef DWORD          AsnGauge;
  156. typedef DWORD          AsnTimeticks;
  157. typedef AsnOctetString AsnOpaque;
  158.  
  159. typedef struct {
  160.     BYTE asnType;
  161.     union {
  162.         // RFC 1155 SimpleSyntax (subset of ISO ASN.1)
  163.         AsnInteger           number;
  164.         AsnOctetString       string;
  165.         AsnObjectIdentifier  object;
  166.  
  167.         // ISO ASN.1
  168.         AsnSequence          sequence;
  169.  
  170.         // RFC 1155 ApplicationSyntax
  171.         AsnIPAddress         address;
  172.         AsnCounter           counter;
  173.         AsnGauge             gauge;
  174.         AsnTimeticks         ticks;
  175.         AsnOpaque            arbitrary;
  176.     } asnValue;
  177. } AsnAny;
  178.  
  179. typedef AsnObjectIdentifier AsnObjectName;
  180. typedef AsnAny              AsnObjectSyntax;
  181. typedef AsnIPAddress        AsnNetworkAddress;
  182.  
  183. typedef struct vb {
  184.     AsnObjectName   name;
  185.     AsnObjectSyntax value;
  186. } RFC1157VarBind;
  187.  
  188. typedef struct {
  189.     RFC1157VarBind *list;
  190.     UINT           len;
  191. } RFC1157VarBindList;
  192.  
  193. typedef struct {
  194.     RFC1157VarBindList varBinds;
  195.     AsnInteger         requestType;
  196.     AsnInteger         requestId;
  197.     AsnInteger         errorStatus;
  198.     AsnInteger         errorIndex;
  199. } RFC1157Pdu;
  200.  
  201. typedef struct {
  202.     RFC1157VarBindList  varBinds;
  203.     AsnObjectIdentifier enterprise;
  204.     AsnNetworkAddress   agentAddr;
  205.     AsnInteger          genericTrap;
  206.     AsnInteger          specificTrap;
  207.     AsnTimeticks        timeStamp;
  208. } RFC1157TrapPdu;
  209.  
  210. typedef struct {
  211.    BYTE pduType;
  212.    union {
  213.       RFC1157Pdu     pdu;
  214.       RFC1157TrapPdu trap;
  215.    } pduValue;
  216. } RFC1157Pdus;
  217.  
  218. typedef struct {
  219.     AsnObjectIdentifier dstParty;
  220.     AsnObjectIdentifier srcParty;
  221.     RFC1157Pdus pdu;
  222.     AsnOctetString community; // This is temporary
  223. } SnmpMgmtCom;
  224.  
  225.  
  226.  
  227. //
  228. // SNMP Utility Prototypes
  229. //
  230.  
  231.  
  232. // Preferred names for the APIs, prototypes following may change in future.
  233.  
  234. #define SnmpUtilOidCpy(a,b)      SNMP_oidcpy(a,b)
  235. #define SnmpUtilOidAppend(a,b)   SNMP_oidappend(a,b)
  236. #define SnmpUtilOidNCmp(a,b,c)   SNMP_oidncmp(a,b,c)
  237. #define SnmpUtilOidCmp(a,b)      SNMP_oidcmp(a,b)
  238. #define SnmpUtilOidFree(a)       SNMP_oidfree(a)
  239.  
  240. #define SnmpUtilVarBindListCpy(a,b)  SNMP_CopyVarBindList(a,b)
  241. #define SnmpUtilVarBindCpy(a,b)      SNMP_CopyVarBind(a,b)
  242. #define SnmpUtilVarBindListFree(a)   SNMP_FreeVarBindList(a)
  243. #define SnmpUtilVarBindFree(a)       SNMP_FreeVarBind(a)
  244.  
  245. #define SnmpUtilPrintAsnAny(a)   SNMP_printany(a)
  246.  
  247. #ifdef SNMPDBG
  248. #define SNMP_free(x)   SNMP_DBG_free(x, __LINE__, __FILE__)
  249. #define SNMP_malloc(x) SNMP_DBG_malloc(x, __LINE__, __FILE__)
  250. #define SNMP_realloc(x, y)  SNMP_DBG_realloc(x, y, __LINE__, __FILE__)
  251. #else
  252. #define SNMP_free(x)   GlobalFree( (HGLOBAL) x )
  253. #define SNMP_malloc(x) (void *) GlobalAlloc( GMEM_FIXED | GMEM_ZEROINIT, (DWORD)x )
  254. #define SNMP_realloc(x, y)  (void *) ((x == NULL) ? GlobalAlloc( GMEM_FIXED | GMEM_ZEROINIT, (DWORD) y) : \
  255.                                        GlobalReAlloc( (HGLOBAL)x, (DWORD)y, GMEM_MOVEABLE | GMEM_ZEROINIT ))
  256. #endif
  257.  
  258. #ifdef __cplusplus
  259. extern "C" {
  260. #endif
  261.  
  262. extern void
  263. SNMP_FUNC_TYPE SNMP_DBG_free(
  264.     IN void *x,
  265.     IN int line,
  266.     IN char *file
  267.     );
  268.  
  269. extern void *
  270. SNMP_FUNC_TYPE SNMP_DBG_malloc(
  271.     IN unsigned int x,
  272.     IN int line,
  273.     IN char *file
  274.     );
  275.  
  276. extern void *
  277. SNMP_FUNC_TYPE SNMP_DBG_realloc(
  278.     IN void *x,
  279.     IN unsigned int y,
  280.     IN int line,
  281.     IN char *file
  282.     );
  283.  
  284.  
  285.  
  286. extern SNMPAPI
  287. SNMP_FUNC_TYPE SNMP_oidcpy(
  288.     OUT AsnObjectIdentifier *DestObjId, // Destination OID
  289.     IN AsnObjectIdentifier *SrcObjId    // Source OID
  290.     );
  291.  
  292. extern SNMPAPI
  293. SNMP_FUNC_TYPE SNMP_oidappend(
  294.     IN OUT AsnObjectIdentifier *DestObjId, // Destination OID
  295.     IN AsnObjectIdentifier *SrcObjId       // Source OID
  296.     );
  297.  
  298. extern SNMPAPI
  299. SNMP_FUNC_TYPE SNMP_oidncmp(
  300.     IN AsnObjectIdentifier *A, // First OID
  301.     IN AsnObjectIdentifier *B, // Second OID
  302.     IN UINT Len                // Max len to compare
  303.     );
  304.  
  305. #define SNMP_oidcmp(A,B) SNMP_oidncmp(A,B,max((A)->idLength,(B)->idLength))
  306.  
  307. extern void
  308. SNMP_FUNC_TYPE SNMP_oidfree(
  309.     IN OUT AsnObjectIdentifier *Obj // OID to free
  310.     );
  311.  
  312. extern SNMPAPI
  313. SNMP_FUNC_TYPE SNMP_CopyVarBindList(
  314.     RFC1157VarBindList *dst, // Destination var bind list
  315.     RFC1157VarBindList *src  // Source var bind list
  316.     );
  317.  
  318. extern SNMPAPI
  319. SNMP_FUNC_TYPE SNMP_CopyVarBind(
  320.     RFC1157VarBind *dst, // Destination var bind
  321.     RFC1157VarBind *src  // Source var bind
  322.     );
  323.  
  324.  
  325. extern void
  326. SNMP_FUNC_TYPE SNMP_FreeVarBindList(
  327.     RFC1157VarBindList *VarBindList // Variable bindings list to free
  328.     );
  329.  
  330. extern void
  331. SNMP_FUNC_TYPE SNMP_FreeVarBind(
  332.     RFC1157VarBind *VarBind // Variable binding to free
  333.     );
  334.  
  335.  
  336. extern void
  337. SNMP_FUNC_TYPE SNMP_printany(
  338.     IN AsnAny *Any
  339.     );
  340.  
  341. #ifdef __cplusplus
  342. }
  343. #endif
  344.  
  345. #endif /* snmp_h */
  346.  
  347.