static OIDC_T ID_example[] = { 1, 3, 6, 1, 4, 1, 731, 100 };
static int len_example = 8;
static OIDC_T ID_exampleEnum[] = { 1, 3, 6, 1, 4, 1, 731, 100, 4, 0 };
static int len_exampleEnum = 10;
char snmp_trap_community[32] = "SNMP_trap";
unsigned char local_ip[4] = {192,168,255,1};
EBUFFER_T ebuff;
/*****************************************************************************
****
****
**** Trap creation function for testtrap trap
****
**** DESCRIPTION:
**** trap test
****
**** Returns length of encoded packet, 0 on SNMP failure,
**** or -1 if an instance is too long.
****
****
*****************************************************************************
*/
void trapsend(void)
{
int crt_testtrap_trap(
EBUFFER_T *ebuff,
OCTET_T *local_ip,
char *snmp_trap_community,
unsigned comlen,
UINT_32_T timestamp,
INT_32_T AexampleEnum) /* INTEGER */
{
SNMP_PKT_T *trap_pkt;
/*EBufferInitialize(&ebuff);
/* Create the SNMP packet structure. */
trap_pkt = SNMP_Create_Trap(SNMP_VERSION_1, strlen(snmp_trap_community), snmp_trap_community,
len_example, ID_example,
local_ip,
6, /* enterpriseSpecific(6) */
10,
timestamp,
1);
/* Verify that SNMP_Create_Trap succeeded. */
if (trap_pkt == (SNMP_PKT_T*)0)
return 0;
/* Bind the variables in the trap. */
if (SNMP_Bind_Integer(trap_pkt, 0, len_exampleEnum, ID_exampleEnum, AexampleEnum) == -1)
goto fail;
/* Encode the packet as bytes into the user-supplied buffer. */
if (SNMP_Encode_Packet(trap_pkt, ebuff) == -1)
goto fail;
printf("SNMP_Encode_Packet ok!\n");
/* Free the SNMP packet structure. */
SNMP_Free(trap_pkt);
fail:
printf("SNMP_Encode_Packet failed!\n");
/* Come here on failure during bind or encode. */
SNMP_Free(trap_pkt);
return 0;
}
#define ADDR "192.168.103.108"
struct sockaddr_in traps_to;
int s;
int sendNum;
traps_to.sin_family = AF_INET;
traps_to.sin_port = htons(162);
traps_to.sin_addr.s_addr = inet_addr(ADDR);
sendNum=sendto(s, ebuff.start_bp, EBufferUsed(&ebuff),0, (struct sockaddr *)&traps_to, sizeof(traps_to));
if((sendNum)==ERROR)
{
printf("sendto failed!\n");
}
printf("%d bytes of message sent:%s\n",sendNum,ebuff);
/*SGRPv1_INC_COUNTER(snmp_stats.snmpOutPkts);
SGRPv1_INC_COUNTER(snmp_stats.snmpOutTraps);*/
EBufferClean(&ebuff);
}