---
name: "netsnmp_library"
section: "3snmp"
platform: "linux"
package: "libsnmp-dev"
version: "5.4.3~dfsg-2.8+deb7u1"
release: "Debian 7 (Wheezy)"
platforms: ["linux"]
url: "https://new.carta.tech/netsnmp_library"
---

# netsnmp\_library(3snmp)

the Net-SNMP library

## NAME

netsnmp\_library - the Net-SNMP library

### Data Structures

struct **snmp\_internal\_session**\
 struct **session\_list**\

### Modules

**asn1 parsing and datatype manipulation routines.**\

*Note on.*  **A generic callback mechanism**\
 **generic linked-list data handling with a string as a key.**\
 **storage space for defaults**\

*The purpose of the default storage is three-fold:.*  **mib parsing and datatype manipulation routines.**\
 **Store and retrieve data referenced by an OID.**\

*This is essentially a way of storing data associated with a given OID.*  **parsing various configuration files at run time**\

*The read\_config related functions are a fairly extensible system of parsing various configuration files at the run time.*  **generic library based alarm timers for various parts of an application**\
 **various PDU processing routines**\
 **generic logging for net-snmp**\
 **Memory Utility Routines**\

### Defines

\#define **MIN**(a, b)   (((a) \< (b)) ? (a) : (b))\
 \#define **MIB\_CLIENTS\_ARE\_EVIL**   1\
 \#define **\_init\_agent\_callback\_transport**()\
 \#define **SNMP\_NEED\_REQUEST\_LIST**\
 \#define **timercmp**(tvp, uvp, cmp)\
 \#define **timerclear**(tvp)   (tvp)-\>tv\_sec = (tvp)-\>tv\_usec = 0\
 \#define **MAX\_PACKET\_LENGTH**   (0x7fffffff)\
 \#define **NETSNMP\_STREAM\_QUEUE\_LEN**   5\
 \#define **BSD4\_2**\
 \#define **DEFAULT\_COMMUNITY**   'public'\
 \#define **DEFAULT\_RETRIES**   5\
 \#define **DEFAULT\_TIMEOUT**   1000000L\
 \#define **DEFAULT\_REMPORT**   SNMP\_PORT\
 \#define **DEFAULT\_ENTERPRISE**   default\_enterprise\
 \#define **DEFAULT\_TIME**   0\
 \#define **MAXIMUM\_PACKET\_SIZE**   0x7fffffff\
 \#define **DEBUGPRINTPDUTYPE**(token, type)   DEBUGDUMPSECTION(token, snmp\_pdu\_type(type))\
 \#define **ERROR\_STAT\_LENGTH**   11\

### Functions

