File tree Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Expand file tree Collapse file tree 3 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -1388,6 +1388,52 @@ impl Socket {
1388
1388
getsockopt :: < c_int > ( self . as_raw ( ) , sys:: IPPROTO_IP , sys:: IP_TOS ) . map ( |tos| tos as u32 )
1389
1389
}
1390
1390
}
1391
+
1392
+ /// Set the value of the `IP_RECVTOS` option for this socket.
1393
+ ///
1394
+ /// If enabled, the IP_TOS ancillary message is passed with
1395
+ /// incoming packets. It contains a byte which specifies the
1396
+ /// Type of Service/Precedence field of the packet header.
1397
+ #[ cfg( not( any(
1398
+ target_os = "fuschia" ,
1399
+ target_os = "illumos" ,
1400
+ target_os = "netbsd" ,
1401
+ target_os = "redox" ,
1402
+ target_os = "solaris" ,
1403
+ target_os = "windows" ,
1404
+ ) ) ) ]
1405
+ pub fn set_recv_tos ( & self , recv_tos : bool ) -> io:: Result < ( ) > {
1406
+ let recv_tos = if recv_tos { 1 } else { 0 } ;
1407
+
1408
+ unsafe {
1409
+ setsockopt (
1410
+ self . as_raw ( ) ,
1411
+ sys:: IPPROTO_IP ,
1412
+ sys:: IP_RECVTOS ,
1413
+ recv_tos as c_int ,
1414
+ )
1415
+ }
1416
+ }
1417
+
1418
+ /// Get the value of the `IP_RECVTOS` option for this socket.
1419
+ ///
1420
+ /// For more information about this option, see [`set_recv_tos`].
1421
+ ///
1422
+ /// [`set_recv_tos`]: Socket::set_recv_tos
1423
+ #[ cfg( not( any(
1424
+ target_os = "fuschia" ,
1425
+ target_os = "illumos" ,
1426
+ target_os = "netbsd" ,
1427
+ target_os = "redox" ,
1428
+ target_os = "solaris" ,
1429
+ target_os = "windows" ,
1430
+ ) ) ) ]
1431
+ pub fn recv_tos ( & self ) -> io:: Result < bool > {
1432
+ unsafe {
1433
+ getsockopt :: < c_int > ( self . as_raw ( ) , sys:: IPPROTO_IP , sys:: IP_RECVTOS )
1434
+ . map ( |recv_tos| recv_tos > 0 )
1435
+ }
1436
+ }
1391
1437
}
1392
1438
1393
1439
/// Socket options for IPv6 sockets, get/set using `IPPROTO_IPV6`.
Original file line number Diff line number Diff line change @@ -77,6 +77,14 @@ pub(crate) use libc::{MSG_TRUNC, SO_OOBINLINE};
77
77
// Used in `Socket`.
78
78
#[ cfg( all( feature = "all" , not( target_os = "redox" ) ) ) ]
79
79
pub ( crate ) use libc:: IP_HDRINCL ;
80
+ #[ cfg( not( any(
81
+ target_os = "fuschia" ,
82
+ target_os = "illumos" ,
83
+ target_os = "netbsd" ,
84
+ target_os = "redox" ,
85
+ target_os = "solaris" ,
86
+ ) ) ) ]
87
+ pub ( crate ) use libc:: IP_RECVTOS ;
80
88
#[ cfg( not( any(
81
89
target_os = "fuschia" ,
82
90
target_os = "redox" ,
Original file line number Diff line number Diff line change @@ -1172,6 +1172,17 @@ test!(IPv4 ttl, set_ttl(40));
1172
1172
target_os = "illumos" ,
1173
1173
) ) ) ]
1174
1174
test ! ( IPv4 tos, set_tos( 96 ) ) ;
1175
+
1176
+ #[ cfg( not( any(
1177
+ target_os = "fuschia" ,
1178
+ target_os = "illumos" ,
1179
+ target_os = "netbsd" ,
1180
+ target_os = "redox" ,
1181
+ target_os = "solaris" ,
1182
+ target_os = "windows" ,
1183
+ ) ) ) ]
1184
+ test ! ( IPv4 recv_tos, set_recv_tos( true ) ) ;
1185
+
1175
1186
#[ cfg( not( windows) ) ] // TODO: returns `WSAENOPROTOOPT` (10042) on Windows.
1176
1187
test ! ( IPv4 broadcast, set_broadcast( true ) ) ;
1177
1188
You can’t perform that action at this time.
0 commit comments