Problems retrieving Hex-STRING in c++
Erik <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <[email protected]> |
Hi all!
Im new coding with net-snmp, so please be gentle...:)
I have some problem retrieving mac-addresses with net-snmp. I have som code that works exellent retrieving text-strings, but when i try to retrieve a mac address from a Mikrotik router (ex. .1.3.6.1.2.1.2.2.1.6.3) im getting nothing back.
Here is my code:
string SNMPController::snmpSendRequest(string _oid)
{
count=1;
result = "";
anOID_len = MAX_OID_LEN;
int status = 0;
//Open the session
SOCK_STARTUP;
ss = snmp_open(&session); // establish the session
if (!ss) {
snmp_perror("ack");
// MessageBox("Could not open session!");
snmp_log(LOG_ERR, "something horrible happened!!!\n");
result = "ERROR";
}
pdu = snmp_pdu_create(SNMP_MSG_GET);
read_objid(_oid.c_str(), anOID,&anOID_len);
snmp_add_null_var(pdu, anOID, anOID_len);
// Send the Request out.
status = snmp_synch_response(ss, pdu, &response);
// Process the response.
if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR)
{
// SUCCESS: Print the result variables
for(vars = response->variables; vars; vars = vars->next_variable)
print_variable(vars->name, vars->name_length, vars);
// manipuate the information ourselves
for(vars = response->variables; vars; vars = vars->next_variable)
{
if (vars->type == ASN_OCTET_STR)
{
char *sp = (char *)malloc(1 + vars->val_len);
memcpy(sp, vars->val.string, vars->val_len);
sp[vars->val_len] = '\0';
//printf("value #%d is a string: %s\n", count++, sp);
result = (string)sp;
deletesp;
}
else
{
char buf[1024];
snprint_variable(buf, sizeof(buf), vars->name, vars->name_length, vars);
result = (string)buf;
//printf("value #%d is NOT a string! Ack!\n", count++);
}
}
}
else
{
//FAILURE: print what went wrong!
if (status == STAT_SUCCESS)
{
fprintf(stderr, "Error in packet\nReason: %s\n",snmp_errstring(response->errstat));
AfxMessageBox(snmp_errstring(response->errstat));
result = "ERROR";
}
else
{
snmp_sess_perror("snmpget", ss);
result = "ERROR";
}
}
//Clean up:
//1) free the response.
//2) close the session.
if (response)
snmp_free_pdu(response);
snmp_close(ss);
SOCK_CLEANUP;
returnresult;
}
Any help with solving this would be VERY apreciated!
best regards
Erik