TCPIP_IPV4_PacketOptionFieldSet Function
C
IPV4_OPTION_FIELD* TCPIP_IPV4_PacketOptionFieldSet(
IPV4_PACKET* pPkt,
uint16_t optionLen,
bool firstOption
);
Description
This function is a helper to allow setting a specific option into an IPv4 packet that supports options. It is meant for supporting user controlled and variable size options.
Preconditions
IPv4 properly initialized. pPkt properly created with TCPIP_IPV4_PacketAlloc().
Parameters
Parameters | Description |
---|---|
pPkt | A packet allocated with TCPIP_IPV4_PacketALloc(). |
optionLen | Size for the option to set, in bytes. This is the size of the whole IPV4_OPTION_FIELD, the option data included. |
firstOption | Specifies that this is the first option to be set to the packet. |
Returns
A valid IPV4_OPTION_FIELD pointer that the caller can use to set the IPv4 option fields.
0 - Invalid packet or the option field cannot hold the required option size.
Remarks
This function should be called for unsupported options or for options that have variable data. It doesn't have to be used for standard supported options (TCPIP_IPV4_OPTION_ROUTER_ALERT, for ex.)
The packet should have been allocated with enough option space using TCPIP_IPV4_PacketAlloc().
Sequential calls can be made using firstOption true for the first call and false for the subsequent calls.
When setting the option data, optionLen MUST NOT be exceeded.
If the option doesn't take a multiple of 4 bytes, it should be padded with the NOP option (0x01).