op_pk_format()
Abstract
Obtains the name of the packet format associated with the specified packet.
Syntax
op_pk_format (pkptr, fmt_name)
| Argument | Type | Description |
|---|---|---|
pkptr |
Packet* |
pointer to the packet-of-interest [A pointer to a packet can be obtained from many KPs, including op_pk_create(), op_pk_create_fmt(), op_pk_copy(), op_pk_get(), op_subq_pk_access(), and `op_subq_pk_remove().] |
fmt_name |
char* |
name of the packet’s format (filled in by this KP) [This value should be a statically declared character array, or a character pointer which points to dynamically allocated memory; either way, it must point to a string large enough to hold the format name for the specified packet. If the specified packet is unformatted, the string is set to “NONE”.] |
Return Type
void
No return value.
Example
/* obtain the arriving packet */
pkptr = op_pk_get (INPUT_STRM);
/* determine the format of the packet */
op_pk_format (pkptr, pk_format);
/* print out a debug statement */
printf ("processing packet with format [%s]\n", pk_format);
/* store the packet in the second subqueue */
op_subq_pk_insert (1, pkptr, OPC_QPOS_TAIL);
Details
Formatted packets can be created via the KP op_pk_create_fmt(). At creation, a format is specified that sets the internal structure of the created packet. Packet formats can be defined in a mode of the Packet Format Editor, or through an Ema program. Formats consist of a list of named packet fields, each of which has a specified type, a size (in terms of bits), and a default value which can be set or unset upon packet creation.
Every formatted packet has an associated format. Both unformatted and formatted packets can be passed to this KP, but only formatted packets will produce meaningful results; unformatted packets cause the string “NONE” to be assigned to the passed character pointer.
Purpose
Provides a mechanism for determining the name of a packet’s format. This can be useful information for performing branches in process logic which are conditional on the type of packet being processed. Debug statements that show the formats of arriving packets are also useful, as in the example on the previous page.
Errors
- Program Abort: Segmentation violation. (due to an invalid packet pointer, malformed packet or invalid
fmt_nameargument) - Program Abort: Packet pointer is NIL.
- Program Abort: Packet pointer references destroyed packet.
Reference
- Use the KP op_pk_is_format() to test the name of a packet format
- Use the KP op_pk_create_fmt() to create a packet based on a specified format
- Use the KP op_pk_nfd_type() to determine the type of a packet’s named field
- Use the KP op_pk_nfd_name_to_index() to perform a conversion of a field name into a field index
- Use the KP op_pk_nfd_get() to obtain the value of a packet’s named field
- Use the KP op_pk_nfd_set() to assign the value of a packet’s named field