@@ -1615,6 +1615,53 @@ impl Socket {
1615
1615
. map ( |recv_tos| recv_tos > 0 )
1616
1616
}
1617
1617
}
1618
+
1619
+ /// Set value for `IP_DONTFRAG` option of this socket
1620
+ #[ cfg( any(
1621
+ target_os = "macos" ,
1622
+ target_os = "ios" ,
1623
+ target_os = "linux" ,
1624
+ target_os = "windows" ,
1625
+ ) ) ]
1626
+ pub fn dont_frag ( & self ) -> io:: Result < bool > {
1627
+ unsafe {
1628
+ #[ cfg( any( target_os = "macos" , target_os = "ios" , ) ) ]
1629
+ return getsockopt :: < c_int > ( self . as_raw ( ) , sys:: IPPROTO_IP , libc:: IP_DONTFRAG )
1630
+ . map ( |dont_frag| dont_frag > 0 ) ;
1631
+ #[ cfg( any( target_os = "linux" , target_os = "windows" , ) ) ]
1632
+ return getsockopt :: < c_int > ( self . as_raw ( ) , sys:: IPPROTO_IP , sys:: IP_MTU_DISCOVER )
1633
+ . map ( |dont_frag| dont_frag == 0 ) ;
1634
+ }
1635
+ }
1636
+ /// Set value for `IP_DONTFRAG` option on this socket
1637
+ #[ cfg( any(
1638
+ target_os = "macos" ,
1639
+ target_os = "ios" ,
1640
+ target_os = "linux" ,
1641
+ target_os = "windows" ,
1642
+ ) ) ]
1643
+ pub fn set_dont_frag ( & self , dont_frag : bool ) -> io:: Result < ( ) > {
1644
+ unsafe {
1645
+ #[ cfg( any( target_os = "macos" , target_os = "ios" , ) ) ]
1646
+ return setsockopt (
1647
+ self . as_raw ( ) ,
1648
+ sys:: IPPROTO_IP ,
1649
+ libc:: IP_DONTFRAG ,
1650
+ dont_frag as c_int ,
1651
+ ) ;
1652
+ #[ cfg( any( target_os = "linux" , target_os = "windows" , ) ) ]
1653
+ return setsockopt (
1654
+ self . as_raw ( ) ,
1655
+ sys:: IPPROTO_IP ,
1656
+ sys:: IP_MTU_DISCOVER ,
1657
+ if dont_frag {
1658
+ sys:: IP_PMTUDISC_DONT
1659
+ } else {
1660
+ sys:: IP_PMTUDISC_DO
1661
+ } ,
1662
+ ) ;
1663
+ } ;
1664
+ }
1618
1665
}
1619
1666
1620
1667
/// Socket options for IPv6 sockets, get/set using `IPPROTO_IPV6`.
@@ -2015,6 +2062,54 @@ impl Socket {
2015
2062
)
2016
2063
}
2017
2064
}
2065
+
2066
+ /// Get value for `IP_DONTFRAG` option on this socket.
2067
+ #[ cfg( any(
2068
+ target_os = "linux" ,
2069
+ target_os = "windows" ,
2070
+ target_os = "macos" ,
2071
+ target_os = "ios" ,
2072
+ ) ) ]
2073
+ pub fn dont_frag_v6 ( & self ) -> io:: Result < bool > {
2074
+ unsafe {
2075
+ #[ cfg( any( target_os = "macos" , target_os = "ios" , ) ) ]
2076
+ return getsockopt :: < c_int > ( self . as_raw ( ) , sys:: IPPROTO_IPV6 , libc:: IPV6_DONTFRAG )
2077
+ . map ( |dont_frag| dont_frag > 0 ) ;
2078
+ #[ cfg( any( target_os = "linux" , target_os = "windows" , ) ) ]
2079
+ return getsockopt :: < c_int > ( self . as_raw ( ) , sys:: IPPROTO_IPV6 , sys:: IPV6_MTU_DISCOVER )
2080
+ . map ( |dont_frag| dont_frag == sys:: IP_PMTUDISC_DONT ) ;
2081
+ }
2082
+ }
2083
+
2084
+ /// Set value for `IP_DONTFRAG` option on this socket
2085
+ #[ cfg( any(
2086
+ target_os = "macos" ,
2087
+ target_os = "ios" ,
2088
+ target_os = "linux" ,
2089
+ target_os = "windows" ,
2090
+ ) ) ]
2091
+ pub fn set_dont_frag_v6 ( & self , dont_frag : bool ) -> io:: Result < ( ) > {
2092
+ unsafe {
2093
+ #[ cfg( any( target_os = "macos" , target_os = "ios" , ) ) ]
2094
+ return setsockopt (
2095
+ self . as_raw ( ) ,
2096
+ sys:: IPPROTO_IPV6 ,
2097
+ libc:: IPV6_DONTFRAG ,
2098
+ dont_frag as c_int ,
2099
+ ) ;
2100
+ #[ cfg( any( target_os = "linux" , target_os = "windows" , ) ) ]
2101
+ setsockopt (
2102
+ self . as_raw ( ) ,
2103
+ sys:: IPPROTO_IPV6 ,
2104
+ sys:: IPV6_MTU_DISCOVER ,
2105
+ if dont_frag {
2106
+ sys:: IP_PMTUDISC_DONT
2107
+ } else {
2108
+ sys:: IP_PMTUDISC_DO
2109
+ } ,
2110
+ )
2111
+ }
2112
+ }
2018
2113
}
2019
2114
2020
2115
/// Socket options for TCP sockets, get/set using `IPPROTO_TCP`.
0 commit comments