From a0252bc75b8546008c6b87e58344c4340683d5eb Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Thu, 31 Oct 2019 23:09:48 -0400 Subject: [PATCH] move msghdr and cmsghdr out of bits/socket.h these structures can now be defined generically in terms of endianness and long size. previously, the 32-bit archs all shared a common definition from the generic bits header, and each 64-bit arch had to repeat the 64-bit version, with endian conditionals if the arch had variants of each endianness. I would prefer getting rid of the preprocessor conditionals for padding and instead using unnamed bitfield members, like commit 9b2921bea1d5017832e1b45d1fd64220047a9802 did for struct timespec. however, at present sendmsg, recvmsg, and recvmmsg need access to the padding members by name to zero them. this could perhaps be cleaned up in the future. --- arch/aarch64/bits/socket.h | 31 ------------------------------- arch/generic/bits/socket.h | 15 --------------- arch/mips/bits/socket.h | 16 ---------------- arch/mips64/bits/socket.h | 32 -------------------------------- arch/mipsn32/bits/socket.h | 16 ---------------- arch/powerpc/bits/socket.h | 16 ---------------- arch/powerpc64/bits/socket.h | 32 -------------------------------- arch/riscv64/bits/socket.h | 17 ----------------- arch/s390x/bits/socket.h | 17 ----------------- arch/x86_64/bits/socket.h | 16 ---------------- include/sys/socket.h | 34 ++++++++++++++++++++++++++++++++++ 11 files changed, 34 insertions(+), 208 deletions(-) delete mode 100644 arch/aarch64/bits/socket.h delete mode 100644 arch/riscv64/bits/socket.h delete mode 100644 arch/s390x/bits/socket.h delete mode 100644 arch/x86_64/bits/socket.h diff --git a/arch/aarch64/bits/socket.h b/arch/aarch64/bits/socket.h deleted file mode 100644 index 55337c8b..00000000 --- a/arch/aarch64/bits/socket.h +++ /dev/null @@ -1,31 +0,0 @@ -struct msghdr { - void *msg_name; - socklen_t msg_namelen; - struct iovec *msg_iov; -#if __BYTE_ORDER == __BIG_ENDIAN - int __pad1, msg_iovlen; -#else - int msg_iovlen, __pad1; -#endif - void *msg_control; -#if __BYTE_ORDER == __BIG_ENDIAN - int __pad2; - socklen_t msg_controllen; -#else - socklen_t msg_controllen; - int __pad2; -#endif - int msg_flags; -}; - -struct cmsghdr { -#if __BYTE_ORDER == __BIG_ENDIAN - int __pad1; - socklen_t cmsg_len; -#else - socklen_t cmsg_len; - int __pad1; -#endif - int cmsg_level; - int cmsg_type; -}; diff --git a/arch/generic/bits/socket.h b/arch/generic/bits/socket.h index 1f73b995..e69de29b 100644 --- a/arch/generic/bits/socket.h +++ b/arch/generic/bits/socket.h @@ -1,15 +0,0 @@ -struct msghdr { - void *msg_name; - socklen_t msg_namelen; - struct iovec *msg_iov; - int msg_iovlen; - void *msg_control; - socklen_t msg_controllen; - int msg_flags; -}; - -struct cmsghdr { - socklen_t cmsg_len; - int cmsg_level; - int cmsg_type; -}; diff --git a/arch/mips/bits/socket.h b/arch/mips/bits/socket.h index b82c7d34..92551b9f 100644 --- a/arch/mips/bits/socket.h +++ b/arch/mips/bits/socket.h @@ -1,19 +1,3 @@ -struct msghdr { - void *msg_name; - socklen_t msg_namelen; - struct iovec *msg_iov; - int msg_iovlen; - void *msg_control; - socklen_t msg_controllen; - int msg_flags; -}; - -struct cmsghdr { - socklen_t cmsg_len; - int cmsg_level; - int cmsg_type; -}; - #define SOCK_STREAM 2 #define SOCK_DGRAM 1 diff --git a/arch/mips64/bits/socket.h b/arch/mips64/bits/socket.h index aafb209c..519b9c8e 100644 --- a/arch/mips64/bits/socket.h +++ b/arch/mips64/bits/socket.h @@ -1,35 +1,3 @@ -struct msghdr { - void *msg_name; - socklen_t msg_namelen; - struct iovec *msg_iov; -#if __BYTE_ORDER == __BIG_ENDIAN - int __pad1, msg_iovlen; -#else - int msg_iovlen, __pad1; -#endif - void *msg_control; -#if __BYTE_ORDER == __BIG_ENDIAN - int __pad2; - socklen_t msg_controllen; -#else - socklen_t msg_controllen; - int __pad2; -#endif - int msg_flags; -}; - -struct cmsghdr { -#if __BYTE_ORDER == __BIG_ENDIAN - int __pad1; - socklen_t cmsg_len; -#else - socklen_t cmsg_len; - int __pad1; -#endif - int cmsg_level; - int cmsg_type; -}; - #define SOCK_STREAM 2 #define SOCK_DGRAM 1 #define SOL_SOCKET 65535 diff --git a/arch/mipsn32/bits/socket.h b/arch/mipsn32/bits/socket.h index b82c7d34..92551b9f 100644 --- a/arch/mipsn32/bits/socket.h +++ b/arch/mipsn32/bits/socket.h @@ -1,19 +1,3 @@ -struct msghdr { - void *msg_name; - socklen_t msg_namelen; - struct iovec *msg_iov; - int msg_iovlen; - void *msg_control; - socklen_t msg_controllen; - int msg_flags; -}; - -struct cmsghdr { - socklen_t cmsg_len; - int cmsg_level; - int cmsg_type; -}; - #define SOCK_STREAM 2 #define SOCK_DGRAM 1 diff --git a/arch/powerpc/bits/socket.h b/arch/powerpc/bits/socket.h index a94b8bdb..557e324f 100644 --- a/arch/powerpc/bits/socket.h +++ b/arch/powerpc/bits/socket.h @@ -1,19 +1,3 @@ -struct msghdr { - void *msg_name; - socklen_t msg_namelen; - struct iovec *msg_iov; - int msg_iovlen; - void *msg_control; - socklen_t msg_controllen; - int msg_flags; -}; - -struct cmsghdr { - socklen_t cmsg_len; - int cmsg_level; - int cmsg_type; -}; - #define SO_DEBUG 1 #define SO_REUSEADDR 2 #define SO_TYPE 3 diff --git a/arch/powerpc64/bits/socket.h b/arch/powerpc64/bits/socket.h index dae47302..557e324f 100644 --- a/arch/powerpc64/bits/socket.h +++ b/arch/powerpc64/bits/socket.h @@ -1,35 +1,3 @@ -struct msghdr { - void *msg_name; - socklen_t msg_namelen; - struct iovec *msg_iov; -#if __BYTE_ORDER == __BIG_ENDIAN - int __pad1, msg_iovlen; -#else - int msg_iovlen, __pad1; -#endif - void *msg_control; -#if __BYTE_ORDER == __BIG_ENDIAN - int __pad2; - socklen_t msg_controllen; -#else - socklen_t msg_controllen; - int __pad2; -#endif - int msg_flags; -}; - -struct cmsghdr { -#if __BYTE_ORDER == __BIG_ENDIAN - int __pad1; - socklen_t cmsg_len; -#else - socklen_t cmsg_len; - int __pad1; -#endif - int cmsg_level; - int cmsg_type; -}; - #define SO_DEBUG 1 #define SO_REUSEADDR 2 #define SO_TYPE 3 diff --git a/arch/riscv64/bits/socket.h b/arch/riscv64/bits/socket.h deleted file mode 100644 index e2fd64cf..00000000 --- a/arch/riscv64/bits/socket.h +++ /dev/null @@ -1,17 +0,0 @@ -struct msghdr { - void *msg_name; - socklen_t msg_namelen; - struct iovec *msg_iov; - int msg_iovlen, __pad1; - void *msg_control; - socklen_t msg_controllen; - int __pad2; - int msg_flags; -}; - -struct cmsghdr { - socklen_t cmsg_len; - int __pad1; - int cmsg_level; - int cmsg_type; -}; diff --git a/arch/s390x/bits/socket.h b/arch/s390x/bits/socket.h deleted file mode 100644 index bd4b20c4..00000000 --- a/arch/s390x/bits/socket.h +++ /dev/null @@ -1,17 +0,0 @@ -struct msghdr { - void *msg_name; - socklen_t msg_namelen; - struct iovec *msg_iov; - int __pad1, msg_iovlen; - void *msg_control; - int __pad2; - socklen_t msg_controllen; - int msg_flags; -}; - -struct cmsghdr { - int __pad1; - socklen_t cmsg_len; - int cmsg_level; - int cmsg_type; -}; diff --git a/arch/x86_64/bits/socket.h b/arch/x86_64/bits/socket.h deleted file mode 100644 index a4c89f3d..00000000 --- a/arch/x86_64/bits/socket.h +++ /dev/null @@ -1,16 +0,0 @@ -struct msghdr { - void *msg_name; - socklen_t msg_namelen; - struct iovec *msg_iov; - int msg_iovlen, __pad1; - void *msg_control; - socklen_t msg_controllen, __pad2; - int msg_flags; -}; - -struct cmsghdr { - socklen_t cmsg_len; - int __pad1; - int cmsg_level; - int cmsg_type; -}; diff --git a/include/sys/socket.h b/include/sys/socket.h index 6be699d9..4ea7be1e 100644 --- a/include/sys/socket.h +++ b/include/sys/socket.h @@ -19,6 +19,40 @@ extern "C" { #include +struct msghdr { + void *msg_name; + socklen_t msg_namelen; + struct iovec *msg_iov; +#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN + int __pad1; +#endif + int msg_iovlen; +#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN + int __pad1; +#endif + void *msg_control; +#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN + int __pad2; +#endif + socklen_t msg_controllen; +#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN + int __pad2; +#endif + int msg_flags; +}; + +struct cmsghdr { +#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN + int __pad1; +#endif + socklen_t cmsg_len; +#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN + int __pad1; +#endif + int cmsg_level; + int cmsg_type; +}; + #ifdef _GNU_SOURCE struct ucred { pid_t pid; -- 2.25.1