]>
git.ipfire.org Git - thirdparty/squid.git/blob - compat/cmsg.h
2 * Compatibility-layer for CMSG_
4 #ifndef SQUID_COMPAT_CMSG_H
5 #define SQUID_COMPAT_CMSG_H
7 // cmsg.h is found through sys/socket.h
9 #include <sys/socket.h>
15 /* mostly windows-specific */
18 unsigned int cmsg_len
;
21 unsigned char cmsg_data
[16]; /* dummy */
22 /* followed by UCHAR cmsg_data[]; */
25 /* lifted off https://metacpan.org/source/SAMPO/Socket-PassAccessRights-0.03/passfd.c */
27 # define CMSG_DATA(cmsg) ((cmsg)->cmsg_data)
31 # define CMSG_NXTHDR(mhdr, cmsg) __cmsg_nxthdr (mhdr, cmsg)
35 # define CMSG_FIRSTHDR(mhdr) \
36 ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) \
37 ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) NULL)
41 # define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) \
42 & ~(sizeof (size_t) - 1))
45 # define CMSG_SPACE(len) (CMSG_ALIGN (len) \
46 + CMSG_ALIGN (sizeof (struct cmsghdr)))
47 #undef HAVE_CONSTANT_CMSG_SPACE
48 #define HAVE_CONSTANT_CMSG_SPACE 1
51 # define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
55 void *msg_name
; /* Address to send to/receive from. */
56 socklen_t msg_namelen
; /* Length of address data. */
58 struct iovec
*msg_iov
; /* Vector of data to send/receive into. */
59 size_t msg_iovlen
; /* Number of elements in the vector. */
61 void *msg_control
; /* Ancillary data (eg BSD filedesc passing). */
62 size_t msg_controllen
; /* Ancillary data buffer length.
63 !! The type should be socklen_t but the
64 definition of the kernel is incompatible
67 int msg_flags
; /* Flags on received message. */
76 char sun_path
[256]; /* pathname */
78 # define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \
79 + strlen ((ptr)->sun_path))
81 #endif /* CMSG_SPACE */
86 #ifndef SCM_CREDENTIALS
87 #define SCM_CREDENTIALS 2
90 #define SCM_SECURITY 3
99 // CMSG_SPACE is not constant on some systems (in particular Max OS X),
100 // provide a replacement that can be used at build time in that case
101 // NP: this must go below our replacement definitions.
103 #if HAVE_CONSTANT_CMSG_SPACE
104 #define SQUID_CMSG_SPACE CMSG_SPACE
106 // add 16 bytes for header and data alignment
107 #define SQUID_CMSG_SPACE(len) (sizeof(struct cmsghdr) + (len) + 16)
110 #endif /* SQUID_COMPAT_CMSG_H */