]>
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>
12 // WinSock2.h defines these for Windows
17 // sockaddr_un might be in sys/un.h if not pulled in already
24 unsigned int cmsg_len
;
27 unsigned char cmsg_data
[16]; /* dummy */
28 /* followed by UCHAR cmsg_data[]; */
32 /* lifted off https://metacpan.org/source/SAMPO/Socket-PassAccessRights-0.03/passfd.c */
34 # define CMSG_DATA(cmsg) ((cmsg)->cmsg_data)
38 # define CMSG_NXTHDR(mhdr, cmsg) __cmsg_nxthdr (mhdr, cmsg)
42 # define CMSG_FIRSTHDR(mhdr) \
43 ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) \
44 ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) NULL)
48 # define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) \
49 & ~(sizeof (size_t) - 1))
53 # define CMSG_SPACE(len) (CMSG_ALIGN (len) \
54 + CMSG_ALIGN (sizeof (struct cmsghdr)))
55 #undef HAVE_CONSTANT_CMSG_SPACE
56 #define HAVE_CONSTANT_CMSG_SPACE 1
60 # define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
72 void *msg_name
; /* Address to send to/receive from. */
73 socklen_t msg_namelen
; /* Length of address data. */
75 struct iovec
*msg_iov
; /* Vector of data to send/receive into. */
76 size_t msg_iovlen
; /* Number of elements in the vector. */
78 void *msg_control
; /* Ancillary data (eg BSD filedesc passing). */
79 size_t msg_controllen
; /* Ancillary data buffer length.
80 !! The type should be socklen_t but the
81 definition of the kernel is incompatible
84 int msg_flags
; /* Flags on received message. */
91 char sun_path
[256]; /* pathname */
96 # define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \
97 + strlen ((ptr)->sun_path))
103 #ifndef SCM_CREDENTIALS
104 #define SCM_CREDENTIALS 2
107 #define SCM_SECURITY 3
114 // CMSG_SPACE is not constant on some systems (in particular Max OS X),
115 // provide a replacement that can be used at build time in that case
116 // NP: this must go below our replacement definitions.
118 #if HAVE_CONSTANT_CMSG_SPACE
119 #define SQUID_CMSG_SPACE CMSG_SPACE
121 // add 16 bytes for header and data alignment
122 #define SQUID_CMSG_SPACE(len) (sizeof(struct cmsghdr) + (len) + 16)
125 #endif /* SQUID_COMPAT_CMSG_H */