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
9b2921bea1 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.
This commit is contained in:
Rich Felker 2019-10-31 23:09:48 -04:00
parent 573a4d2d59
commit a0252bc75b
11 changed files with 34 additions and 208 deletions

View File

@ -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;
};

View File

@ -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;
};

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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;
};

View File

@ -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;
};

View File

@ -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;
};

View File

@ -19,6 +19,40 @@ extern "C" {
#include <bits/socket.h>
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;