op_pk_name_to_index()
Abstract
Converts a field name into the corresponding numeric field index, based on a specified packet format.
Syntax
op_pk_name_to_index (format_name, field_name)
| Argument | Type | Description |
|---|---|---|
format_name |
const char * |
Name of the packet format-of-interest |
field_name |
const char * |
Name of the field-of-interest. |
Return Type
int
Numeric index of the specified field.
The constant OPC_FIELD_INDEX_INVALID will be returned if an error occurs.
Example
/* pull the next packet off the queue */
pkptr = op_subq_pk_remote (0, OPC_QPOS_HEAD);
/* determine the size of the information field */
info_size = op_pk_nfd_size (pkptr, "fd_info");
/* if the size of this field is too large, clamp it */
if (info_size > 1300)
{
/* convert the field name into a field index */
fd_index = op_pk_name_to_index ("AX.25", "fd_info");
/* set the field size to the maximum */
op_pk_fd_set_int32 (pkptr, fd_index, 1300, 16);
}
Details
This function is similar to op_pk_nfd_name_to_index(), but takes the name of a packet format instead of a packet pointer.
Purpose
Provides a way to get the numeric index of a field in a packet format, given the field name. This allows you to compute the index values without actually having a packet. By doing so, you can set up a group of index variables that can be used later in the code in conjunction with op_pk_fd_set(), op_pk_fd_get(), and their variants for more efficient access to fields than with the op_pk_nfd_ functions.
Errors
- Recoverable Error: No field named (
<field_name>) in packet format (<format_name>)
Reference
- Use the KP op_pk_nfd_name_to_index() to perform the same operation for a specified packet instead of a packet format
- Use the KP op_pk_fd_index_to_name() to perform the reverse operation of converting a numeric field index into a field name
- Use the KP op_pk_fd_set() to set the value of a field in a packet using a numeric index