op_pk_nfd_type()
Abstract
Obtains the type of a field in the specified packet; the field-of-interest is specified by name.
Syntax
op_pk_nfd_type (pkptr, fd_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_fmt(), op_pk_copy(), op_pk_get(), op_subq_pk_access(), and op_subq_pk_remove().] |
fd_name |
const char* |
name of the field-of-interest [This name should be a defined field within the packet’s format; however, no error will occur if it is not. Instead, the value OPC_FIELD_TYPE_UNSPEC will be returned indicating the specified field is not defined in the packet.] |
Return Type
int
Type of the specified field.
[This value is an integer code which represents the field type (see Table 55 “Field Type Symbolic Constants“ on page 14); the possible values of this code are also listed in the Details section.]
Example
/* pull the next packet off the queue */
pkptr = op_subq_pk_remove (0, OPC_QPOS_HEAD);
/* determine the type of the payload field */
switch (op_pk_nfd_type (pkptr, "payload"))
{
case OPC_FIELD_TYPE_INTEGER:
op_pk_nfd_get (pkptr, "payload", &val_i);
printf ("Field (%d): Type (integer) Value (%d)\n", j, val_i); break;
case OPC_FIELD_TYPE_DOUBLE:
op_pk_nfd_get (pkptr, "payload", &val_d);
printf ("Field (%d): Type (double) Value (%g)\n", j, val_d); break;
}
Details
This KP returns a numeric code which represents the type of the specified field; the value of the code can be compared to the following symbolic constants:
OPC_FIELD_TYPE_INTEGEROPC_FIELD_TYPE_DOUBLEOPC_FIELD_TYPE_STRUCTOPC_FIELD_TYPE_INFOOPC_FIELD_TYPE_PACKETOPC_FIELD_TYPE_UNSPEC
The constant OPC_FIELD_TYPE_UNSPEC is returned if a recoverable error occurs.
Purpose
Provides a mechanism to determine the type of a packet field. Typically this is used when a packet is received by a process that is written generically, so that it can process diverse packet formats. Unlike the unformatted version of this KP, op_pk_fd_type(), the name of the field must be specified, so this KP will most likely be used when several packet formats are similar, with the same field names, but different field types.
This KP should only be applied to formatted packets; otherwise the returned type code for any field name passed to this KP will be OPC_FIELD_TYPE_UNSPEC.
Errors
- Program Abort: Segmentation violation. (due to an invalid packet pointer or
fd_nameargument) - Program Abort: Packet pointer is NIL.
- Program Abort: Packet pointer references destroyed packet.
- Recoverable Error: No field named (<fd_name>) in packet (<pk_id>).
Reference
- Use the KP
op_pk_fd_type()to determine the type of a field in an unformatted (or formatted) packet, using a numeric index to specify the field-of-interest (this unformatted version of the KP is often more useful, since it supports the construction of loops for completely generic packet processing) - Use the KP
op_pk_nfd_size()to determine the size of a packet field - Use the KP
op_pk_nfd_is_set()to determine if a packet field is set