gtpc2m8lC/C++ Language Support User's Guide

tpf_snmp_BER_encode-Encode SNMP Variables in BER Format

This function encodes Simple Network Management Protocol (SNMP) variables using a subset of the basic encoding rules (BER). Use this function when passing variables from the UMIB user exit and when encoding a variable binding list for the tpf_itrpc C/C++ function or the ITRPC macro. For information about BER encoding, see ISO 8825 Part 1: Basic Encoding Rules. Go to http://www.iso.ch/ to view ISO 8825.

Format

#include   <c$snmp.h>
int tpf_snmp_BER_encode(struct snmp_struct *snmp_structure_ptr);      

snmp_structure_ptr
A pointer to snmp_struct. This structure contains the following elements:

snmp_input_type
The unsigned character defining the type of variable to encode. Use one of the following values:

ISNMP_TYPE_INTEGER
For integer-type values.

ISNMP_TYPE_DISPLAYSTRING
For display string-type values.

ISNMP_TYPE_OBJECTID
For object ID-type values.

ISNMP_TYPE_IP_ADDRESS
For Internet Protocol (IP) address-type values.

ISNMP_TYPE_COUNTER
For counter-type values.

ISNMP_TYPE_GAUGE
For gauge-type values.

ISNMP_TYPE_TIMETICKS
For time ticks-type values.

ISNMP_TYPE_SEQUENCE_OF
For sequence of-type values.

snmp_input_length
The integer value defining the length of the variable to encode that is pointed to by snmp_input_value. Valid lengths are in the range 1-32 767 bytes.
Note:
When using SNMP agent support, the maximum packet size is 548.

snmp_input_value
The pointer to the value to be encoded.

snmp_output_value
The pointer to the storage in which to build the variable encoded in BER format.

Normal Return

A value of 0. The following field in snmp_struct was updated:

snmp_output_length
The integer value defining the length of the encoded value that is pointed to by snmp_output_value.

snmp_output_value
The pointer that now contains the BER-encoded value.

Error Return

A value of -1. An unsupported type or length was passed. No elements in snmp_struct were updated.

Programming Considerations

This function is implemented in dynamic link library (DLL) CNMP. You must use the definition side-deck for DLL CNMP to link-edit an application that uses this function.

Examples

The following example encodes a 7-byte object identifier pointed to by oid_ptr in BER format.

#include <c$snmp.h>
#include <stdlib.h>
#include <string.h>
 
extern "C" int QZZ8()
{
 
struct   snmp_struct	snmp_structure_ptr;
char     buffer_ptr[100];
char     *oid_ptr;
int      rc,length=0;
 
oid_ptr = (char *)malloc(24);
memcpy(oid_ptr, "\x2B\x06\x01\x02\x01\x04\x01", 7);
 
snmp_structure_ptr.snmp_input_type   = ISNMP_TYPE_OBJECTID;
snmp_structure_ptr.snmp_input_length = 7;
snmp_structure_ptr.snmp_input_value  = oid_ptr;
snmp_structure_ptr.snmp_output_value = buffer_ptr;
 
rc = tpf_snmp_BER_encode(&snmp_structure_ptr);
if (rc == -1)
     return(-1);
 
length += snmp_structure_ptr.snmp_output_length;
return (0);
 
}
 

Related Information