int **init\_agent** (const char \*app)\
 *Initialize the agent.*  void **shutdown\_agent** (void)\
 void **add\_to\_init\_list** (char \*module\_list)\
 int **should\_init** (const char \*module\_name)\
 int **snmp\_build** (u\_char \*\*pkt, size\_t \*pkt\_len, size\_t \*offset, **netsnmp\_session** \*pss, **netsnmp\_pdu** \*pdu)\
 int **snmp\_get\_errno** (void)\
 void **snmp\_synch\_reset** (**netsnmp\_session** \*notused)\
 void **snmp\_synch\_setup** (**netsnmp\_session** \*notused)\
 const char \* **strerror** (int err)\
 const char \* **snmp\_pdu\_type** (int type)\
 long **snmp\_get\_next\_reqid** (void)\
 long **snmp\_get\_next\_msgid** (void)\
 long **snmp\_get\_next\_sessid** (void)\
 long **snmp\_get\_next\_transid** (void)\
 void **snmp\_perror** (const char \*prog\_string)\
 void **snmp\_set\_detail** (const char \*detail\_string)\
 const char \* **snmp\_api\_errstring** (int snmp\_errnumber)\
 void **snmp\_error** (**netsnmp\_session** \*psess, int \*p\_errno, int \*p\_snmp\_errno, char \*\*p\_str)\
 void **snmp\_sess\_error** (void \*sessp, int \*p\_errno, int \*p\_snmp\_errno, char \*\*p\_str)\
 void **netsnmp\_sess\_log\_error** (int priority, const char \*prog\_string, **netsnmp\_session** \*ss)\
 void **snmp\_sess\_perror** (const char \*prog\_string, **netsnmp\_session** \*ss)\
 void **snmp\_sess\_init** (**netsnmp\_session** \*session)\
 void **init\_snmp** (const char \*type)\
 *Calls the functions to do config file loading and mib* **module** *parsing in the correct order.*  void **snmp\_store** (const char \*type)\
 void **snmp\_shutdown** (const char \*type)\
 *Shuts down the application, saving any needed persistent storage, and appropriate clean up.*  **netsnmp\_session** \* **snmp\_open** (**netsnmp\_session** \*session)\
 **netsnmp\_session** \* **snmp\_open\_ex** (**netsnmp\_session** \*session, int(\*fpre\_parse)(**netsnmp\_session** \*, **netsnmp\_transport** \*, void \*, int), int(\*fparse)(**netsnmp\_session** \*, **netsnmp\_pdu** \*, u\_char \*, size\_t), int(\*fpost\_parse)(**netsnmp\_session** \*, **netsnmp\_pdu** \*, int), int(\*fbuild)(**netsnmp\_session** \*, **netsnmp\_pdu** \*, u\_char \*, size\_t \*), int(\*frbuild)(**netsnmp\_session** \*, **netsnmp\_pdu** \*, u\_char \*\*, size\_t \*, size\_t \*), int(\*fcheck)(u\_char \*, size\_t))\
 int **snmpv3\_engineID\_probe** (struct **session\_list** \*slp, **netsnmp\_session** \*in\_session)\
 *probe for peer engineID*  **netsnmp\_session** \* **snmp\_add** (**netsnmp\_session** \*in\_session, **netsnmp\_transport** \*transport, int(\*fpre\_parse)(**netsnmp\_session** \*, **netsnmp\_transport** \*, void \*, int), int(\*fpost\_parse)(**netsnmp\_session** \*, **netsnmp\_pdu** \*, int))\
 **netsnmp\_session** \* **snmp\_add\_full** (**netsnmp\_session** \*in\_session, **netsnmp\_transport** \*transport, int(\*fpre\_parse)(**netsnmp\_session** \*, **netsnmp\_transport** \*, void \*, int), int(\*fparse)(**netsnmp\_session** \*, **netsnmp\_pdu** \*, u\_char \*, size\_t), int(\*fpost\_parse)(**netsnmp\_session** \*, **netsnmp\_pdu** \*, int), int(\*fbuild)(**netsnmp\_session** \*, **netsnmp\_pdu** \*, u\_char \*, size\_t \*), int(\*frbuild)(**netsnmp\_session** \*, **netsnmp\_pdu** \*, u\_char \*\*, size\_t \*, size\_t \*), int(\*fcheck)(u\_char \*, size\_t), **netsnmp\_pdu** \*(\*fcreate\_pdu)(**netsnmp\_transport** \*, void \*, size\_t))\
 void \* **snmp\_sess\_add\_ex** (**netsnmp\_session** \*in\_session, **netsnmp\_transport** \*transport, int(\*fpre\_parse)(**netsnmp\_session** \*, **netsnmp\_transport** \*, void \*, int), int(\*fparse)(**netsnmp\_session** \*, **netsnmp\_pdu** \*, u\_char \*, size\_t), int(\*fpost\_parse)(**netsnmp\_session** \*, **netsnmp\_pdu** \*, int), int(\*fbuild)(**netsnmp\_session** \*, **netsnmp\_pdu** \*, u\_char \*, size\_t \*), int(\*frbuild)(**netsnmp\_session** \*, **netsnmp\_pdu** \*, u\_char \*\*, size\_t \*, size\_t \*), int(\*fcheck)(u\_char \*, size\_t), **netsnmp\_pdu** \*(\*fcreate\_pdu)(**netsnmp\_transport** \*, void \*, size\_t))\
 void \* **snmp\_sess\_add** (**netsnmp\_session** \*in\_session, **netsnmp\_transport** \*transport, int(\*fpre\_parse)(**netsnmp\_session** \*, **netsnmp\_transport** \*, void \*, int), int(\*fpost\_parse)(**netsnmp\_session** \*, **netsnmp\_pdu** \*, int))\
 void \* **snmp\_sess\_open** (**netsnmp\_session** \*pss)\
 int **create\_user\_from\_session** (**netsnmp\_session** \*session)\
 int **snmp\_sess\_close** (void \*sessp)\
 int **snmp\_close** (**netsnmp\_session** \*session)\
 int **snmp\_close\_sessions** (void)\
 int **snmpv3\_header\_realloc\_rbuild** (u\_char \*\*pkt, size\_t \*pkt\_len, size\_t \*offset, **netsnmp\_session** \*session, **netsnmp\_pdu** \*pdu)\
 int **snmpv3\_scopedPDU\_header\_realloc\_rbuild** (u\_char \*\*pkt, size\_t \*pkt\_len, size\_t \*offset, **netsnmp\_pdu** \*pdu, size\_t body\_len)\
 int **snmpv3\_packet\_realloc\_rbuild** (u\_char \*\*pkt, size\_t \*pkt\_len, size\_t \*offset, **netsnmp\_session** \*session, **netsnmp\_pdu** \*pdu, u\_char \*pdu\_data, size\_t pdu\_data\_len)\
 int **snmpv3\_packet\_build** (**netsnmp\_session** \*session, **netsnmp\_pdu** \*pdu, u\_char \*packet, size\_t \*out\_length, u\_char \*pdu\_data, size\_t pdu\_data\_len)\
 u\_char \* **snmp\_pdu\_build** (**netsnmp\_pdu** \*pdu, u\_char \*cp, size\_t \*out\_length)\
 int **snmp\_pdu\_realloc\_rbuild** (u\_char \*\*pkt, size\_t \*pkt\_len, size\_t \*offset, **netsnmp\_pdu** \*pdu)\
 int **snmpv3\_parse** (**netsnmp\_pdu** \*pdu, u\_char \*data, size\_t \*length, u\_char \*\*after\_header, **netsnmp\_session** \*sess)\
 int **snmpv3\_make\_report** (**netsnmp\_pdu** \*pdu, int error)\
 int **snmpv3\_get\_report\_type** (**netsnmp\_pdu** \*pdu)\
 int **snmp\_pdu\_parse** (**netsnmp\_pdu** \*pdu, u\_char \*data, size\_t \*length)\
 u\_char \* **snmpv3\_scopedPDU\_parse** (**netsnmp\_pdu** \*pdu, u\_char \*cp, size\_t \*length)\
 int **snmp\_send** (**netsnmp\_session** \*session, **netsnmp\_pdu** \*pdu)\
 int **snmp\_sess\_send** (void \*sessp, **netsnmp\_pdu** \*pdu)\
 int **snmp\_async\_send** (**netsnmp\_session** \*session, **netsnmp\_pdu** \*pdu, snmp\_callback callback, void \*cb\_data)\
 int **snmp\_sess\_async\_send** (void \*sessp, **netsnmp\_pdu** \*pdu, snmp\_callback callback, void \*cb\_data)\
 void **snmp\_free\_var** (**netsnmp\_variable\_list** \*var)\
 void **snmp\_free\_varbind** (**netsnmp\_variable\_list** \*var)\
 void **snmp\_free\_pdu** (**netsnmp\_pdu** \*pdu)\
 **netsnmp\_pdu** \* **snmp\_create\_sess\_pdu** (**netsnmp\_transport** \*transport, void \*opaque, size\_t olength)\
 void **snmp\_read** (fd\_set \*fdset)\
 int **\_sess\_read** (void \*sessp, fd\_set \*fdset)\
 int **snmp\_sess\_read** (void \*sessp, fd\_set \*fdset)\
 int **snmp\_select\_info** (int \*numfds, fd\_set \*fdset, struct timeval \*timeout, int \*block)\
 int **snmp\_sess\_select\_info** (void \*sessp, int \*numfds, fd\_set \*fdset, struct timeval \*timeout, int \*block)\
 void **snmp\_timeout** (void)\
 void **snmp\_sess\_timeout** (void \*sessp)\
 int **snmp\_oid\_ncompare** (const oid \*in\_name1, size\_t len1, const oid \*in\_name2, size\_t len2, size\_t max\_len)\
 int **snmp\_oid\_compare** (const oid \*in\_name1, size\_t len1, const oid \*in\_name2, size\_t len2)\
 *lexicographical compare two object identifiers.*  int **netsnmp\_oid\_compare\_ll** (const oid \*in\_name1, size\_t len1, const oid \*in\_name2, size\_t len2, size\_t \*offpt)\
 *lexicographical compare two object identifiers and return the point where they differ*  int **snmp\_oidtree\_compare** (const oid \*in\_name1, size\_t len1, const oid \*in\_name2, size\_t len2)\
 *Compares 2 OIDs to determine if they are equal up until the shortest length.*  int **snmp\_oidsubtree\_compare** (const oid \*in\_name1, size\_t len1, const oid \*in\_name2, size\_t len2)\
 int **netsnmp\_oid\_equals** (const oid \*in\_name1, size\_t len1, const oid \*in\_name2, size\_t len2)\
 *Compares 2 OIDs to determine if they are exactly equal.*  int **netsnmp\_oid\_is\_subtree** (const oid \*in\_name1, size\_t len1, const oid \*in\_name2, size\_t len2)\
 *Identical to netsnmp\_oid\_equals, except only the length up to len1 is compared.*  int **netsnmp\_oid\_find\_prefix** (const oid \*in\_name1, size\_t len1, const oid \*in\_name2, size\_t len2)\
 *Given two OIDs, determine the common prefix to them both.*  **netsnmp\_variable\_list** \* **snmp\_pdu\_add\_variable** (**netsnmp\_pdu** \*pdu, const oid \*name, size\_t name\_length, u\_char type, const u\_char \*value, size\_t len)\
 **netsnmp\_variable\_list** \* **snmp\_varlist\_add\_variable** (**netsnmp\_variable\_list** \*\*varlist, const oid \*name, size\_t name\_length, u\_char type, const u\_char \*value, size\_t len)\
 int **snmp\_add\_var** (**netsnmp\_pdu** \*pdu, const oid \*name, size\_t name\_length, char type, const char \*value)\
 void \* **snmp\_sess\_pointer** (**netsnmp\_session** \*session)\
 **netsnmp\_session** \* **snmp\_sess\_session** (void \*sessp)\
 **netsnmp\_transport** \* **snmp\_sess\_transport** (void \*sessp)\
 void **snmp\_sess\_transport\_set** (void \*sp, **netsnmp\_transport** \*t)\
 oid \* **snmp\_duplicate\_objid** (const oid \*objToCopy, size\_t objToCopyLen)\
 u\_int **snmp\_increment\_statistic** (int which)\
 u\_int **snmp\_increment\_statistic\_by** (int which, int count)\
 u\_int **snmp\_get\_statistic** (int which)\
 void **snmp\_init\_statistics** (void)\

