Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anyone please help in knowing when will we get the SNMPERR_SUCCESS error.
From the description of snmp_api.h, I see this is the non-pdu success code.
What does that mean.?

I have a scenario where I am trying to open a snmp session.
In return, it is going to catch block of my code saying failed to open snmp session with error code (0,0).

I understood that (0,0) means SNMPERR_SUCCESS. But I want to know what could be the problem. if it means a success code. why is it in error list.

Please correct me if I have mistaken. and help me to analyse further


Thanks in advance.
Posted
Comments
Andy Lanng 30-Oct-15 7:46am    
Wow - that takes me back :)

SNMPERR_SUCCESS is letting you know the return code. In this case they used the misnomer SNMPERR as the prefix for the return code. If it is non-zeo then an error of some sort occurred. if it is zero then it's fine and you get the SNMPERR_SUCCESS.

It means "all went as expected". It's a good thing ^_^
Member 12018498 30-Oct-15 7:55am    
Thank you Andy..But the snmp session was not started .
From the below description... snmp_open will return null if some error occurs.
/*
* netsnmp_session *snmp_open(session)
* netsnmp_session *session;
*
* Sets up the session with the snmp_session information provided
* by the user. Then opens and binds the necessary UDP port.
* A handle to the created session is returned (this is different than
* the pointer passed to snmp_open()). On any error, NULL is returned
* and snmp_errno is set to the appropriate error code.
*/
netsnmp_session *snmp_open(netsnmp_session *);
............................................................
So i wrote a check if its null throw the error. Its quite clear that it was null.
Can you please suggest something
Andy Lanng 30-Oct-15 7:59am    
pfff. I had to really strain to remember that much. Jochen has posted a solution version of my comment to I assume he is more knowledgeable than me as of right now.

(I've forgotten more than I know, but that nothing about my current level of knowledge ^_^)
Member 12018498 30-Oct-15 8:03am    
Ok no problem :) . Thanks again for helping to understand.

1 solution

It is just the success return value. It is part of the error definition list to have also a value indicating that no error occured.

Your code should not interpret that value as error.

[UPDATE]
From comments it has become clear that the failing function is snmp_open:
struct snmp_session * snmp_open ( struct snmp_session *);

This function does not return a SNMP_ERR* code but a pointer. When this fails, NULL is returned and the error code can be retrieved:
struct snmp_session session;
struct snmp_session *handle;

snmp_sess_init(&session);
// Set session parameters here
handle = snmp_open(&session);
if (NULL == handle)
{
    // handle error here
    int liberr, syserr,
    char *errstr;
    snmp_error(&session, &liberr, &syserr, &errstr);
    printf("SNMP open error %s.\n", errstr);
    free(errstr);
}
 
Share this answer
 
v2
Comments
Member 12018498 30-Oct-15 7:58am    
Thank you Jochen.Does that mean there is some other problem with null value returned from snmp_open?. Please see the above comment
Jochen Arndt 30-Oct-15 8:08am    
The return value of snmp_open() is a pointer to a netsnmp_session and not a SNMP_ERR_* code!

Functions returning pointers usually return NULL upon errors. Then the corresponding error code can be accessed by a function (old: snmp_get_errno, new: snmp_error) or global variable (old: snmp_errno, new: snmperr).

See also the snmp_open man page (http://linux.die.net/man/3/snmp_open).
Member 12018498 30-Oct-15 8:45am    
The error code I got was SNMPERR_SUCCESS. I accessed the error code and the result I got is (0,0). which means everything is fine. go ahead. But if its returned null, there must be some problem rite?

part of code---
............................................................
struct snmp_session session;( snmp_session present in snmp_api.h.)
openSession = NetSnmp::getInstance().snmp_sess_open(&session);
if (NULL == openSession) {
int liberr=0, syserr=0;
char *errstr=NULL;
NetSnmp::getInstance().snmp_error(&session, &liberr, &syserr, &errstr);

std::string error(errstr);
::free(errstr);
cout<<"Failed to open snmp session to %s, error: %s (%d,%d)", port,errstr, liberr, syserr";
close();
}


And the output is: "Failed to open snmp session to 127.0.0.1:xxxx, error: (0,0)"

.............................................................
hence I was confused, that error code says everything is fine, but still null is returned .
Jochen Arndt 30-Oct-15 8:56am    
Here you call snmp_sess_open() and not snmp_open().

Than you should call snmp_sess_error() upon failures and not snmp_error().

See http://linux.die.net/man/3/snmp_sess_open.
Member 12018498 30-Oct-15 9:06am    
I am really thankful for your time Jochen. Thank you so much.
went through the link suggested by you. and i see the below line
"For errors returned by snmp_sess_open(), use the corresponding function snmp_error() instead of snmp_sess_error(). " So I think that it should not be the problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900