eSNMP API Routines
inst2ip
Description
Use the EXACT mode for evaluating an instance for
Get
and
Set
operations. For
GetNext
and
GetBulk
operations, use the NEXT mode. When using NEXT mode,
this routine assumes that the search for data will be performed using greater
than or equal to matches.
Return Values
Carry value is 0
The routine completed successfully.
Carry value is 1
For EXACT match, an error occurred. For NEXT
match, there was a carry. (If there was a carry,
the returned ipaddr is 0.)
Examples
1.
The following example converts an instance to an IP address for a
Get
operation, which is an EXACT match.
#include <esnmp.h>
OID
*incoming = &method->varbind->name;
OBJECT
*object
= method->object;
int instLength;
unsigned int instance[6];
unsigned int ip_addr;
int
iface;
-- The instance is N.1.A.A.A.A where the A’s are the IP address--
instLength = oid2instance(incoming, object, instance, 6);
if (instLength == 6 && !inst2ip(&instance[2], 4, &ip_addr, TRUE,0)) {
iface = (int) instance[0];
}
else
return ESNMP_MTHD_noSuchInstance;
2.
The following example shows a
GetNext
operation in which there is only
one key or in which the ipaddr value is the least significant part of the
key. This is a NEXT match; therefore, a value of 1 is passed back for the
carry value.
#include <esnmp.h>
OID
*incoming = &method->varbind->name;
OBJECT
*object
= method->object;
int instLength;
unsigned int instance[6];
unsigned int ip_addr;
int
iface;
-- The instance is N.1.A.A.A.A where the A’s are the IP address--
instLength = oid2instance(incoming, object, instance, 6);
iface = (instLength < 1) ? 0 :(int) instance[0];
iface += inst2ip(&instance[2], instLength - 2, &ip_addr, FALSE, 1);
3.
In the following example, the search key consists of multiple parts. If
you are doing a
GetNext
operation, you must find the next possible value
for the search key, so that you can perform a cascaded greater-than or
equal-to search.
eSNMP API Routines 5–45