### Variables

struct **module\_init\_list** \* **initlist** = NULL\
 struct **module\_init\_list** \* **noinitlist** = NULL\
 **netsnmp\_subtree** \* **subtrees**\
 long **long\_return**\
 u\_char **return\_buf** \[258\]\
 struct timeval **starttime**\
 int **callback\_master\_num** = -1\
 oid **nullOid** \[\] = { 0, 0 }\
 int **nullOidLen** = sizeof(nullOid)\
 struct **session\_list** \* **Sessions** = NULL\
 int **snmp\_errno** = 0\

## Define Documentation

### #define timercmp(tvp, uvp, cmp) Value:

```
/* CSTYLED */         ((tvp)->tv_sec cmp (uvp)->tv_sec ||         ((tvp)->tv_sec == (uvp)->tv_sec &&         /* CSTYLED */         (tvp)->tv_usec cmp (uvp)->tv_usec))
```

Definition at line 148 of file snmp\_api.c.

## Function Documentation

### int \_sess\_read (void \* sessp, fd\_set \* fdset)

XXX-rks: why no SNMP\_FREE(isp-\>packet); ??

XXX-rks: why no SNMP\_FREE(isp-\>packet); ??

Definition at line 5412 of file snmp\_api.c.

### int init\_agent (const char \* app)

