tst_recv_hop_limit_udp - Receiving the Hop Limit when the IPV6_RECVHOPLIMIT socket option is enabled
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_udp [-tooloption ...] -tooloption : v6api tool option
1. Create an IPv6/UDP socket 2. Set the value of hop limit to 64 3. Enabled the IPV6_RECVHOPLIMIT option to receive hop limit 4. Bind the socket to address 5. Send one message to socket itself 6. Receive one message used recvmsg() 7. Check A: The hop limit option is returned 8. Check B: The received value and length of 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.