阅读:1918回复:0
net-snmp5.1.2开发难题。
初用net-snmp5.1.2在linux下编程程序,安装完之后,找了一段程序调试,源码如下:
#include <./mylib/net-snmp5.2/include/net-snmp/net-snmp-config.h> #include <./mylib/net-snmp5.2/include/net-snmp/net-snmp-includes.h> #include <string.h> int main(int argc, char ** argv) { struct snmp_session session; struct snmp_session *sess_handle; struct snmp_pdu *pdu; struct snmp_pdu *response; struct variable_list *vars; oid id_oid[MAX_OID_LEN]; oid serial_oid[MAX_OID_LEN]; size_t id_len = MAX_OID_LEN; size_t serial_len = MAX_OID_LEN; int status; struct tree * mib_tree; /*********************/ if(argv[1] == NULL){ printf("Please supply a hostname\n"); exit(1); } init_snmp("APC Check"); snmp_sess_init( &session ); session.version = SNMP_VERSION_1; session.community = "public"; session.community_len = strlen(session.community); session.peername = argv[1]; sess_handle = snmp_open(&session); add_mibdir("."); //mib_tree = read_mib("PowerNet-MIB.txt"); pdu = snmp_pdu_create(SNMP_MSG_GET); read_objid("system.sysDesrc.0", id_oid, &id_len); snmp_add_null_var(pdu, id_oid, id_len); read_objid("system.sysName.0", serial_oid, &serial_len); snmp_add_null_var(pdu, serial_oid, serial_len); status = snmp_synch_response(sess_handle, pdu, &response); for(vars = response->variables; vars; vars = vars->next_variable) print_value(vars->name, vars->name_length, vars); snmp_free_pdu(response); snmp_close(sess_handle); return (0); } 调试输出是两个值都是null.为什么啊? 请高手指点一二。 |
|