Witam mam problem mam aplikacje odpytujaca mi CMTS'a o adresy IP ale jest problem normalnie bym korzystal z snmpwalk podaje oida a on mi wszystkie z tego zakresu wypisuje natomiast w moim programie nie moge tego zrobic Moze ma ktos jakis pomysl:
#include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h>
#include <string.h>
int main(int argc, char ** argv)
{
netsnmp_session session, *ss;
netsnmp_pdu *pdu;
netsnmp_pdu *response;
oid anOID[MAX_OID_LEN];
size_t anOID_len = MAX_OID_LEN;
netsnmp_variable_list *vars;
int status;
int count=1;
init_snmp("snmpapp");
snmp_sess_init( &session );
session.peername = strdup("xxxxxxx");
session.version = SNMP_VERSION_2c;
session.community = "commname";
session.community_len = strlen(session.community);
SOCK_STARTUP;
ss = snmp_open(&session);
if (!ss) {
snmp_sess_perror("ack", &session);
SOCK_CLEANUP;
exit(1);
}
pdu = snmp_pdu_create(SNMP_MSG_GETNEXT);
if (!snmp_parse_oid("transmission.127.1.3.3.1.3", anOID, &anOID_len)) {
snmp_perror(".1.3.6.1.2.1.1.1.0");
SOCK_CLEANUP;
exit(1);
}
//get_node(, anOID, &anOID_len);
snmp_add_null_var(pdu, anOID, anOID_len);
status = snmp_synch_response(ss, pdu, &response);
if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR)
{
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 if (status == STAT_TIMEOUT)
fprintf(stderr, "Timeout: No response from %s.\n",
session.peername);
else
snmp_sess_perror("snmpapp", ss);
}
if (response)
snmp_free_pdu(response);
snmp_close(ss);
SOCK_CLEANUP;
return (0);
}
Z tego dostaje taki wynik:
SNMPv2-SMI::transmission.127.1.3.3.1.3.1 = IpAddress: 172.16.1.183
A chce zeby mi wyswietlilo tak jak smntpwalk:
snmpwalk -c pass -v 2c -Ov 192.168.1.1 SNMPv2-SMI::transmission.127.1.3.3.1.3
IpAddress: 0.0.0.0
IpAddress: 0.0.0.0
IpAddress: 172.*********
IpAddress: 0.0.0.0
IpAddress: 172******
IpAddress: 0.0.0.0
IpAddress: 172.********
IpAddress: 0.0.0.0
IpAddress: 0.0.0.0
IpAddress: 0.0.0.0
IpAddress: 172.*****
IpAddress: 172.******
IpAddress: 172.*******
IpAddress: 0.0.0.0
IpAddress: 0.0.0.0