Initialize the agent. Calls into init\_agent\_read\_config to set tha app's configuration file in the appropriate default storage space, NETSNMP\_DS\_LIB\_APPTYPE. Need to call init\_agent before calling init\_snmp.

**Parameters:**

*app* the configuration file to be read in, gets stored in default storage

**Returns:**

Returns non-zero on failure and zero on success.

**See also:**

**init\_snmp**

Definition at line 270 of file snmp\_vars.c.

### void init\_snmp (const char \* type)

Calls the functions to do config file loading and mib **module** parsing in the correct order. **Parameters:**

*type* label for the config file 'type'

**Returns:**

void

**See also:**

**init\_agent**

Definition at line 787 of file snmp\_api.c.

### int netsnmp\_oid\_compare\_ll (const oid \* in\_name1, size\_t len1, const oid \* in\_name2, size\_t len2, size\_t \* offpt)

lexicographical compare two object identifiers and return the point where they differ Caution: this method is called often by command responder applications (ie, agent).

**Returns:**

\-1 if name1 \< name2, 0 if name1 = name2, 1 if name1 \> name2 and offpt = len where name1 != name2

Definition at line 6350 of file snmp\_api.c.

### int netsnmp\_oid\_equals (const oid \* in\_name1, size\_t len1, const oid \* in\_name2, size\_t len2)

