op_pk_fd_access_ptr()
Abstract
Accesses a structure stored in the specified packet; the field-of-interest is specified by a numeric index.
Syntax
op_pk_fd_access_ptr (pkptr, field_index, struct_pptr)
| 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().] |
field_index |
int |
numeric index of the field-of-interest [This value must be non-negative.] |
struct_pptr |
void** |
pointer to a variable to be filled in with the structure being accessed. The variable itself must be a pointer to some data structure. |
Return Type
Compcode
OPC_COMPCODE_FAILURE if the field is not obtained; OPC_COMPCODE_SUCCESS otherwise.
Example
/* Access the datagram field information structure */
/* to assign source address information. */
op_pk_fd_access_ptr (pk_copy_ptr, pk_fd_index, (void**)&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
If successful, *struct_pptr is set to the address of the structure stored in the packet. The structure is not removed from the packet (as is the case with op_pk_fd_get_ptr()). Any changes made using *struct_pptr will be made to the structure in the packet.
Note: This KP should be used only to access structure packet fields. Accessing other kinds of fields will result in an error. Use one of the typed op_pk_fd_get… KPs for numerical fields.
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.
Purpose
Provides a mechanism to access a structure stored inside a packet using the field index instead of the field name.
Errors
- Program Abort: Segmentation violation. (due to invalid
pkptrorstruct_pptrarguments) - Program Abort: Packet pointer is NIL.
- Program Abort: Packet pointer references destroyed packet.
- Program Abort: Packet pointer references unowned packet (
<pk_id>). - Recoverable Error: Field (
<field_index>) of packet (<pk_id>) is of type (<field_type>). - Recoverable Error: Field index (
<field_index>) is out-of-range for packet (<pk_id>). - Recoverable Error: No field with index (
<field_index>) in packet (<pk_id>). - Recoverable Error: Contents of packet (
<pk_id>) is a value vector. Packet doesn’t allow field operations.
Reference
- Use the KP op_pk_fd_get_ptr() to obtain the value of a structure field from a packet, using a numeric index to specify the field
- Use the KP op_pk_fd_access_read_only_ptr() for efficient read-only access to the value of a structure field
- Use one of the variants the KP op_pk_nfd_get() to obtain the value of a field from a formatted packet, using a name to specify the field to be accessed
- Use one of the variants of the KP op_pk_fd_set() to assign a value to a packet field
- Use the KP op_pk_fd_type() to determine the type of a packet field
- Use the KP op_pk_fd_size() to determine the size of a packet field
- Use the KP op_pk_fd_is_set() to determine if a packet field is set