---
name: "netsnmp_varbind_api"
section: "3"
platform: "linux"
package: "net-snmp"
version: "5.9.5.2-2"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/netsnmp_varbind_api"
---

# netsnmp\_varbind\_api(3)

netsnmp\_varbind\_api functions

## NAME

snmp\_pdu\_add\_variable, snmp\_varlist\_add\_variable, snmp\_add\_null\_var, snmp\_clone\_varbind, snmp\_set\_var\_objid, snmp\_set\_var\_value, snmp\_set\_var\_typed\_value, snmp\_set\_var\_typed\_integer, print\_variable, fprint\_variable, snprint\_variable, print\_value, fprint\_value, snprint\_value, snmp\_free\_var, snmp\_free\_varbind - netsnmp\_varbind\_api functions

## SYNOPSIS

**#include \<net-snmp/varbind\_api.h\>**

### Creation

**netsnmp\_variable\_list \*snmp\_pdu\_add\_variable(**\
                      **netsnmp\_pdu \****pdu***,**\
                      **const oid \****objid***, size\_t** *objidlen***,**\
                      **u\_char** *type***, const void \****value***, size\_t** *len***);**\
 **netsnmp\_variable\_list \*snmp\_varlist\_add\_variable(**\
                      **netsnmp\_variable\_list \****varlist***,**\
                      **const oid \****objid***, size\_t** *objidlen***,**\
                      **u\_char** *type***, const void \****value***, size\_t** *len***);**\
 **netsnmp\_variable\_list \*snmp\_add\_null\_var(**\
                      **netsnmp\_pdu \****pdu***,**\
                      **const oid \****objid***, size\_t** *objidlen***);**

**netsnmp\_variable\_list \*snmp\_clone\_varbind(**\
                      **netsnmp\_variable\_list \****varlist***);**

### Setting Values

**int  snmp\_set\_var\_objid( netsnmp\_variable\_list\*** *variable***,**\
                      **const oid \*** *objid***, size\_t** *objidlen***);**\
 **int  snmp\_set\_var\_value( netsnmp\_variable\_list\*** *variable***,**\
                      **const void \*** *value***, size\_t** *vallen***);**\
 **int  snmp\_set\_var\_typed\_value( netsnmp\_variable\_list\*** *variable***,**\
                      **u\_char** *type***,**\
                      **const void \*** *value***, size\_t** *vallen***);**\
 **int  snmp\_set\_var\_typed\_integer( netsnmp\_variable\_list\*** *variable***,**\
                      **u\_char** *type***, long** *value***);**\

### Output

**void  print\_variable(const oid \****objid***, size\_t** *objidlen***,**\
                      **const netsnmp\_variable\_list \****variable***);**\
 **void fprint\_variable(FILE \****fp***,**\
                      **const oid \****objid***, size\_t** *objidlen***,**\
                      **const netsnmp\_variable\_list \****variable***);**\
 **int snprint\_variable(char \****buf***, size\_t** *len***,**\
                      **const oid \****objid***, size\_t** *objidlen***,**\
                      **const netsnmp\_variable\_list \****variable***);**

**void  print\_value(const oid \****objid***, size\_t** *objidlen***,**\
                      **const netsnmp\_variable\_list \****variable***);**\
 **void fprint\_value(FILE \****fp***,**\
                      **const oid \****objid***, size\_t** *objidlen***,**\
                      **const netsnmp\_variable\_list \****variable***);**\
 **int snprint\_value(char \****buf***, size\_t** *len***,**\
                      **const oid \****objid***, size\_t** *objidlen***,**\
                      **const netsnmp\_variable\_list \****variable***);**\
\

### Deletion

**void snmp\_free\_var(       netsnmp\_variable\_list \****variable***);**\
 **void snmp\_free\_varbind( netsnmp\_variable\_list \****variables***);**\

## DESCRIPTION

The functions dealing with variable bindings fall into four groups -  dealing with the creation, setting of values, output and deletion of varbinds.

### Creation

**snmp\_pdu\_add\_variable** will create a new varbind structure, initialised with the name ( *objid*, *objidlen* ), syntax ( *type* ) and value ( *value ,  len* ) provided. This varbind is then added to the end of the varbind list in the given PDU.

**snmp\_varlist\_add\_variable** is similar, but appends the new varbind to the end of the varbind list provided. When adding the first varbind to an empty list, simply pass the address of the head of the list:

-

    netsnmp\_variable\_list \*vl = NULL;\
     snmp\_varlist\_add\_variable(\
               &vl, name1, name1\_len,\
               ASN\_*TYPE*, &val1, val1\_len);\
     snmp\_varlist\_add\_variable(\
               &vl, name2, name2\_len,\
               ASN\_*TYPE*, &val2, val2\_len);

In both cases, the routine will return a pointer to the new varbind structure (or NULL if the varbind creation fails).

**snmp\_add\_null\_var** is a convenience function to add an empty varbind to the PDU. without needing to specify the NULL value explicitly. This is the normal mechanism for constructing a GET (or similar) information retrieval request.\
 Again, this returns a pointer to the new varbind, or NULL.

**snmp\_clone\_varbind** creates a copy of each varbind in the specified list, returning a pointer to the head of the new list (or NULL if the cloning fails).\

### Setting of values

**snmp\_set\_var\_objid** sets the name of the varbind structure to the specified OID.\
 **snmp\_set\_var\_typed\_value** sets the syntax type and value of the varbind structure.\
 **snmp\_set\_var\_value** sets the value of the varbind structure, leaving the syntax type unchanged.\
 **snmp\_set\_var\_typed\_integer** is a convenience function to set the syntax type and value for a 32-bit integer-based varbind.

All four of these return 0 if the assignment is successful, or 1 if it is not.

### Output

**print\_variable** will take an object identifier (as returned by **read\_objid**, **snmp\_parse\_oid** or **get\_module\_node**) and an instance of such a variable, and prints to the standard output the textual form of the object identifier together with the value of the variable.

**fprint\_variable** does the same, but prints to the FILE pointer specified by the initial parameter.

**snprint\_variable** prints the same information into the buffer pointed to by *buf* which is of length *len*. It returns the number of characters printed, or -1 if the buffer was not large enough.  In the latter case, *buf* will typically contained a truncated version of the information (but this behaviour is not guaranteed).  This function replaces the obsolete function **sprint\_variable**.

**print\_value**, **fprint\_value**, and **snprint\_value** do the same as the equivalent **print\_variable** routines, but only displaying the value of the variable, without the corresponding object identifier.

For displaying the OID of a varbind, see [**netsnmp\_mib\_api**(3)](/netsnmp_mib_api/3.md).\

### Deletion

**snmp\_free\_var** releases all memory used by the given varbind structure.\
 **snmp\_free\_varbind** releases all memory used by each varbind structure in the varbind list provided.\

## SEE ALSO

[**netsnmp\_pdu\_api**(3)](/netsnmp_pdu_api/3.md) [**netsnmp\_mib\_api**(3)](/netsnmp_mib_api/3.md)
