0

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?

Community
  • 1
  • 1
UVV
  • 502
  • 8
  • 21

1 Answers1

2

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).

Jolta
  • 2,620
  • 1
  • 29
  • 42
  • Thanks for the explanation. So basically if I request one variable I should expect only one in response. What I'm just trying to figure out is what is better/more efficient in case I have a list of variables to request: either to iterate through all of them with GETNEXT (that's what I'm currently doing) or set all variables in one request. – UVV Aug 27 '14 at 13:12
  • Careful with the terminology there - don't confuse "get" and "set" in this context. ;) I'll assume you are only getting variables. If it's a fixed set of variables, it is more efficient to use one request for all of them. It saves you, for n variables, (round-trip-time * n) time units. If there are so many variables that the packet size could exceed the MTU of the network, you might run into fragmentation, which is not necessarily a problem, but some SNMP agents may choke on such big requests, and return the error code "tooBig" in that case. Get-next or get-bulk are good options, too. – Jolta Aug 27 '14 at 13:56
  • Thanks, I'm interested in gets so far :) . My confusion was because I want to traverse a table and it seems that GETNEXT is the only reasonable option here. – UVV Aug 27 '14 at 14:55
  • Yeah, mixing up get and set in this context seems to be dangerous :) – UVV Aug 27 '14 at 14:57
  • 1
    Yes, if you want to get multiple rows out of a table, then get-next is the correct choice, unless you are able to use get-bulk. Get-bulk is more efficient, doing the same job in fewer transactions. – Jolta Aug 28 '14 at 13:26