op_pk_nfd_access()
Abstract
Obtains the value of an integer, double, structure, or information field in the specified packet, leaving the field unchanged; the field-of-interest is specified by name.
Syntax
op_pk_nfd_access (pkptr, fd_name, value_ptr)
| 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 must be a defined field within the packet’s format, or an error will occur.] |
value_ptr |
void* |
pointer to a variable to be filled in with the specified field’s value [This argument can accept a pointer to any data type except packet. The data type of the argument pointer must match the data type of the specified field, or an error will occur.] |
Return Type
Compcode
Completion code indicating if the specified field’s value was successfully obtained. The constant OPC_COMPCODE_FAILURE will be returned if an error occurs, such as a missing field.
Example
/* Access the datagram field information structure */
/* to assign source address information. */
op_pk_nfd_access (pk_copy_ptr, “fields”, &pkt_fields_ptr);
/* Set the source address before forwarding the packet. */
pkt_fields_ptr->src_addr = iface_ptr->addr_range_ptr->address;
pkt_fields_ptr->src_internal_addr = ip_rtab_addr_convert (iface_ptr->addr_range_ptr->address);
Details
This KP supports value access for packet fields of any data type except packet. Fields of type structure have their values copied into the passed variable, but are otherwise unaffected (that is, structure fields remain set and accessible, and continue to contribute the same amount of bits to the packet’s total size).
WARNING: Because this KP does not remove structure fields when accessing their values, multiple processes might be able to work on the same object, possibly affecting each other unintentionally.
For fields of type integer, double, and information, this KP acts like op_pk_nfd_get().
Purpose
Provides a mechanism to obtain the value of a packet field. This KP implements functionality identical to op_pk_nfd_get(), except that
- fields of type structure are not stripped from the packet
- fields of type packet are not supported
Errors
- Program Abort: Segmentation violation. (due to an invalid packet pointer or malformed packet)
- Program Abort: Packet pointer is NIL.
- Program Abort: Packet pointer references destroyed packet.
- Program Abort: Packet pointer references unowned packet (
<pk_id>).
Reference
- Use one of the formats of the KP
op_pk_nfd_set()to assign a value to a packet field - Use the KP
op_pk_nfd_access_read_only_ptr()for efficient read-only access to a structure field of a packet - Use the KP
op_pk_fd_get()to obtain the value of a field from an unformatted (or formatted) packet, using a numeric index to specify the field to be accessed - Use the KP
op_pk_nfd_type()to determine the type of a packet field - 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