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