@@ -991,6 +991,44 @@ fn into_linger(duration: Option<Duration>) -> sys::linger {
991991/// * Linux: <https://man7.org/linux/man-pages/man7/ip.7.html>
992992/// * Windows: <https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options>
993993impl Socket {
994+ /// Get the value of the `IP_HDRINCL` option on this socket.
995+ ///
996+ /// For more information about this option, see [`set_header_included`].
997+ ///
998+ /// [`set_header_included`]: Socket::set_header_included
999+ #[ cfg( all( feature = "all" , not( target_os = "redox" ) ) ) ]
1000+ #[ cfg_attr( docsrs, doc( all( feature = "all" , not( target_os = "redox" ) ) ) ) ]
1001+ pub fn header_included ( & self ) -> io:: Result < bool > {
1002+ unsafe {
1003+ getsockopt :: < c_int > ( self . as_raw ( ) , sys:: IPPROTO_IP , sys:: IP_HDRINCL )
1004+ . map ( |included| included != 0 )
1005+ }
1006+ }
1007+
1008+ /// Set the value of the `IP_HDRINCL` option on this socket.
1009+ ///
1010+ /// If enabled, the user supplies an IP header in front of the user data.
1011+ /// Valid only for [`SOCK_RAW`] sockets; see [raw(7)] for more information.
1012+ /// When this flag is enabled, the values set by `IP_OPTIONS`, [`IP_TTL`],
1013+ /// and [`IP_TOS`] are ignored.
1014+ ///
1015+ /// [`SOCK_RAW`]: Type::RAW
1016+ /// [raw(7)]: https://man7.org/linux/man-pages/man7/raw.7.html
1017+ /// [`IP_TTL`]: Socket::set_ttl
1018+ /// [`IP_TOS`]: Socket::set_tos
1019+ #[ cfg( all( feature = "all" , not( target_os = "redox" ) ) ) ]
1020+ #[ cfg_attr( docsrs, doc( all( feature = "all" , not( target_os = "redox" ) ) ) ) ]
1021+ pub fn set_header_included ( & self , included : bool ) -> io:: Result < ( ) > {
1022+ unsafe {
1023+ setsockopt (
1024+ self . as_raw ( ) ,
1025+ sys:: IPPROTO_IP ,
1026+ sys:: IP_HDRINCL ,
1027+ included as c_int ,
1028+ )
1029+ }
1030+ }
1031+
9941032 /// Get the value of the `IP_TRANSPARENT` option on this socket.
9951033 ///
9961034 /// For more information about this option, see [`set_ip_transparent`].
@@ -1016,7 +1054,7 @@ impl Socket {
10161054 /// are routed through the TProxy box (i.e., the system
10171055 /// hosting the application that employs the IP_TRANSPARENT
10181056 /// socket option). Enabling this socket option requires
1019- /// superuser privileges (the CAP_NET_ADMIN capability).
1057+ /// superuser privileges (the ` CAP_NET_ADMIN` capability).
10201058 ///
10211059 /// TProxy redirection with the iptables TPROXY target also
10221060 /// requires that this option be set on the redirected socket.
0 commit comments