#ifndef _SNMP_MACRO_H
#define _SNMP_MACRO_H

#define SyntaxInteger			0x02
#define SyntaxOctetString			0x04
#define SyntaxIpAddress			0x40
#define SyntaxCounter			0x41
#define SyntaxTimeTicks			0x43
#define SyntaxOpaque			0x44

#define Create_Object_Cloumn		1
#define Create_Sub_Object_Command		1

#define GET_NULL() do { \
	*pdata = 0; \
	*vartype = SyntaxInteger; \
	datalen = 1; \
} while(0)

#define GET_INTEGER(integer) do { \
	*((int *)pdata) = htonl(integer); \
	*vartype = SyntaxInteger; \
	datalen = 4; \
} while(0)

#define SET_INTEGER(integer) do { \
	int i; \
	if(datalen > 4) \
		return -1; \
	for(i = 0, integer = 0; i < datalen; i++) \
	{ \
		integer = integer << 8; \
		integer += pdata[i]; \
	} \
} while(0)

#define RETURN_INTEGER(integer) do { \
	int i; \
	if(datalen > 4) \
		datalen = 4; \
	for(i = 0; i < datalen; i++) \
	{ \
		pdata[datalen-i-1] = ((u8 *)&integer)[i]; \
	} \
} while(0)

#undef GET_U8	/* undefine the "public" macro */
#define GET_U8(byte) do { \
	*pdata = byte; \
	*vartype = SyntaxInteger; \
	datalen = 1; \
} while(0)

#define SET_U8(byte) do { \
	byte = pdata[datalen-1]; \
} while(0)

#define GET_STRING(string) do { \
	strcpy((char *)pdata, (char *)string); \
	*vartype = SyntaxOctetString; \
	datalen = strlen((char *)string); \
} while(0)

#define SET_STRING(string) do { \
	memcpy(string, pdata, datalen); \
	string[datalen] = 0; \
} while(0)

#define GET_OCTETSTRING(octets, count) do { \
	memcpy(pdata, octets, count); \
	*vartype = SyntaxOctetString; \
	datalen = count; \
} while(0)

#define SET_OCTETSTRING(octets, count) do { \
	memcpy(octets, pdata, count); \
} while(0)

#define GET_OPAQUE(octets, count) do { \
	memcpy(pdata, octets, count); \
	*vartype = SyntaxOpaque; \
	datalen = count; \
} while(0)

#define SET_OPAQUE(octets, count) do { \
	memcpy(octets, pdata, count); \
} while(0)

#define GET_IP(ip) do { \
	memcpy(pdata, ip, 4); \
	*vartype = SyntaxIpAddress; \
	datalen = 4; \
} while(0)

#define SET_IP(ip) do { \
	memcpy(ip, pdata, 4); \
} while(0)

#endif

