@@ -1995,7 +1995,63 @@ pub const PRIO_PROCESS: ::c_int = 0;
1995
1995
pub const PRIO_PGRP : :: c_int = 1 ;
1996
1996
pub const PRIO_USER : :: c_int = 2 ;
1997
1997
1998
+ // As per sys/socket.h, header alignment must be 8 bytes on SPARC
1999
+ // and 4 bytes everywhere else:
2000
+ #[ cfg( target_arch = "sparc64" ) ]
2001
+ const _CMSG_HDR_ALIGNMENT: usize = 8 ;
2002
+ #[ cfg( any( target_arch = "x86" , target_arch = "x86_64" ) ) ]
2003
+ const _CMSG_HDR_ALIGNMENT: usize = 4 ;
2004
+
2005
+ const _CMSG_DATA_ALIGNMENT: usize = :: mem:: size_of :: < :: c_int > ( ) ;
2006
+
2007
+ fn _CMSG_HDR_ALIGN ( p : usize ) -> usize {
2008
+ ( p + _CMSG_HDR_ALIGNMENT - 1 ) & !( _CMSG_HDR_ALIGNMENT - 1 )
2009
+ }
2010
+
2011
+ fn _CMSG_DATA_ALIGN ( p : usize ) -> usize {
2012
+ ( p + _CMSG_DATA_ALIGNMENT - 1 ) & !( _CMSG_DATA_ALIGNMENT - 1 )
2013
+ }
2014
+
1998
2015
f ! {
2016
+ pub fn CMSG_DATA ( cmsg: * const :: cmsghdr) -> * mut :: c_uchar {
2017
+ _CMSG_DATA_ALIGN( cmsg. offset( 1 ) as usize ) as * mut :: c_uchar
2018
+ }
2019
+
2020
+ pub fn CMSG_LEN ( length: :: c_uint) -> :: c_uint {
2021
+ _CMSG_DATA_ALIGN( :: mem:: size_of:: <:: cmsghdr>( ) ) as :: c_uint + length
2022
+ }
2023
+
2024
+ pub fn CMSG_FIRSTHDR ( mhdr: * const :: msghdr) -> * mut :: cmsghdr {
2025
+ if ( ( * mhdr) . msg_controllen as usize ) < :: mem:: size_of:: <:: cmsghdr>( ) {
2026
+ 0 as * mut :: cmsghdr
2027
+ } else {
2028
+ ( * mhdr) . msg_control as * mut :: cmsghdr
2029
+ }
2030
+ }
2031
+
2032
+ pub fn CMSG_NXTHDR ( mhdr: * const :: msghdr, cmsg: * const :: cmsghdr)
2033
+ -> * mut :: cmsghdr
2034
+ {
2035
+ if cmsg. is_null( ) {
2036
+ return :: CMSG_FIRSTHDR ( mhdr) ;
2037
+ } ;
2038
+ let next = _CMSG_HDR_ALIGN( cmsg as usize + ( * cmsg) . cmsg_len as usize
2039
+ + :: mem:: size_of:: <:: cmsghdr>( ) ) ;
2040
+ let max = ( * mhdr) . msg_control as usize
2041
+ + ( * mhdr) . msg_controllen as usize ;
2042
+ if next > max {
2043
+ 0 as * mut :: cmsghdr
2044
+ } else {
2045
+ _CMSG_HDR_ALIGN( cmsg as usize + ( * cmsg) . cmsg_len as usize )
2046
+ as * mut :: cmsghdr
2047
+ }
2048
+ }
2049
+
2050
+ pub fn CMSG_SPACE ( length: :: c_uint) -> :: c_uint {
2051
+ _CMSG_HDR_ALIGN( :: mem:: size_of:: <:: cmsghdr>( ) as usize
2052
+ + length as usize ) as :: c_uint
2053
+ }
2054
+
1999
2055
pub fn FD_CLR ( fd: :: c_int, set: * mut fd_set) -> ( ) {
2000
2056
let bits = :: mem:: size_of_val( & ( * set) . fds_bits[ 0 ] ) * 8 ;
2001
2057
let fd = fd as usize ;
0 commit comments