File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
38
38
([ #1857 ] ( https://github.com/nix-rust/nix/pull/1857 ) )
39
39
- Added ` SockProtocol::Raw ` for raw sockets
40
40
([ #1848 ] ( https://github.com/nix-rust/nix/pull/1848 ) )
41
+ - added ` IP_MTU ` (` IpMtu ` ) ` IPPROTO_IP ` sockopt on Linux and Android.
42
+ ([ #1865 ] ( https://github.com/nix-rust/nix/pull/1865 ) )
41
43
42
44
### Changed
43
45
Original file line number Diff line number Diff line change @@ -925,6 +925,15 @@ sockopt_impl!(
925
925
libc:: IPV6_RECVERR ,
926
926
bool
927
927
) ;
928
+ #[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
929
+ sockopt_impl ! (
930
+ /// Fetch the current system-estimated Path MTU.
931
+ IpMtu ,
932
+ GetOnly ,
933
+ libc:: IPPROTO_IP ,
934
+ libc:: IP_MTU ,
935
+ libc:: c_int
936
+ ) ;
928
937
#[ cfg( any( target_os = "android" , target_os = "freebsd" , target_os = "linux" ) ) ]
929
938
sockopt_impl ! (
930
939
/// Set or retrieve the current time-to-live field that is used in every
Original file line number Diff line number Diff line change @@ -236,6 +236,33 @@ fn test_so_tcp_keepalive() {
236
236
}
237
237
}
238
238
239
+ #[ test]
240
+ #[ cfg( any( target_os = "android" , target_os = "linux" ) ) ]
241
+ #[ cfg_attr( qemu, ignore) ]
242
+ fn test_get_mtu ( ) {
243
+ use nix:: sys:: socket:: { bind, connect, SockaddrIn } ;
244
+ use std:: net:: SocketAddrV4 ;
245
+ use std:: str:: FromStr ;
246
+
247
+ let std_sa = SocketAddrV4 :: from_str ( "127.0.0.1:4001" ) . unwrap ( ) ;
248
+ let std_sb = SocketAddrV4 :: from_str ( "127.0.0.1:4002" ) . unwrap ( ) ;
249
+
250
+ let usock = socket (
251
+ AddressFamily :: Inet ,
252
+ SockType :: Datagram ,
253
+ SockFlag :: empty ( ) ,
254
+ SockProtocol :: Udp ,
255
+ )
256
+ . unwrap ( ) ;
257
+
258
+ // Bind and initiate connection
259
+ bind ( usock, & SockaddrIn :: from ( std_sa) ) . unwrap ( ) ;
260
+ connect ( usock, & SockaddrIn :: from ( std_sb) ) . unwrap ( ) ;
261
+
262
+ // Loopback connections have 2^16 - the maximum - MTU
263
+ assert_eq ! ( getsockopt( usock, sockopt:: IpMtu ) , Ok ( u16 :: MAX as i32 ) )
264
+ }
265
+
239
266
#[ test]
240
267
#[ cfg( any( target_os = "android" , target_os = "freebsd" , target_os = "linux" ) ) ]
241
268
fn test_ttl_opts ( ) {
You can’t perform that action at this time.
0 commit comments