beautypg.com

Compaq AAR04BCTE User Manual

Page 104

background image

eSNMP API Routines
inst2ip

The search key consists of a number and two ipaddr values. These are
represented in the instance part of the OID as n.A.A.A.A.B.B.B.B, where:

n is a single value integer.

The A.A.A.A portion makes up one IP address.

The B.B.B.B portion makes up a second IP address.

If all elements are given, the total length of the search key is 9. In this
case, you perform the operation as follows:

Convert the least significant part of the key (that is, the B.B.B.B
portion), by calling the

inst2ip

routine, passing it a 1 for the carry

and (length - 5) for the length.

If the conversion of the B.B.B.B portion generates a carry (that is,
returns 1), you pass it to the next most significant part of the key.

Convert the A.A.A.A portion by calling the

inst2ip

routine, passing it

(length - 1) for the length and the carry returned from the conversion
of the B.B.B.B portion.

The most significant element n is a number; therefore, add the carry
from the A.A.A.A conversion to the number. If the result overflows,
then the search key is not valid.

#include
OID

*incoming = &method->varbind->name;

OBJECT

*object

= method->object;

int instLength;
unsigned int instance[9];
unsigned int ip_addrA;
unsigned int ip_addrB;
int

iface;

int

carry;

-- The instance is N.A.A.A.A.B.B.B.B --
instLength = oid2instance(incoming, object, instance, 9);
iface = (instLength < 1) ? 0 :(int) instance[0];
carry = inst2ip(&instance[1], instLength - 1, &ip_addrB, FALSE, 1);
carry = inst2ip(&instance[5], instLength - 5, &ip_addrA, FALSE, carry);
iface += carry;
if (iface > carry) {

-- a carry caused an overflow in the most significant element
return ESNMP_MTHD_noSuchInstance;
}

5–46 eSNMP API Routines