]> git.ipfire.org Git - thirdparty/squid.git/blame - compat/cmsg.h
SourceFormat Enforcement
[thirdparty/squid.git] / compat / cmsg.h
CommitLineData
f68414c6 1/*
4ac4a490 2 * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
37be9888
AJ
3 *
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.
f68414c6 7 */
37be9888 8
14c0d3ab
DK
9#ifndef SQUID_COMPAT_CMSG_H
10#define SQUID_COMPAT_CMSG_H
11
37be9888
AJ
12/*
13 * Compatibility-layer for CMSG_
14 */
15
f68414c6 16// cmsg.h is found through sys/socket.h
14c0d3ab
DK
17#if HAVE_SYS_SOCKET_H
18#include <sys/socket.h>
19#endif
20
2ff9dfaa
AJ
21// mswsock.h defines WSA_CMSG definitions
22#if HAVE_MSWSOCK_H
23#include <mswsock.h>
24#endif
5c01f369
AJ
25#if HAVE_WINSOCK2_H
26#include <winsock2.h>
5c01f369
AJ
27#endif
28
c72f8c2e
AJ
29// sockaddr_un might be in sys/un.h if not pulled in already
30#if HAVE_SYS_UN_H
31#include <sys/un.h>
32#endif
f68414c6 33
c72f8c2e 34#if !HAVE_CMSGHDR
00e73a76 35struct cmsghdr {
c72f8c2e
AJ
36 unsigned int cmsg_len;
37 int cmsg_level;
38 int cmsg_type;
00e73a76
A
39 unsigned char cmsg_data[16]; /* dummy */
40 /* followed by UCHAR cmsg_data[]; */
c72f8c2e
AJ
41};
42#endif
f68414c6
AJ
43
44/* lifted off https://metacpan.org/source/SAMPO/Socket-PassAccessRights-0.03/passfd.c */
2ff9dfaa
AJ
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)
50#else
51# define SQUID_CMSG_DATA(cmsg) ((cmsg)->cmsg_data)
f68414c6
AJ
52#endif
53
54#ifndef CMSG_NXTHDR
2ff9dfaa 55# define CMSG_NXTHDR(mhdr, X) __cmsg_nxthdr (mhdr, X)
f68414c6
AJ
56#endif
57
58#ifndef CMSG_FIRSTHDR
59# define CMSG_FIRSTHDR(mhdr) \
60 ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) \
61 ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) NULL)
62#endif
63
64#ifndef CMSG_ALIGN
65# define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) \
66 & ~(sizeof (size_t) - 1))
67#endif
68
c72f8c2e 69#ifndef CMSG_SPACE
f68414c6
AJ
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
c72f8c2e 74#endif
f68414c6
AJ
75
76#ifndef CMSG_LEN
77# define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
78#endif
79
c72f8c2e
AJ
80#if !HAVE_IOVEC
81struct iovec {
82 void *iov_base;
83 size_t iov_len;
84};
85#endif
86
87#if !HAVE_MSGHDR
f68414c6
AJ
88struct msghdr {
89 void *msg_name; /* Address to send to/receive from. */
90 socklen_t msg_namelen; /* Length of address data. */
91
92 struct iovec *msg_iov; /* Vector of data to send/receive into. */
93 size_t msg_iovlen; /* Number of elements in the vector. */
94
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
99 with this. */
100
101 int msg_flags; /* Flags on received message. */
102};
c72f8c2e 103#endif
f68414c6 104
c72f8c2e 105#if !HAVE_SOCKADDR_UN
f68414c6 106struct sockaddr_un {
00e73a76 107 char sun_family;
f68414c6
AJ
108 char sun_path[256]; /* pathname */
109};
c72f8c2e
AJ
110#endif
111
112#ifndef SUN_LEN
f68414c6
AJ
113# define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \
114 + strlen ((ptr)->sun_path))
c72f8c2e 115#endif
f68414c6
AJ
116
117#ifndef SCM_RIGHTS
118#define SCM_RIGHTS 1
119#endif
120#ifndef SCM_CREDENTIALS
121#define SCM_CREDENTIALS 2
122#endif
123#ifndef SCM_SECURITY
124#define SCM_SECURITY 3
125#endif
126
127#ifndef AF_LOCAL
128#define AF_LOCAL 1
129#endif
130
f68414c6
AJ
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.
134
14c0d3ab
DK
135#if HAVE_CONSTANT_CMSG_SPACE
136#define SQUID_CMSG_SPACE CMSG_SPACE
137#else
138// add 16 bytes for header and data alignment
139#define SQUID_CMSG_SPACE(len) (sizeof(struct cmsghdr) + (len) + 16)
140#endif
141
142#endif /* SQUID_COMPAT_CMSG_H */
f53969cc 143