NETSNMP_VARBIND_API(3)
NETSNMP_VARBIND_API(3) π
okay bestie, so this is the Net-SNMP manual for the netsnmp_varbind_api functions β section 3, library calls, the whole vibe. varbinds are literally the little name+value bundles that SNMP is made of, and this page is the entire guide to making them, filling them in, printing them and yeeting them into the void. let's get into it π¦
β¨ 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 β these are the netsnmp_varbind_api functions, periodt π
πΈ 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 π
so the functions that mess with variable bindings split into four little friend groups β making them, setting their values, printing them out, and freeing them. four groups, four vibes, one slay. π«Ά
π¦ Creation π¦
snmp_pdu_add_variable creates a brand new varbind structure, all initialised with the name (objid, objidlen), the syntax (type) and the value (value, len) you hand it. then it adds that varbind to the end of the varbind list in the PDU you gave it. iconic behaviour honestly.
snmp_varlist_add_variable is basically the same energy, except it appends the new varbind to the end of the varbind list you provide. and when you're adding the very first varbind to an empty list, you just pass the address of the head of the list, like:
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);
both of these routines return a pointer to the new varbind structure β or NULL if the varbind creation fails π (bestie it happens).
snmp_add_null_var is the convenience queen: it adds an empty varbind to the PDU, so you don't have to spell out the NULL value yourself. this is the normal mechanism for constructing a GET (or similar) information retrieval request. again, it returns a pointer to the new varbind, or NULL.
snmp_clone_varbind makes a copy of each varbind in the specified list, and returns a pointer to the head of the new list β or NULL if the cloning fails. copy-paste but make it C. π
π¦ Setting of values π¦
snmp_set_var_objidsets the name of the varbind structure to the specified OID.snmp_set_var_typed_valuesets the syntax type and the value of the varbind structure.snmp_set_var_valuesets the value of the varbind structure, leaving the syntax type unchanged. she's not touching the type, not her business.snmp_set_var_typed_integeris a convenience function that sets 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. yes, 0 is the good one here, don't @ me. π
π¦ Output π¦
print_variable takes an object identifier (as returned by read_objid, snmp_parse_oid or get_module_node) plus an instance of such a variable, and prints to standard output the textual form of the object identifier together with the value of the variable. both. the whole package. π₯
fprint_variable does the same thing, but it prints to the FILE pointer you passed as 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 wasn't large enough. in that too-small case, buf will typically contain a truncated version of the information β but heads up, that behaviour is not guaranteed. also important: this function replaces the obsolete function sprint_variable.
print_value, fprint_value, and snprint_value do the same as the equivalent print_variable routines, except they only display the value of the variable, without the corresponding object identifier. value only, no name, she's mysterious like that. π
for displaying the OID of a varbind, go look at netsnmp_mib_api(3) instead.
π¦ Deletion π¦
snmp_free_var releases all the memory used by the given varbind structure. bye bestie π
snmp_free_varbind releases all the memory used by each varbind structure in the varbind list you provided. the whole group chat, gone. no leaks, no cap. π
π SEE ALSO π
and that's the whole page, bestie!! this was Net-SNMP version V5.9.5.2, dated 13 Aug 2010 β yes she's an elder but she's still serving β¨π thanks for reading, go forth and free your varbinds ππ¦πΈ
π¦ where this page comes from
- alpine 3.23: net-snmp-doc 5.9.5.2-r0 Β· Net-SNMP
- alpine 3.24: net-snmp-doc 5.9.5.2-r0 Β· Net-SNMP
- arch rolling: net-snmp 5.9.5.2-2 Β· BSD
- fedora 44: net-snmp-devel 1:5.9.5.2-4.fc44 Β· MIT-CMU AND BSD-3-Clause AND MIT
- fedora 44: net-snmp-devel 1:5.9.5.2-4.fc44 Β· MIT-CMU AND BSD-3-Clause AND MIT
- nixos 26.05: net-snmp 5.9.5.2
- nixpkgs unstable: net-snmp 5.9.5.2
- ubuntu stonking: libsnmp-dev 5.9.5.2+dfsg-2.1ubuntu5
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms