op_pk_fd_index_to_name()

Abstract

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

Syntax

op_pk_fd_index_to_name (pkptr, fd_index, 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(), op_pk_create_fmt(), op_pk_copy(), op_pk_get(), op_subq_pk_access(), and op_subq_pk_remove().]
fd_index int numeric index of the field-of-interest
[This value should be non-negative; however, no error will occur if it is not.]
fd_name char* name of the specified field (filled in by this KP)
[This argument should be a statically declared character array, or a character pointer which points to dynamically allocated memory; it must point to a string large enough to hold the name of the specified field.]

Return Type

void

No return value.

Example

/* pull the next packet off the queue */
pkptr = op_subq_pk_remove (0, OPC_QPOS_HEAD);

/* determine the number of fields the packet has */
num_fds = op_pk_fd_max_index (pkptr);

/* loop through each field, printing its field name */
for (j = 0; j < num_fds; j++)
	{
	/* obtain the field name */
	op_pk_fd_index_to_name (pkptr, j, fd_name);

	/* print the field name */
	printf ("Field (%d): Name (%s)\n", j, fd_name);
	}

Details

This KP is useful for determining the names of fields only in formatted packets. However, applying this KP to an unformatted packet will not cause an error. Instead, the field name string will be assigned the constructed value field_<field_no>. This type of value will also result if the specified field index is larger than the last defined field, or smaller than zero.

Purpose

Provides a mechanism for determining the name of a formatted packet field if it is not known a priori by a process. This can be useful for generic processes which must handle arriving packets of different format. A process can loop through the fields of a packet (the upper bound of the loop can be determined using the KP op_pk_fd_max_index()), obtain the name of each field via this KP, and compare the field names to one or more names it is searching for based on its processing goal.

Errors

  • Program Abort: Segmentation violation. (due to an invalid packet pointer, malformed packet, or malformed fd_name argument)
  • Program Abort: Packet pointer is NIL.
  • Program Abort: Packet pointer references destroyed packet.
  • Recoverable Error: Field index (<fd_index>) is out-of-range for packet (<pk_id>).

Reference

本站文档由 北京智网畅联科技有限公司 整理、翻译并提供 · 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