DIGITAL TCP/IP Services for OpenVMS
eSNMP Programming and Reference


Previous Contents Index


inst2ip

Returns an IP address derived from an OID instance.

Format

int inst2ip (unsigned int *instance, int *length, unsigned int *ipAddr, int *exact, int *carry)


Arguments

*instance

A pointer to an array of unsigned int containing the instance numbers returned by the oid2instance routine to be converted to an IP address.

The range for elements is between 0 and 255. Using the EXACT mode, the routine returns 1 if an element is out of range. Using the NEXT mode, a value greater than 255 causes that element to overflow. This value is set to 0 and the next most significant element is incremented, so it returns a lexically equivalent value of the next possible ipaddr.

*length

The number of elements in the instance array. Instances beyond four are ignored. If the length is less than four the missing values are assumed to be zero. A negative length results in an ipaddr value of zero. For an exact match (such as Get) there must be exactly four elements.

*ipAddr

A pointer indicating where to return the IP address value. This routine is in network byte order (the most significant element is first).

*exact

Can either be TRUE or FALSE.

TRUE means do an EXACT match. If any element is greater than 255 or if there are not exactly four elements, return a value of one. The carry argument is ignored.

FALSE means do a NEXT match. That is, return the lexically next IP address if the carry is set and the length is at least four. If there are fewer than four elements, assume the missing values are zero. If any one element contains a value greater than 255, then zero the value and increment the next most significant element. Return one only in the case where there is a carry from the most significant (the first) value.

*carry

Adds to the IP address on a NEXT match. If you are trying to determine the next possible IP address, pass in a one. Otherwise, pass in a zero. A length of less than four cancels the carry.

Description

For evaluation of an instance for Get and Set operations use the EXACT mode. For GetNext and GetBulk operations use the NEXT mode. When using this mode, the logic of the routine assumes that the search for data will be performed using greater than or equal to matches.

Return Values

CARRY IS ZERO The routine completed successfully.
CARRY IS ONE An error for either EXACT match or NEXT match. (If there was a carry, the returned ipaddr.)

Examples


 
#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; 
 


 
#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); 
 


 
#include <esnmp.h> 
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_addr, FALSE, 1); 
carry = inst2ip(&instance[5], instLength - 5, &ip_addr, FALSE, carry); 
iface += carry; 
if (iface > 0xFFFFFFFF) 
-- a carry caused an overflow in the most significant element 
return ESNMP_MTHD_noSuchInstance; 
 


cmp_oid

Compares two OID structures.

Format

int cmp_oid (oid *q, oid *p)


Description

This routine does an element-by-element comparison starting with the most significant element (element 0) and working toward the least significant element. If all other elements are equal, the OID with the fewest number of elements is considered less.

Return Values

NEGATIVE ONE The OID q is less than OID p.
ZERO The OID q is in OID p.
POSITIVE ONE The OID q is greater than OID p.

cmp_oid_prefix

Compares an OID against a prefix.

Format

int cmp_oid_prefix (oid *q, oid *prefix)


Description

A prefix could be the OID on an object in the object table. The elements beyond the prefix are the instance information.

This routine does an element-by-element comparison, starting with the most significant element (element 0) and working toward the least significant element. If all elements of the prefix OID match exactly with corresponding elements of OID q it is considered an even match if OID q contains additional elements. OID q is considered greater than the prefix if the first nonmatching element is larger. It is considered smaller if the first nonmatching element is less.


Return Values

NEGATIVE ONE The OID is less than the prefix.
ZERO The OID is in prefix.
POSITIVE ONE The OID is greater than the prefix.

Example


 
#include <esnmp.h> 
OID *q; 
OBJECT *object; 
if (cmp_oid_prefix(q, &object->oid) == 0) 
   printf("matches prefix\n"); 
 


clone_oid

Copies the OID.

Format

oid clone_oid (oid *new, oid *oid)


Arguments

*new

A pointer to the OID structure that is to receive the copy.

*oid

A pointer to the OID structure where the data is to be obtained.

Description

This routine dynamically allocates the element's buffer and inserts its pointer into the OID structure received. It is the responsibility of the caller to free this buffer.

Point to the OID structure that is to receive the new OID values and call this routine. Any previous value in the new OID structure is freed and the new values are dynamically allocated and inserted. Be sure to initialize the new OID structure with zeros if you do not want it to be freed.


Return Values

null An error or the pointer to the OID is returned.

Example


 
#include <esnmp.h> 
OID oid1; 
OID oid2; 
: 
: assume oid1 gets assigned a value 
: 
memset(&oid2, 0, sizeof(OCT)); 
if (clone_oid(&oid2, &oid1) == NULL) 
    DPRINTF((WARNING, "It did not work\n")); 
 