Compares 2 OIDs to determine if they are exactly equal. This should be faster than doing a snmp\_oid\_compare for different length OIDs, since the length is checked first and if != returns immediately. Might be very slighly faster if lengths are ==.

**Parameters:**

*in\_name1* A pointer to the first oid. \
 *len1* length of the first OID (in segments, not bytes) \
 *in\_name2* A pointer to the second oid. \
 *len2* length of the second OID (in segments, not bytes)

**Returns:**

0 if they are equal, 1 if they are not.

Definition at line 6431 of file snmp\_api.c.

### int netsnmp\_oid\_find\_prefix (const oid \* in\_name1, size\_t len1, const oid \* in\_name2, size\_t len2)

Given two OIDs, determine the common prefix to them both. **Parameters:**

*in\_name1* A pointer to the first oid. \
 *len1* Length of the first oid. \
 *in\_name2* A pointer to the second oid. \
 *len2* Length of the second oid.

**Returns:**

length of largest common index of commonality. 1 = first, 0 if none \* or -1 on error.

Definition at line 6487 of file snmp\_api.c.

### int netsnmp\_oid\_is\_subtree (const oid \* in\_name1, size\_t len1, const oid \* in\_name2, size\_t len2)

Identical to netsnmp\_oid\_equals, except only the length up to len1 is compared. Functionally, this determines if in\_name2 is equal or a subtree of in\_name1

**Parameters:**

*in\_name1* A pointer to the first oid. \
 *len1* length of the first OID (in segments, not bytes) \
 *in\_name2* A pointer to the second oid. \
 *len2* length of the second OID (in segments, not bytes)

**Returns:**

0 if one is a common prefix of the other.

Definition at line 6467 of file snmp\_api.c.

### int snmp\_oid\_compare (const oid \* in\_name1, size\_t len1, const oid \* in\_name2, size\_t len2)

lexicographical compare two object identifiers. Caution: this method is called often by command responder applications (ie, agent).

**Returns:**

\-1 if name1 \< name2, 0 if name1 = name2, 1 if name1 \> name2

Definition at line 6301 of file snmp\_api.c.

### int snmp\_oidtree\_compare (const oid \* in\_name1, size\_t len1, const oid \* in\_name2, size\_t len2)

Compares 2 OIDs to determine if they are equal up until the shortest length. **Parameters:**

*in\_name1* A pointer to the first oid. \
 *len1* length of the first OID (in segments, not bytes) \
 *in\_name2* A pointer to the second oid. \
 *len2* length of the second OID (in segments, not bytes)

**Returns:**

0 if they are equal, 1 if in\_name1 is \> in\_name2, or -1 if \<.

Definition at line 6403 of file snmp\_api.c.

### void snmp\_shutdown (const char \* type)

Shuts down the application, saving any needed persistent storage, and appropriate clean up. **Parameters:**

*type* Label for the config file 'type' used

**Returns:**

void

Definition at line 853 of file snmp\_api.c.

### int snmpv3\_engineID\_probe (struct session\_list \* slp, netsnmp\_session \* in\_session)

probe for peer engineID **Parameters:**

*slp* session list pointer. \
 *in\_session* session for errors

**Note:**

- •

  called by \_sess\_open(), snmp\_sess\_add\_ex()

- •

  in\_session is the user supplied session provided to those functions.

- •

  the first session in slp should the internal allocated copy of in\_session

**Returns:**

0 : error

1 : ok

Definition at line 1276 of file snmp\_api.c.

## Author

Generated automatically by Doxygen for net-snmp from the source code.
