op_pk_nfd_default()
Abstract
Obtains the default value of a field in the specified formatted packet; the field-of-interest is specified by name.
Syntax
op_pk_nfd_default (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 constant value OPC_DBL_UNDEF will be returned.] |
Return Type
double
Default value of the specified field.
[Only integer and double fields can be assigned meaningful defaults in packet formats. This KP returns a double for both integer and double default values; the returned value can be cast into an integer if required. OPC_DBL_UNDEF is returned if an error occurs.]
Example
/* obtain an arriving packet */
pkptr = op_pk_get (0);
/* determine the default value of the opcode field */
def_opcode = (int) op_pk_nfd_default (pkptr, "opcode");
/* restore the default value to the opcode field */
op_pk_nfd_set (pkptr, "opcode", def_opcode);
Details
The Packet Format Editor allows the default value of a field to be specified before the type of the field is specified, so any type of field may be assigned a default value. However, the default values are only used in the case of integer and double fields.
If this KP is applied to an unformatted packet or any recoverable error occurs, the constant OPC_DBL_UNDEF will be returned.
Purpose
Provides a mechanism to determine the default value for a field in a formatted packet. This is useful if a process needs to reset the field to the default value, but does not have a priori knowledge of the default value.
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>).
- Recoverable Error: No field named (<fd_name>) in packet (<pk_id>).
Reference
- Use the KP op_pk_nfd_get() to obtain the current value of a packet field
- 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