op_pk_nfd_name_to_index()

Abstract

Converts a field name into the corresponding numeric field index, based on the format of a specified packet.

Syntax

op_pk_nfd_name_to_index (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; if it is not, this KP will return a large negative number, indicating that the specified field is not defined in the packet]

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_nfd_name_to_index (pkptr, "fd_info");

	/* set the field size to the maximum */
	op_pk_fd_set (pkptr, fd_index, OPC_FIELD_TYPE_INTEGER, 1300, 16);
	}

Details

Packet fields are stored in a list within the packet. They are always numerically indexed, and in formatted packets they have associated field names. Conversion between field names and numeric indices can be performed by this KP and the inverse KP op_pk_fd_index_to_name().

Purpose

Provides a mechanism for determining the numeric index of a field in a formatted packet. A typical use of this KP is to modify the predefined size of a formatted packet field (as specified in the packet format); the only way to accomplish this is via the use of op_pk_fd_set(), which depends on this KP (as shown in the example on the previous page).

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.
  • Recoverable Error: No field named (<fd_name>) in packet (<pk_id>).

Reference

  • Use the KP op_pk_name_to_index() to perform the same operation for a specified packet format instead of a packet
  • 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

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · Documentation compiled and provided by Beijing ZNetLink Technology Co., Ltd.

交流群 · QQ Group:OPNET/智网妙算网络仿真交流群(群号 486383494)

原文档 © 2017 Riverbed Technology · 本站为公益翻译,由 AI 辅助完成,请仔细甄别

Original documentation © 2017 Riverbed Technology. Community translation, AI-assisted. Contact: jiazequn@znetlink.com