7
7
// except according to those terms.
8
8
9
9
use std:: cmp:: min;
10
- #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
10
+ #[ cfg( all( feature = "all" , any ( target_os = "fuchsia" , target_os = " linux") ) ) ]
11
11
use std:: ffi:: { CStr , CString } ;
12
12
#[ cfg( not( target_os = "redox" ) ) ]
13
13
use std:: io:: IoSlice ;
@@ -90,6 +90,7 @@ pub(crate) use libc::{
90
90
feature = "all" ,
91
91
any(
92
92
target_os = "freebsd" ,
93
+ target_os = "fuchsia" ,
93
94
target_os = "linux" ,
94
95
target_os = "netbsd" ,
95
96
target_vendor = "apple" ,
@@ -142,6 +143,7 @@ type IovLen = usize;
142
143
all( target_os = "linux" , target_env = "musl" ) ,
143
144
target_os = "dragonfly" ,
144
145
target_os = "freebsd" ,
146
+ target_os = "fuchsia" ,
145
147
target_os = "illumos" ,
146
148
target_os = "netbsd" ,
147
149
target_os = "openbsd" ,
@@ -159,8 +161,8 @@ impl Domain {
159
161
///
160
162
/// # Notes
161
163
///
162
- /// This function is only available on Linux.
163
- #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
164
+ /// This function is only available on Fuchsia and Linux.
165
+ #[ cfg( all( feature = "all" , any ( target_os = "fuchsia" , target_os = " linux") ) ) ]
164
166
pub const PACKET : Domain = Domain ( libc:: AF_PACKET ) ;
165
167
}
166
168
@@ -169,7 +171,7 @@ impl_debug!(
169
171
libc:: AF_INET ,
170
172
libc:: AF_INET6 ,
171
173
libc:: AF_UNIX ,
172
- #[ cfg( target_os = "linux" ) ]
174
+ #[ cfg( any ( target_os = "fuchsia" , target_os = " linux") ) ]
173
175
libc:: AF_PACKET ,
174
176
libc:: AF_UNSPEC , // = 0.
175
177
) ;
@@ -180,14 +182,15 @@ impl Type {
180
182
///
181
183
/// # Notes
182
184
///
183
- /// This function is only available on Android, DragonFlyBSD, FreeBSD ,
184
- /// Linux, NetBSD and OpenBSD.
185
+ /// This function is only available on Android, DragonFlyBSD, Fuchsia ,
186
+ /// FreeBSD, Linux, NetBSD and OpenBSD.
185
187
#[ cfg( all(
186
188
feature = "all" ,
187
189
any(
188
190
target_os = "android" ,
189
191
target_os = "dragonfly" ,
190
192
target_os = "freebsd" ,
193
+ target_os = "fuchsia" ,
191
194
target_os = "illumos" ,
192
195
target_os = "linux" ,
193
196
target_os = "netbsd" ,
@@ -202,14 +205,15 @@ impl Type {
202
205
///
203
206
/// # Notes
204
207
///
205
- /// This function is only available on Android, DragonFlyBSD, FreeBSD ,
206
- /// Linux, NetBSD and OpenBSD.
208
+ /// This function is only available on Android, DragonFlyBSD, Fuchsia ,
209
+ /// FreeBSD, Linux, NetBSD and OpenBSD.
207
210
#[ cfg( all(
208
211
feature = "all" ,
209
212
any(
210
213
target_os = "android" ,
211
214
target_os = "dragonfly" ,
212
215
target_os = "freebsd" ,
216
+ target_os = "fuchsia" ,
213
217
target_os = "illumos" ,
214
218
target_os = "linux" ,
215
219
target_os = "netbsd" ,
@@ -224,6 +228,7 @@ impl Type {
224
228
target_os = "android" ,
225
229
target_os = "dragonfly" ,
226
230
target_os = "freebsd" ,
231
+ target_os = "fuchsia" ,
227
232
target_os = "illumos" ,
228
233
target_os = "linux" ,
229
234
target_os = "netbsd" ,
@@ -248,6 +253,7 @@ impl_debug!(
248
253
target_os = "android",
249
254
target_os = "dragonfly",
250
255
target_os = "freebsd",
256
+ target_os = "fuchsia",
251
257
target_os = "linux",
252
258
target_os = "netbsd",
253
259
target_os = "openbsd"
@@ -257,6 +263,7 @@ impl_debug!(
257
263
target_os = "android",
258
264
target_os = "dragonfly",
259
265
target_os = "freebsd",
266
+ target_os = "fuchsia",
260
267
target_os = "linux",
261
268
target_os = "netbsd",
262
269
target_os = "openbsd"
@@ -519,15 +526,12 @@ fn recvmsg(
519
526
} else {
520
527
size_of :: < libc:: sockaddr_storage > ( ) as libc:: socklen_t
521
528
} ;
522
- let mut msg = libc:: msghdr {
523
- msg_name : msg_name. cast ( ) ,
524
- msg_namelen,
525
- msg_iov : bufs. as_mut_ptr ( ) . cast ( ) ,
526
- msg_iovlen : min ( bufs. len ( ) , IovLen :: MAX as usize ) as IovLen ,
527
- msg_control : ptr:: null_mut ( ) ,
528
- msg_controllen : 0 ,
529
- msg_flags : 0 ,
530
- } ;
529
+ // libc::msghdr contains unexported padding fields on Fuchsia.
530
+ let mut msg: libc:: msghdr = unsafe { mem:: zeroed ( ) } ;
531
+ msg. msg_name = msg_name. cast ( ) ;
532
+ msg. msg_namelen = msg_namelen;
533
+ msg. msg_iov = bufs. as_mut_ptr ( ) . cast ( ) ;
534
+ msg. msg_iovlen = min ( bufs. len ( ) , IovLen :: MAX as usize ) as IovLen ;
531
535
syscall ! ( recvmsg( fd, & mut msg, flags) )
532
536
. map ( |n| ( n as usize , msg. msg_namelen , RecvFlags ( msg. msg_flags ) ) )
533
537
}
@@ -578,19 +582,16 @@ fn sendmsg(
578
582
bufs : & [ IoSlice < ' _ > ] ,
579
583
flags : c_int ,
580
584
) -> io:: Result < usize > {
581
- let mut msg = libc:: msghdr {
582
- // Safety: we're creating a `*mut` pointer from a reference, which is UB
583
- // once actually used. However the OS should not write to it in the
584
- // `sendmsg` system call.
585
- msg_name : ( msg_name as * mut sockaddr_storage ) . cast ( ) ,
586
- msg_namelen,
587
- // Safety: Same as above about `*const` -> `*mut`.
588
- msg_iov : bufs. as_ptr ( ) as * mut _ ,
589
- msg_iovlen : min ( bufs. len ( ) , IovLen :: MAX as usize ) as IovLen ,
590
- msg_control : ptr:: null_mut ( ) ,
591
- msg_controllen : 0 ,
592
- msg_flags : 0 ,
593
- } ;
585
+ // libc::msghdr contains unexported padding fields on Fuchsia.
586
+ let mut msg: libc:: msghdr = unsafe { mem:: zeroed ( ) } ;
587
+ // Safety: we're creating a `*mut` pointer from a reference, which is UB
588
+ // once actually used. However the OS should not write to it in the
589
+ // `sendmsg` system call.
590
+ msg. msg_name = ( msg_name as * mut sockaddr_storage ) . cast ( ) ;
591
+ msg. msg_namelen = msg_namelen;
592
+ // Safety: Same as above about `*const` -> `*mut`.
593
+ msg. msg_iov = bufs. as_ptr ( ) as * mut _ ;
594
+ msg. msg_iovlen = min ( bufs. len ( ) , IovLen :: MAX as usize ) as IovLen ;
594
595
syscall ! ( sendmsg( fd, & mut msg, flags) ) . map ( |n| n as usize )
595
596
}
596
597
@@ -651,6 +652,7 @@ pub(crate) fn set_tcp_keepalive(fd: Socket, keepalive: &TcpKeepalive) -> io::Res
651
652
target_os = "android" ,
652
653
target_os = "dragonfly" ,
653
654
target_os = "freebsd" ,
655
+ target_os = "fuchsia" ,
654
656
target_os = "illumos" ,
655
657
target_os = "linux" ,
656
658
target_os = "netbsd" ,
@@ -778,6 +780,7 @@ impl crate::Socket {
778
780
target_os = "android" ,
779
781
target_os = "dragonfly" ,
780
782
target_os = "freebsd" ,
783
+ target_os = "fuchsia" ,
781
784
target_os = "illumos" ,
782
785
target_os = "linux" ,
783
786
target_os = "netbsd" ,
@@ -792,6 +795,7 @@ impl crate::Socket {
792
795
target_os = "android" ,
793
796
target_os = "dragonfly" ,
794
797
target_os = "freebsd" ,
798
+ target_os = "fuchsia" ,
795
799
target_os = "illumos" ,
796
800
target_os = "linux" ,
797
801
target_os = "netbsd" ,
@@ -881,9 +885,9 @@ impl crate::Socket {
881
885
/// This value gets the socket mark field for each packet sent through
882
886
/// this socket.
883
887
///
884
- /// This function is only available on Linux and requires the
885
- /// `CAP_NET_ADMIN` capability.
886
- #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
888
+ /// This function is only available on Fuchsia and Linux. On Linux it
889
+ /// requires the `CAP_NET_ADMIN` capability.
890
+ #[ cfg( all( feature = "all" , any ( target_os = "fuchsia" , target_os = " linux") ) ) ]
887
891
pub fn mark ( & self ) -> io:: Result < u32 > {
888
892
unsafe {
889
893
getsockopt :: < c_int > ( self . inner , libc:: SOL_SOCKET , libc:: SO_MARK ) . map ( |mark| mark as u32 )
@@ -896,9 +900,9 @@ impl crate::Socket {
896
900
/// this socket. Changing the mark can be used for mark-based routing
897
901
/// without netfilter or for packet filtering.
898
902
///
899
- /// This function is only available on Linux and requires the
900
- /// `CAP_NET_ADMIN` capability.
901
- #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
903
+ /// This function is only available on Fuchsia and Linux. On Linux it
904
+ /// requires the `CAP_NET_ADMIN` capability.
905
+ #[ cfg( all( feature = "all" , any ( target_os = "fuchsia" , target_os = " linux") ) ) ]
902
906
pub fn set_mark ( & self , mark : u32 ) -> io:: Result < ( ) > {
903
907
unsafe { setsockopt :: < c_int > ( self . inner , libc:: SOL_SOCKET , libc:: SO_MARK , mark as c_int ) }
904
908
}
@@ -907,8 +911,8 @@ impl crate::Socket {
907
911
///
908
912
/// This value gets the socket binded device's interface name.
909
913
///
910
- /// This function is only available on Linux.
911
- #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
914
+ /// This function is only available on Fuchsia and Linux.
915
+ #[ cfg( all( feature = "all" , any ( target_os = "fuchsia" , target_os = " linux") ) ) ]
912
916
pub fn device ( & self ) -> io:: Result < Option < CString > > {
913
917
// TODO: replace with `MaybeUninit::uninit_array` once stable.
914
918
let mut buf: [ MaybeUninit < u8 > ; libc:: IFNAMSIZ ] =
@@ -952,8 +956,8 @@ impl crate::Socket {
952
956
///
953
957
/// If `interface` is `None` or an empty string it removes the binding.
954
958
///
955
- /// This function is only available on Linux.
956
- #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
959
+ /// This function is only available on Fuchsia and Linux.
960
+ #[ cfg( all( feature = "all" , any ( target_os = "fuchsia" , target_os = " linux") ) ) ]
957
961
pub fn bind_device ( & self , interface : Option < & CStr > ) -> io:: Result < ( ) > {
958
962
let ( value, len) = if let Some ( interface) = interface {
959
963
( interface. as_ptr ( ) , interface. to_bytes_with_nul ( ) . len ( ) )
@@ -1014,10 +1018,10 @@ impl crate::Socket {
1014
1018
///
1015
1019
/// For more information about this option, see [`set_freebind`].
1016
1020
///
1017
- /// This function is only available on Linux.
1021
+ /// This function is only available on Fuchsia and Linux.
1018
1022
///
1019
1023
/// [`set_freebind`]: Socket::set_freebind
1020
- #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
1024
+ #[ cfg( all( feature = "all" , any ( target_os = "fuchsia" , target_os = " linux") ) ) ]
1021
1025
pub fn freebind ( & self ) -> io:: Result < bool > {
1022
1026
unsafe {
1023
1027
getsockopt :: < c_int > ( self . inner , libc:: SOL_SOCKET , libc:: IP_FREEBIND )
@@ -1033,8 +1037,8 @@ impl crate::Socket {
1033
1037
/// dynamic IP address to be up at the time that the application is trying
1034
1038
/// to bind to it.
1035
1039
///
1036
- /// This function is only available on Linux.
1037
- #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
1040
+ /// This function is only available on Fuchsia and Linux.
1041
+ #[ cfg( all( feature = "all" , any ( target_os = "fuchsia" , target_os = " linux") ) ) ]
1038
1042
pub fn set_freebind ( & self , reuse : bool ) -> io:: Result < ( ) > {
1039
1043
unsafe {
1040
1044
setsockopt (
0 commit comments