snmp_sess_init, snmp_open, snmp_send, snmp_async_send, snmp_select_info, snmp_read, snmp_timeout, snmp_synch_response, snmp_close, snmp_perror, snmp_sess_perror, snmp_error, snmp_api_errstring − netsnmp_session_api functions


#include <net-snmp/session_api.h>

void snmp_sess_init ( netsnmp_session*sess);

netsnmp_session* snmp_open ( netsnmp_session *sess);

/* Input parameter not used in active sessions */

int snmp_send ( netsnmp_session *session,

netsnmp_pdu *pdu);

int snmp_async_send ( netsnmp_session *session,

netsnmp_pdu *pdu,
void *

int snmp_select_info ( int * numfds,fd_set *fdset,

struct timeval *timeout,int *block);

void snmp_read ( fd_set *fdset);

void snmp_timeout ( void );

int snmp_synch_response ( netsnmp_session *session,

netsnmp_pdu *pdu,
netsnmp_pdu **

int snmp_close ( netsnmp_session *session);
int snmp_close_sessions ( void );

Error Reporting
(Move to output_api(3))

void snmp_error ( netsnmp_session *session,

int *pcliberr,int *psnmperr,char **pperrstring);

char *snmp_api_errstring ( intsnmperr);

void snmp_perror ( char *msg);

/* for parsing errors only */

void snmp_sess_perror (char *msg,netsnmp_session *sess);

/* all other SNMP library errors */


Snmp_sess_init prepares a netsnmp_session that sources transport characteristics and common information that will be used for a set of SNMP transactions. After this structure is passed to snmp_open to create an SNMP session, the structure is not used.

Snmp_open returns a pointer to a newly-formed netsnmp_session object, which the application must use to reference the active SNMP session.

snmp_send and snmp_async_send() each take as input a pointer to a netsnmp_pdu object. This structure contains information that describes a transaction that will be performed over an open session.

Consult snmp_api.h for the definitions of these structures.

With the snmp_async_send() call, snmp_read will invoke the specified callback when the response is received.

Snmp_read, snmp_select_info, and snmp_timeout provide an interface for the use of the select(2) system call so that SNMP transactions can occur asynchronously.

Snmp_select_info is given the information that would have been passed to select in the absence of SNMP. For example, this might include window update information. This information is modified so that SNMP will get the service it requires from the call to select. In this case, numfds, fdset, and timeout correspond to the nfds, readfds, and timeout arguments to select, respectively. The only exception is that timeout must always point to an allocated (but perhaps uninitialized) struct timeval. If timeout would have been passed as NULL, block is set to true, and timeout is treated as undefined. This same rule applies upon return from snmp_select_info.

After calling snmp_select_info, select is called with the returned data. When select returns, snmp_read should be called with the fd_set returned from select to read each SNMP socket that has input. If select times out, snmp_timeout should be called to see if the timeout was intended for SNMP.

snmp_synch_response is a convenience routine that will send the request, wait for the response and process it before returning. See the descriptions of snmp_send , snmp_read etc for details.


Previous versions of the library used snmp_get_errno to read the global variable snmp_errno which may have held the error status within the SNMP library. The existing method snmp_perror should be used to log ASN.1 coding errors only.

The new method snmp_sess_perror is provided to capture errors that occur during the processing of a particular SNMP session. Snmp_sess_perror calls snmp_error function to obtain the "C" library error errno , the SNMP library error snmperr , and the SNMP library detailed error message that is associated with an error that occurred during a given session.

Note that in all cases except one, snmp_sess_perror should be handed the netsnmp_session * pointer returned from snmp_open. If snmp_open returns a null pointer, pass the INPUT netsnmp_session * pointer used to call snmp_open.

Error return status from snmp_close and snmp_send is indicated by return of 0. A successful status will return a 1 for snmp_close and the request id of the packet for snmp_send. Upon successful return from snmp_send the pdu will be freed by the library.

Consult snmp_api.h for the complete set of SNMP library error values. The SNMP library error value snmperr can be one of the following values:


A generic error occurred.


The local port was bad because it had already been allocated or permission was denied.


The host name or address given was not useable.


The specified session was not open.















A string representation of the error code can be obtained with snmp_api_errstring, and a standard error message may be printed using snmp_perror that functions like the perror standard routine.


select(2), snmp_api.h

More Linux Commands

ip-l2tp(8) L2TPv3 static unmanaged tunnel configuration.....
The ip l2tp commands are used to establish static, or so-called unmanaged L2TPv3 ethernet tunnels. For unmanaged tunnels, there is no L2TP control protocol so n

col(1) - filter reverse line feeds from input (Man Page)....
col filters out reverse (and half-reverse) line feeds so the output is in the correct order, with only forward and half-forward line feeds. It also replaces any

XRaiseWindow(3) - change window stacking order (Man Page)...
The XRaiseWindow function raises the specified window to the top of the stack so that no sibling window obscures it. If the windows are regarded as overlapping

XkbCopyKeyType(3) - Copy one XkbKeyTypeRec structures.......
XkbCopyKeyType copies the key type specified by from to the key type specified by into. Both must point to legal XkbKeyTypeRec structures. Xkb assumes from and

mdoc(7) - quick reference guide for the -mdoc macro package
General description, should include options and parameters. RETURN VALUE Sections two and three function calls. ENVIRONMENT Describe environment variables. FILE

Wand-config(1) - get information about the installed version
Wand-config prints the compiler and linker flags required to compile and link programs that use the Wand Application Programmer Interface. EXAMPLES To print the

colcrt(1) - filter nroff output for CRT previewing (ManPage)
colcrt provides virtual half-line and reverse line feed sequences for terminals without such capability, and on which overstriking is destructive. Half-line cha

acl_set_tag_type(3) - set the tag type of an ACL entry......
The acl_set_tag_type() function sets the tag type of the ACL entry indicated by the argument entry_d to the value of the argument tag_type. Any ACL entry descri

radvdump(8) - dump router advertisements - Linux man page...
radvdump prints out the contents of incoming router advertisements sent by radvd or some other software implementing (parts of) Neighbor Discovery for IP Versio

crypt_gensalt(3) - password hashing - Linux manual page.....
The crypt, crypt_r, crypt_rn, and crypt_ra functions calculate a cryptographic hash function of key with one of a number of supported methods as requested with

libc(7) - Overview of standard C libraries on Linux.........
The term libc is commonly used as a shorthand for the standard C library, a library of standard functions that can be used by all C programs (and sometimes by p

Tk_PhotoPutBlock(3) - manipulate the image data stored in a
Tk_FindPhoto returns an opaque handle that is used to identify a particular photo image to the other procedures. The parameter is the name of the image, that is

We can't live, work or learn in freedom unless the software we use is free.