Syntax
#include <snmp_dpi.h> snmp_dpi_set_packet *mkDPIset( /* Make DPI set packet tree */ snmp_dpi_set_packet *packet_p, /* ptr to SET structure */ char *group_p, /* ptr to group ID(sub-tree)*/ char *instance_p,/* ptr to instance OIDstring*/ int value_type,/* value type: SNMP_TYPE_xxx*/ int value_len, /* length of value */ void *value_p); /* ptr to value */
Parameters
packet_p
See DPI SNMP Value Types for a list of currently defined value types.
The maximum value is 64K -1. However, the implementation often makes the length significantly less. The OS/2 implementation limit is 4K. The SNMP_DPI_BUFFSIZE in the snmp_dpi.h include file defines the limit for OS/2.
Return Values
If successful and a chain of one or more packets was passed in the packet_p parameter, the same pointer that was passed in packet_p is returned. A new dynamically allocated structure has then been added to the end of that chain of snmp_dpi_get_packet structures.
If successful and a NULL pointer was passed in the packet_p parameter, a pointer to a new dynamically allocated structure is returned.
If failure, a NULL pointer is returned.
Description
The mkDPIset() function is used at the subagent side to prepare a chain of one or more snmp_dpi_set_packet structures. This chain is used to create a DPI RESPONSE packet by a call to mkDPIresponse() which can be sent to the DPI peer, which is normally a DPI capable SNMP agent.
The chain of snmp_dpi_set_packet structures can also be used to create a DPI TRAP packet that includes varBinds as explained in The mkDPItrap() Function.
For the value_len, the maximum value is 64K -1. However, the implementation often makes the length significantly less. For example the SNMP PDU size may be limited to 484 bytes at the SNMP manager or agent side. In this case, the total response packet cannot exceed 484 bytes, so a value_len is limited by that. You can send the DPI packet to the agent, but the manager will never see it.
Examples
#include <snmp_dpi.h> unsigned char *pack_p;
snmp_dpi_hdr *hdr_p;
snmp_dpi_set_packet *set_p;
long int num;
hdr_p = pDPIpacket(pack_p) /* parse incoming packet */
/* assume it's in pack_p */
if (hdr_p) {
/* analyze packet, assume GET, no error */
set_p = mkDPIset(snmp_dpi_set_packet_NULL_p,
"1.3.6.1.2.3.4.5.", "1.0",
SNMP_TYPE_Integer32,
sizeof(num), &num);
if (set_p) {
pack_p = mkDPIresponse(hdr_p,
SNMP_ERROR_noError,
0L, set_p);
if (pack_p)
/* send packet to subagent */
} /* endif */
} /* endif */
} /* endif */
The mkDPIset() function is used at the agent side to prepare a chain of one or more snmp_dpi_set_packet structures. This chain is normally anchored in an snmp_dpi_hdr structure that has its packet_type field set to SNMP_DPI_SET, SNMP_DPI_COMMIT or SNMP_DPI_UNDO. When all varBinds have been prepared into snmp_dpi_set_packet structures, a call can be made to mkDPIpacket() which will serialize the DPI parse tree into a DPI packet that can be sent to the DPI peer, which is normally a subagent.
Examples
#include <snmp_dpi.h>
unsigned char *pack_p;
snmp_dpi_hdr *hdr_p;
long int num;
hdr_p = mkDPIhdr(SNMP_DPI_SET);
if (hdr_p) {
hdr_p->data_u.set_p =
mkDPIset(snmp_dpi_set_packet_NULL_p,
"1.3.6.1.2.3.4.5.", "1.0",
SNMP_TYPE_Integer32,
sizeof(num), &num);
if (hdr_p->data_u.set_p) {
pack_p = mkDPIpacket(hdr_p);
if (pack_p)
/* send packet to subagent */
} /* endif */
} /* endif */
} /* endif */
If you must chain many snmp_dpi_set_packet structures, be sure to note that the packets are chained only by forward pointers. It is recommended that you use the last structure in the existing chain as the packet_p parameter. Then, the underlying code does not have to scan through a possibly long chain of structures in order to chain the new structure at the end.
In the next example let's assume that we want to chain 20 snmp_dpi_set_packet structures as a response to a GETBULK.
Examples
#include <snmp_dpi.h>
unsigned char *pack_p;
snmp_dpi_hdr *hdr_p;
snmp_dpi_set_packet *first_p;
snmp_dpi_set_packet *set_p;
long int num[20];
int i;
hdr_p = pDPIpacket(pack_p); /* parse incoming packet */
/* assume it's in pack_p */
if (hdr_p) {
/* analyze packet, assume GETBULK, no error. In this */
/* example we do not check max_repetitions as we should */
set_p = snmp_dpi_set_packet_NULL_p;
first_p = snmp_dpi_set_packet_NULL_p;
for (i=0; i<20; i++) {
char instance[5];
sprintf(instance, "%1.%d", i+1);
set_p = mkDPIset(set_p,
"1.3.6.1.2.3.4.5.", instance,
SNMP_TYPE_Integer32,
sizeof(num), &num[i]);
if (set_p) {
if (first_p) continue; /* OK, iterate for loop */
first_p = set_p; /* remember first one */
} else if (first_p) { /* failed to mkDPIset */
fDPIset(first_p) /* free allocated memory */
first_p = snmp_dpi_set_packet_NULL_p; /* reset */
} /* endif */
} /* endfor */
if (first_p) {
pack_p = mkDPIresponse(hdr_p,
SNMP_ERROR_noError,
0L, first_p);
if (pack_p)
/* send packet to subagent */
} /* endif */
} /* endif */
} /* endif */
Related Information
The pDPIpacket() Function
The mkDPIresponse() Function
The mkDPItrap() Function
The snmp_dpi_hdr Structure
The snmp_dpi_set_packet Structure
DPI SNMP Value Types
Value Representation