Search code examples
snmpnet-snmp

How to use variable list in Net-SNMP library


I'm doing some stuff with Net-SNMP library. Basically what I do is based on the sample application Simple_Application. What is not clear for me though is that part of code:

for (vars = response->variables; vars; vars = vars->next_variable) {
   // process variable
}

I did a lot of testing, read this post as well and it seems to me that you mostly get a scalar value with SNMP request. So the question is: when you get more than one variable as a response?


Solution

  • Each request may contain a number of (scalar) variable names, and the response message will have corresponding variable bindings for each requested variable. So looping through them does make sense in that use case.

    SNMP also allows the "get-next" request, which has similar semantics, and even the "get-bulk" requests, which may return a large number of variables.

    You can find examples of each request type in RFC 1905 (see sections 4.2.1 and 4.2.2 in particular).