|
楼主 |
发表于 2005-3-26 15:47:00
|
显示全部楼层
先贴一个程序,最简单的,取自己的sysLocation.0,
大家看看错在哪里?
[code:1]
main(int argc, char * argv[])
{
struct snmp_session session, *ss;
struct snmp_pdu *request, *response;
oid myoid[MAX_OID_LEN];
size_t myoid_len = MAX_OID_LEN;
struct variable_list *vars;
int status;
init_snmp("snmpapp1");
snmp_sess_init( &session );
session.version = SNMP_VERSION_1;
session.peername = "localhost";
session.community = "public";
session.community_len = strlen(session.community);
ss = snmp_open(&session);
request = snmp_pdu_create(SNMP_MSG_GET);
read_objid("SNMPv2-MIB::sysName.0", myoid, &myoid_len);
printf("myoid=");
for (status=0;status<myoid_len;status=status+1)
printf(".%d",myoid[status]);
printf("\n");
//到这里一切正常
snmp_add_null_var(request, myoid, myoid_len);
status = snmp_synch_response(ss, request, &response); //问题出在这里
if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR) //这里返回的status是0
{
printf("start to work...\n");
for(vars = response->variables; vars; vars = vars->next_variable)
print_variable(vars->name, vars->name_length, vars);
}
else
{
if (status == STAT_SUCCESS)
fprintf(stderr, "Error in packet\nReason: %s\n",
snmp_errstring(response->errstat));
else
snmp_sess_perror("snmpget", ss);
}
if (response)
snmp_free_pdu(response);
snmp_close(ss);
return (0);
}
[/code:1] |
|