www.pudn.com > SNMP·¶ÀýÔ´´úÂë.zip > Snmp.h


/*******************************************************************************
* snmp - 
/************************************************************************* 
 *************************************************************************/
#ifndef _SNMP_H_
#define _SNMP_H_

#define SNMP_VERSION    			0

/* Default Sizes */

#define SNMP_SIZE_COMM              256		/* 256 */
#define SNMP_SIZE_OBJECTID          56 	/* 128 */
#define SNMP_SIZE_BUFCHR            50 /* 256 */ 
#define SNMP_SIZE_BUFINT            50 /* 128 */	

#define SNMP_SIZE_SMALLOBJECTID     32


/* Requests */

#define SNMP_PDU_GET                0
#define SNMP_PDU_NEXT               1
#define SNMP_PDU_RESPONSE           2
#define SNMP_PDU_SET                3
#define SNMP_PDU_TRAP               4
#define SNMP_PDU_COMMIT				9	/* for internal use only */
#define SNMP_PDU_UNDO				10	/* for internal use only */

/* Errors */

#define SNMP_NOERROR                0
#define SNMP_TOOBIG                 1
#define SNMP_NOSUCHNAME             2
#define SNMP_BADVALUE               3
#define SNMP_READONLY               4
#define SNMP_GENERROR               5

/* Rmon Status */

#define SNMP_VALID               1
#define SNMP_CREATEREQUEST       2
#define SNMP_UNDERCREATION       3
#define SNMP_INVALID             4

/* Types */
         
#define SNMP_NULL                IDB_SNMP_NULL 
#define SNMP_INTEGER             IDB_SNMP_INTEGER              /* LngInt */
#define SNMP_OCTETSTR            IDB_SNMP_OCTET_STRING         /* BufChr */
#define SNMP_OBJECTID            IDB_SNMP_OBJECT_IDENTIFIER    /* BufInt */
#define SNMP_IPADDR              IDB_SNMP_IpAddress            /* LngUns */
#define SNMP_COUNTER             IDB_SNMP_Counter              /* LngUns */
#define SNMP_GAUGE               IDB_SNMP_Guage                /* LngUns */
#define SNMP_TIMETICKS           IDB_SNMP_TimeTicks            /* LngUns */
#define SNMP_OPAQUE              IDB_SNMP_Opaque               /* BufChr */
#define SNMP_DISPLAYSTR          IDB_SNMP_OCTET_STRING         /* BufChr */

/* Typedefs */

typedef struct  snmp_stat_s       	snmp_stat_t;
typedef struct  snmp_request_s		snmp_request_t;
typedef struct  snmp_request_s     	snmp_trap_t;	
typedef struct  snmp_request_s		snmp_pdu_t;
typedef union   snmp_syntax_s     	snmp_syntax_t;
typedef struct  snmp_object_s		snmp_object_t;
typedef struct idb_s idb_t;

union snmp_syntax_s {
	l32			LngInt;
	u32			LngUns;
	u8			BufChr [SNMP_SIZE_BUFCHR];
	u32			BufInt [SNMP_SIZE_BUFINT];
	void		*Ptr;
};

struct idb_s {
	u32 object;
	u16 request;
	u32 indexLength;
	u32* index;
	snmp_syntax_t value;
	u32 valueLength;
	u16 snmpReturnCode;
};

struct snmp_object_s {
	u16				Request;
	ul32			Id[SNMP_SIZE_OBJECTID];
	u32				IdLen;
	u16				Type;
	snmp_syntax_t	Syntax;
	u32				SyntaxLen;
};
/* for managment of SNMP process*/
struct snmp_stat_s {			/*	SNMPv1	SNMPv2*/
    ul32            OutPkts; 		/*	yes	yes*/
    ul32            OutTooBigs;		/*	yes	no*/
    ul32            OutNoSuchNames;	/*	yes	no*/
    ul32            OutBadValues;	/*	yes*/
    ul32            OutReadOnlys;	/*	yes*/
    ul32            OutGenErrs;		/*	yes*/
    ul32            OutGetRequests;	/**/
    ul32            OutGetNexts;	/**/
    ul32            OutSetRequests;	/**/
    ul32            OutGetResponses;	/**/
    ul32            OutTraps;		/**/
    ul32 	    snmpInBadCommunityUses;
    ul32 	  snmpEnableAuthenTraps;
    ul32 snmpSilentDrops;
	ul32 snmpProxyDrops;
    ul32            InPkts;		/**/
    ul32            InTooBigs;		/**/
    ul32            InNoSuchNames;	/**/
    ul32            InBadValues;	/**/
    ul32            InReadOnlys;	/**/
    ul32            InGenErrs;		/**/
    ul32            InGetRequests;	/**/
    ul32            InGetNexts;		/**/
    ul32            InSetRequests;	/**/
    ul32            InGetResponses;	/**/
    ul32            InTraps;		/**/
    ul32            InBadVersions;	/**/
    ul32            InASNParseErrs;	/**/
    ul32            InBadTypes;		/**/
};


struct snmp_request_s {
    u32     		Type;
    ul32         	Id;
    union {
			u32     		ErrorStatus;
			u32				Non_repeaters;
			}inner; 
#define ErrorStatus inner.ErrorStatus
#define Non_repeaters inner.Non_repeaters;
	union {
			u32     		ErrorIndex;
			u32				Max_Repetitions;
			}inner2;
#define ErrorIndex inner2.ErrorIndex
#define Max_Repetitions inner2.Max_Repetitions
};


extern i32 snmpErrStatus;
extern i32 snmpErrIndex;
extern const i8 *SnmpTrap[];
                
int SnmpEnc(u8 **Snmp, u32      *SnmpLen, snmp_pdu_t *Pdu, u8 *Com, 
                u32      ComLen, snmp_object_t *Lst, u32      LstLen);
int SnmpDec(u8 *Snmp, u32      SnmpLen, snmp_pdu_t *Pdu, u8 *Com, 
                u32      ComSze, u32      *ComLen, snmp_object_t *Lst, 
                u32      LstSze, u32      *LstLen);
int SnmpErrEnc(snmp_pdu_t *Rqs);
int SnmpCheckDisplayString(u8 *string, u16 len);


#endif