op_pk_fd_type()

Abstract

Obtains the type of a field in the specified packet; the field-of-interest is specified by a numeric index.

Syntax

op_pk_fd_type (pkptr, fd_index)
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. Instead, the value OPC_FIELD_TYPE_UNSPEC will be returned indicating the specified field is not defined in the packet.]

Return Type

int

Type of the specified field.

[This value is an integer code which represents the field type (see Table 55 “Field Type Symbolic Constants“ on page 14); the possible values of this code are also listed in the Details section on the next page.]

Example

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 out its contents */
for (j = 0; j < num_fds; j++)
	{
	if (op_pk_fd_is_set (pkptr, j) == OPC_FALSE)
		continue;
	switch (op_pk_fd_type (pkptr, j))
		{
		case OPC_FIELD_TYPE_INTEGER:
			op_pk_fd_get (pkptr, j, &val_i);
			printf ("Field (%d): Type (integer) Value (%d)\n", j, val_i);
			break;

		case OPC_FIELD_TYPE_DOUBLE:
			op_pk_fd_get (pkptr, j, &val_d);
			printf ("Field (%d): Type (double) Value (%g)\n", j, val_d);
			break;
		}
	}

Details

This KP returns an integer code that represents the type of the specified field; the value of the integer code can be compared to the following symbolic constants:

  • OPC_FIELD_TYPE_INTEGER
  • OPC_FIELD_TYPE_DOUBLE
  • OPC_FIELD_TYPE_STRUCT
  • OPC_FIELD_TYPE_INFO
  • OPC_FIELD_TYPE_PACKET
  • OPC_FIELD_TYPE_UNSPEC

The constant OPC_FIELD_TYPE_UNSPEC is returned if a recoverable error occurs.

Purpose

Provides a mechanism to determine the type of a packet field. Typically this is used when a packet is received by a process that is written generically, so that it can deal with diverse incoming packet formats. The process can determine the maximum field index in a packet using op_pk_fd_max_index(), and then loop through each of the fields, determine if they are set, query their type using this KP, and determine their value or size. This technique of processing packets can be implemented for both unformatted and formatted packets.

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 with index (<fd_index>) in packet (<pk_id>).

Reference

  • Use the KP op_pk_nfd_type() to determine the type of a field in a formatted packet, utilizing a name to specify the field-of-interest
  • 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
  • Use the KP op_pk_fd_max_index() to determine the maximum field index in a packet

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