它的用法是: Obtains the value of a field in the specified packet; the field-of-interest is specified by a numeric index.
函数原型:op_pk_fd_get (pkptr, field_index, value_ptr)
其中,pkptr是一个指向包的指针,数据类型是Packet*
field_index是包域的数字索引,它必须是非负整数
value_ptr是将被赋值的域指针。
举一个例子:
{
/* variable declarations */
int i; double d;
Packet *pkptr, *enc_pkptr;
struct Custom_DS *ds_ptr;
/* obtain an arriving packet */
pkptr = op_pk_get (0); // 得到包的指针
/* obtain the simple field types */
op_pk_fd_get (pkptr, 0, &i);// 域0赋值给i,域1赋值给d
op_pk_fd_get (pkptr, 1, &d);
printf ("packet contents: integer (%d), double (%g)/n", i, d);
/* decapsulate a higher-level packet from the arriving packet */
op_pk_fd_get (pkptr, 2, &enc_pkptr);
op_pk_print (enc_pkptr);
/* extract a data structure from a packet field */
op_pk_fd_get (pkptr, 3, &ds_ptr); op_pk_destroy (pkptr);// 销毁包
}
也许你会问,这些域是从哪里来的呢?
use one of the variants of the KP op_pk_fd_set() to assign a value to a packetfield