tst_recv_hop_limit_tcp - Receiving the Hop Limit (TCP socket)
To check whether the hop limit be set should be used when send data on tcp socket, and the received hop limit can be returned correctly when receive data.
./tst_recv_hop_limit_tcp [-tooloption ...] -tooloption : v6api tool option
1. Create tcp socket for tcp server 2. Ceate tcp socket for tcp client 3. Set hoplimit of tcp server to 255 4. Enable tcp client to receive hop limit 5. Bind tcp server socket to address 6. Listen on tcp server socket 7. Connect to tcp server 8. Accept a connection on tcp socket 9. Send message from tcp server to tcp clien 10.Recv message from tcp server on tcp client 11.Get the value of IPV6_PKTOPTIONS option of tcp client 12.Check A: The Hop Limit option is returned 13.Check B: The received hop limit is correct 14.Check C: The length of received hop limit is correct
None
RFC 3542
6.3. Specifying/Receiving the Hop Limit
The outgoing hop limit is normally specified with either the IPV6_UNICAST_HOPS socket option or the IPV6_MULTICAST_HOPS socket option, both of which are described in [RFC-3493]. Specifying the hop limit as ancillary data lets the application override either the kernel's default or a previously specified value, for either a unicast destination or a multicast destination, for a single output operation. Returning the received hop limit is useful for IPv6 applications that need to verify that the received hop limit is 255 (e.g., that the packet has not been forwarded).
The received hop limit is returned as ancillary data by recvmsg() only if the application has enabled the IPV6_RECVHOPLIMIT socket option:
int on = 1; setsockopt(fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &on, sizeof(on));
In the cmsghdr structure containing this ancillary data, the cmsg_level member will be IPPROTO_IPV6, the cmsg_type member will be IPV6_HOPLIMIT, and the first byte of cmsg_data[] will be the first byte of the integer hop limit.
Nothing special need be done to specify the outgoing hop limit: just specify the control information as ancillary data for sendmsg(). As specified in [RFC-3493], the interpretation of the integer hop limit value is
x < -1: return an error of EINVAL x == -1: use kernel default 0 <= x <= 255: use x x >= 256: return an error of EINVAL
This API defines IPV6_HOPLIMIT as an ancillary-only option, that is, the option name cannot be used as a socket option. This is because [RFC-3493] has more fine-grained socket options; IPV6_UNICAST_HOPS and IPV6_MULTICAST_HOPS.