]>
git.ipfire.org Git - thirdparty/squid.git/blob - compat/cmsg.h
2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 #ifndef SQUID_COMPAT_CMSG_H
10 #define SQUID_COMPAT_CMSG_H
13 * Compatibility-layer for CMSG_
16 // cmsg.h is found through sys/socket.h
18 #include <sys/socket.h>
21 // mswsock.h defines WSA_CMSG definitions
29 // sockaddr_un might be in sys/un.h if not pulled in already
36 unsigned int cmsg_len
;
39 unsigned char cmsg_data
[16]; /* dummy */
40 /* followed by UCHAR cmsg_data[]; */
44 /* lifted off https://metacpan.org/source/SAMPO/Socket-PassAccessRights-0.03/passfd.c */
45 // check for WSA_CMSG first because Windows defines CMSG_DATA for other uses
46 #if defined(WSA_CMSG_DATA)
47 # define SQUID_CMSG_DATA(cmsg) WSA_CMSG_DATA(cmsg)
48 #elif defined(CMSG_DATA)
49 # define SQUID_CMSG_DATA(cmsg) CMSG_DATA(cmsg)
51 # define SQUID_CMSG_DATA(cmsg) ((cmsg)->cmsg_data)
55 # define CMSG_NXTHDR(mhdr, X) __cmsg_nxthdr (mhdr, X)
59 # define CMSG_FIRSTHDR(mhdr) \
60 ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) \
61 ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) NULL)
65 # define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) \
66 & ~(sizeof (size_t) - 1))
70 # define CMSG_SPACE(len) (CMSG_ALIGN (len) \
71 + CMSG_ALIGN (sizeof (struct cmsghdr)))
72 #undef HAVE_CONSTANT_CMSG_SPACE
73 #define HAVE_CONSTANT_CMSG_SPACE 1
77 # define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
89 void *msg_name
; /* Address to send to/receive from. */
90 socklen_t msg_namelen
; /* Length of address data. */
92 struct iovec
*msg_iov
; /* Vector of data to send/receive into. */
93 size_t msg_iovlen
; /* Number of elements in the vector. */
95 void *msg_control
; /* Ancillary data (eg BSD filedesc passing). */
96 size_t msg_controllen
; /* Ancillary data buffer length.
97 !! The type should be socklen_t but the
98 definition of the kernel is incompatible
101 int msg_flags
; /* Flags on received message. */
105 #if !HAVE_SOCKADDR_UN
108 char sun_path
[256]; /* pathname */
113 # define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \
114 + strlen ((ptr)->sun_path))
120 #ifndef SCM_CREDENTIALS
121 #define SCM_CREDENTIALS 2
124 #define SCM_SECURITY 3
131 // CMSG_SPACE is not constant on some systems (in particular Max OS X),
132 // provide a replacement that can be used at build time in that case
133 // NP: this must go below our replacement definitions.
135 #if HAVE_CONSTANT_CMSG_SPACE
136 #define SQUID_CMSG_SPACE CMSG_SPACE
138 // add 16 bytes for header and data alignment
139 #define SQUID_CMSG_SPACE(len) (sizeof(struct cmsghdr) + (len) + 16)
142 #endif /* SQUID_COMPAT_CMSG_H */