free_oid

Frees the OID structure's elements buffer.

Format

void free_oid (oid *oid)


Description

This routine frees the buffer pointed to by the OID->elements and zeros the field and the nelem structure.

Example


 
include <esnmp.h> 
OID oid; 
: 
: assume oid was assigned a value (perhaps with clone_oid() 
: and we are now finished with it. 
: 
free_oid(&oid); 
 


clone_buf

Duplicates a buffer in a dynamically allocated space.

Format

char clone_buf (char *str, int *len)


Arguments

*str

A pointer to the buffer to be duplicated.

*len

The number of bytes to be copied.

Description

One extra byte is always allocated and filled on the end with zeros. If the length is less than zero, the length is set to zero. There is always a buffer pointer, unless there is a malloc error.

Return Values

null A malloc error or the pointer to the allocated buffer that contains a copy of the original buffer is returned.

Example


 
#include <esnmp.h> 
char *str = "something nice"; 
char *copy; 
 


mem2oct

Converts a string, a buffer and length to an oct structure.

Format

oct *mem2oct (oct *new, char *buffer, int *len)


Description

The mem2oct routine dynamically allocates the buffer and inserts its pointer into the oct structure. The caller must free this buffer.

This routine does not allocate an oct structure. It calls the free_oct (new) routine first. Therefore, be sure to initialize the new OID structure with zeros if you do not want it to be freed.


Return Values

null An error or the pointer to the oct structure, the first argument, is returned.

Example


 
#include <esnmp.h> 
char buffer; 
int len; 
OCT abc; 
 
...buffer and len are initialized to something... 
 
memset(&abc, 0, sizeof(OCT)); 
if (mem2oct(&abc, buffer, len) == NULL) 
    DPRINTF((WARNING,"It did not work...\n")); 
 


cmp_oct

Compares two octets.

Format

int cmp_oct (oct *oct1, oct *oct2)


Description

The two octets are compared byte-by-byte for the length of the shortest octet. If all bytes are equal, the lengths are compared. An octet with a null pointer is considered the same as a zero length octet.

Return Values

NEGATIVE ONE The string pointed to by the first oct is less than the second.
ZERO The string pointed to by the first oct is equal.
POSITIVE ONE The string pointed to by the first oct is greater than the second.

Example


 
#include <esnmp.h> 
OCT abc, efg; 
 
...abc and efg are initialized to something... 
 
if (cmp_oct(&abc, &efg) > 0) 
    DPRINTF((WARNING,"octet abc is larger than efg...\n")); 
 


clone_oct

Makes a copy of the data in an oct Octet String structure.

Format

oct clone_oct (oct *new, oct *old)


Arguments

*new

A pointer to the oct structure receiving the data.

*old

A pointer to the oct structure where the data is to be obtained.

Description

The clone_oct routine dynamically allocates the buffer and inserts its pointer and length into the oct structure. The caller must free this buffer.

Note

This routine does not allocate an oct structure.

The previous value of the buffer on the new oct structure is freed prior to the new buffer being allocated. Be sure that the original value for the new ptr is zeroed before cloning, unless you want the old value freed.


Return Values

null An error or the pointer to the oct structure, the first argument, is returned.

Example


 
#include <esnmp.h> 
OCT octet1; 
OCT octet2; 
: 
: assume octet1 gets assigned a value 
: 
memset(&octet2, 0, sizeof(OCT)); 
if (clone_oct(&octet2, &octet1) == NULL) 
    DPRINTF((WARNING, "It did not work\n")); 
 


free_oct

Frees the octet.

Format

void free_oct (oct *oct)


Description

This routine frees the dynamically allocated buffer and zeros the pointer and length on the oct structure. If the buffer is already null this routine does nothing.

Note

This routine does not deallocate the oct structure; instead the buffer that it points to is deallocated.

Example


 
#include <esnmp.h> 
OCT octet; 
: 
: assume octet was assigned a value (perhaps with mem2oct() 
: and we are now finished with it. 
: 
free_oct(&octet); 
 


free_varbind_date

Frees the data on the VARBIND structure. However, this routine does not free the VARBIND structure itself.

Format

void free_varbind_data (varbind *vb)


Example


 
#include <esnmp.h> 
VARBIND *vb; 
 
vb = (VARBIND*)malloc(sizeof(VARBIND)); 
 
... initialized varbind data, perhaps with mem2oct() and 
    instance2oid().  You are now finish with it. 
 
free_varbind_data(vb); 
free(vb); 
 


Index Contents