这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 嵌入式开发 » MCU » [求助]send trap 代码 老是sendto 错误,那位大侠看看

共2条 1/1 1 跳转至

[求助]send trap 代码 老是sendto 错误,那位大侠看看

菜鸟
2006-04-01 02:21:10     打赏


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);


}




关键词: 求助     代码     老是     sendto     错误     那位     大侠         

菜鸟
2007-02-08 04:36:00     打赏
2楼

s没有初始化。

加上下面这两句:

IMPORT int snmpSocket;

int s = snmpSocket;

应该就差不多了,具体没有验证。


共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]