op_pk_name_to_index()

摘要

基于指定的数据包格式,把字段名称转换为对应的数值字段索引。

语法

op_pk_name_to_index (format_name, field_name)
参数 类型 说明
format_name const char * 目标数据包格式的名称
field_name const char * 目标字段的名称。

返回类型

int

指定字段的数值索引。

如果发生错误,将返回常量 OPC_FIELD_INDEX_INVALID。

示例

/* 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_name_to_index ("AX.25", "fd_info");

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

详情

该函数与 op_pk_nfd_name_to_index() 类似,但接受的是数据包格式的名称而不是数据包指针。

用途

提供一种在给定字段名称的情况下获取数据包格式中某字段数值索引的方式。这使你可以在并不实际拥有数据包的情况下计算索引值。这样,你可以预先设置一组索引变量,供后续代码配合 op_pk_fd_set()、op_pk_fd_get() 及其变体使用,以比 op_pk_nfd_ 系列函数更高效地访问字段。

错误

  • 可恢复错误:数据包格式 (<format_name>) 中不存在名为 (<field_name>) 的字段

参考

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