gtpc2m8bC/C++ Language Support User's Guide

tpf_itrpc-Send Simple Network Management Protocol User Trap

This function sends a Simple Network Management Protocol (SNMP) enterprise-specific trap to the remote SNMP destination managers specified in the /etc/snmp.cfg SNMP configuration file.

Format

#include  <c$snmp.h>
int    tpf_itrpc(char* varlist, int varlen, int spectrap);

varlist
A pointer to the variable binding list associated with the SNMP enterprise-specific trap being generated.

varlen
The length, in bytes, of the list specified with varlist. If there is no variable binding list, set this parameter to 0.

spectrap
An implementation-specific value for the SNMP enterprise-specific trap that describes the trap being generated.

Normal Return

Table 20. tpf_itrpc Normal Return

Value Name Return Code Description
ISNMP_ITRPC_OK 0 An SNMP enterprise-specific trap was successfully built and queued to be sent to the network.

Error Return

If an attempt to build an SNMP enterprise-specific trap is unsuccessful, you will receive one of the following error returns:

Table 21. tpf_itrpc Error Return

Value Name Return Code Description
ISNMP_ITRPC_STATE_ERROR -1 The TPF system is not in CRAS state or higher.
ISNMP_ITRPC_CONFIG_ERROR -2 The /etc/snmp.cfg SNMP configuration file was not refreshed successfully.

Do the following:

  1. Create or fix the /etc/snmp.cfg SNMP configuration file.
  2. Enter the ZSNMP command with the REFRESH parameter specified.
  3. Issue the tpf_itrpc function again.
ISNMP_ITRPC_NO_TRAPS -3 The /etc/snmp.cfg SNMP configuration file specifies that the TRAPIP keyword is coded as NONE, disabling SNMP trap support.

If you want to send traps, code the TRAPIP keyword in the /etc/snmp.cfg SNMP configuration file with a valid SNMP destination manager IP address or host name.

ISNMP_ITRPC_ENCODE_ERROR -4 An error occurred when encoding one of the trap values.
ISNMP_ITRPC_SIZE_ERROR -5 The size of the trap exceeded the maximum message size of 548 bytes.

Programming Considerations

Examples

The following example sends the enterprise-specific trap defined in spectrap, and containing the variable binding list pointed to by encoded_list, to all the SNMP destination managers specified in the /etc/snmp.cfg SNMP configuration file.

/**********************************************************************/
/*                 Include files                                      */
/**********************************************************************/
#include <c$snmp.h>
#include <stdlib.h>
#include <string.h>
/**********************************************************************/
/*                      #DEFINES                                      */
/**********************************************************************/
#define  SPECTRAP       4
 
/*********************************************************************/
/*********************************************************************/
extern "C" void QZZ2()
{
 
 int           varlen = 0, spectrap = 0, rc;
 char          object_id[24] = "\x2b\x6\x1\x4\x1\x1";
 char          *temp;
 char             encoded_var[100];
 int              encoded_var_len = 0;
 char          encoded_bind[100];
 int           encoded_bind_len;
 char             encoded_list[100];
 int           encoded_list_len
 int           value=100;
 struct        snmp_struct  encode_struct;
 
 
temp = encoded_var;
 
/*  Encode the OBJECT ID for the Variable Binding */
 
encode_struct.snmp_input_value = object_id
encode_struct.snmp_input_length = strlen(object_id);
encode_struct.snmp_input_type = ISNMP_TYPE_OBJECTID;
encode_struct.snmp_output_value = encoded_var;
 
   if (tpf_snmp_BER_encode(&encode_struct) != 0)
      exit(0);
 
encoded_var_len += encode_struct.snmp_output_length;
temp += encode_struct.snmp_output_length;
 
/* Encode the value and copy the encoded value after the */
/* OBJECT ID.  Increment the size of the VAR-BIND        */
 
encode_struct.snmp_input_value = &value;
encode_struct.snmp_input_length = sizeof(int);
encode_struct.snmp_input_type = ISNMP_TYPE_INTEGER;
encode_struct.snmp_output_value = temp;
 
   if (tpf_snmp_BER_encode(&encode_struct) != 0)
      exit(0);
 
 
encoded_var_len = encode_struct.snmp_output_length;
 
 
/* Encode the variable bind as a SEQUENCE OF            */
 
encode_struct.snmp_input_value = encoded_var;
encode_struct.snmp_input_length = encoded_var_len;
encode_struct.snmp_input_type = ISNMP_TYPE_SEQUENCE_OF;
encode_struct.snmp_output_value = encoded_bind;
 
   if (tpf_snmp_BER_encode(&encode_struct) != 0)
      exit(0);
 
 
encoded_bind_len = encode_struct.snmp_output_length;
 
 
/* Variable Binding complete.  Encode the entire        */
/* variable binding list as a sequence of               */
 
encode_struct.snmp_input_value = encoded_bind;
encode_struct.snmp_input_length = encoded_bind_len;
encode_struct.snmp_input_type = ISNMP_TYPE_SEQUENCE_OF;
encode_struct.snmp_output_value = encoded_list;
 
   if (tpf_snmp_BER_encode(&encode_struct) != 0)
      exit(0);
 
 
encoded_list_len = encode_struct.snmp_output_length;
 
/* Fill in the specific TRAP information and call       */
/* tpf_itrpc passing the variable binding list and      */
/* length                                               */
 
 spectrap = SPECTRAP;
 
 rc = tpf_itrpc(encoded_list, encoded_list_len, spectrap);
 
 exit(0);
}
 

Related Information

tpf_snmp_BER_encode-Encode SNMP Variables in BER Format.