Use macros from bsd headers

This commit is contained in:
Dave Murphy 2023-04-02 16:39:25 +01:00 committed by GitHub
parent 1c1aaf6223
commit 833d295a18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -437,11 +437,20 @@ struct cmsghdr {
/* followed by u_char cmsg_data[]; */ /* followed by u_char cmsg_data[]; */
}; };
// socket credential stuff, we don't need this #define _ALIGNBYTES (sizeof(long) - 1)
// cmsg macros, uses some obscure macro #define _ALIGN(p) (((unsigned long)(p) + _ALIGNBYTES) & ~_ALIGNBYTES)
#define __ALIGNBYTES32 (sizeof(__uint32_t) - 1) /* given pointer to struct cmsghdr, return pointer to data */
#define __ALIGN32(p) ((__size_t)((char *)(__size_t)(p) + __ALIGNBYTES32) &~ __ALIGNBYTES32) #define CMSG_DATA(cmsg) \
((unsigned char *)(cmsg) + _ALIGN(sizeof(struct cmsghdr)))
/* given pointer to struct cmsghdr, return pointer to next cmsghdr */
#define CMSG_NXTHDR(mhdr, cmsg) \
(((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len) + \
_ALIGN(sizeof(struct cmsghdr)) > \
((char *)(mhdr)->msg_control) + (mhdr)->msg_controllen) ? \
(struct cmsghdr *)NULL : \
(struct cmsghdr *)((char *)(cmsg) + _ALIGN((cmsg)->cmsg_len)))
/* /*
* RFC 2292 requires to check msg_controllen, in case that the kernel returns * RFC 2292 requires to check msg_controllen, in case that the kernel returns
@ -452,17 +461,11 @@ struct cmsghdr {
(struct cmsghdr *)(mhdr)->msg_control : \ (struct cmsghdr *)(mhdr)->msg_control : \
(struct cmsghdr *)NULL) (struct cmsghdr *)NULL)
/* Length of the contents of a control message of length len */
#define CMSG_LEN(len) (_ALIGN(sizeof(struct cmsghdr)) + (len))
/* /* Length of the space taken up by a padded control message of length len */
* Given pointer to struct cmsghdr, return pointer to next cmsghdr #define CMSG_SPACE(len) (_ALIGN(sizeof(struct cmsghdr)) + _ALIGN(len))
* RFC 2292 says that CMSG_NXTHDR(mhdr, NULL) is equivalent to CMSG_FIRSTHDR(mhdr)
*/
#define CMSG_NXTHDR(mhdr, cmsg) \
(((char *)(cmsg) + __ALIGN32((cmsg)->cmsg_len) + \
__ALIGN32(sizeof(struct cmsghdr)) > \
((char *)(mhdr)->msg_control) + (mhdr)->msg_controllen) ? \
(struct cmsghdr *)NULL : \
(struct cmsghdr *)((char *)(cmsg) + __ALIGN32((cmsg)->cmsg_len)))
/* "Socket"-level control message types: */ /* "Socket"-level control message types: */
#define SCM_RIGHTS 0x01 /* access rights (array of int) */ #define SCM_RIGHTS 0x01 /* access rights (array of int) */