Dear Teachers:
I am sorry to trouble you, but I can solve some questions .Can you
help me ?
This program have compiled successful .But when I run a program ,it
always show "the host 127.0.0.1 do not support snmp get_default_way
wrong" , I didn't know what should I do! The related fuctions as follows:
main(int argc, char **argv)
{
char *ip;
interface_list_t interface_ent = NULL;
struct in_addr host_in_addr;
if ( get_default_gateway("127.0.0.1", &ip)) {
fprintf(stderr, "get_default_gateway wrong!");
exit(1);
;;;;;;;;;
;;;;;;;;}
get_default_gateway(const char * ip, char ** result)
{
if(snmpz_isaware(ip)){
fprintf(stderr, "The host %s do not support snmp", ip);
return 1;
}
if (snmpz_open(ip, COMMUNITY) != 0)
return -1;
if (snmpz_getip("1.3.6.1.2.1.4.21.1.7.1.1.1.1", result) != 0) {
fprintf(stderr, "snmpz_getip error\n");
}
snmpz_close();
return 0;
}
int snmpz_isaware(const char *hostname)
{
struct snmp_session session_init;
struct snmp_session *mysession;
struct snmp_pdu *pdu;
struct snmp_pdu *response = NULL;
oid myoid[] = { 1, 3, 6, 1, 2, 1, 1, 1, 0 };
int res;
init_snmp("psnmp");
snmp_sess_init(&session_init);
session_init.peername = (char *)hostname;
session_init.version = SNMP_VERSION_1;
session_init.community = "pubic";
session_init.community_len = strlen("pubic");
session_init.timeout = 100000;
session_init.retries = 1;
if((mysession = snmp_open(&session_init)) == NULL)
return -1;
if((pdu = snmp_pdu_create(SNMP_MSG_GET)) == NULL)
res = -2;
else {
snmp_add_null_var(pdu, myoid, sizeof(myoid) / sizeof(oid));
if(snmp_synch_response(mysession, pdu, &response) == STAT_SUCCESS) {
if(response->errstat == SNMP_ERR_NOERROR)
res = 0;
else
res = 1;
} else
res = 1;
if (response) snmp_free_pdu(response);
}
snmp_close(mysession);
return res;
}
What'wrong?
I am looking forward to hearing from you!
Thank you very much!
yours students:yangjing
July 19
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users