]> git.ipfire.org Git - thirdparty/squid.git/blob - compat/cmsg.h
Merged from trunk
[thirdparty/squid.git] / compat / cmsg.h
1 /*
2 * Compatibility-layer for CMSG_
3 */
4 #ifndef SQUID_COMPAT_CMSG_H
5 #define SQUID_COMPAT_CMSG_H
6
7 // cmsg.h is found through sys/socket.h
8 #if HAVE_SYS_SOCKET_H
9 #include <sys/socket.h>
10 #endif
11
12 #ifndef CMSG_H_
13 #define CMSG_H_
14
15 /* mostly windows-specific */
16 #ifndef CMSG_SPACE
17 struct cmsghdr {
18 unsigned int cmsg_len;
19 int cmsg_level;
20 int cmsg_type;
21 unsigned char cmsg_data[16]; /* dummy */
22 /* followed by UCHAR cmsg_data[]; */
23 } ;
24
25 /* lifted off https://metacpan.org/source/SAMPO/Socket-PassAccessRights-0.03/passfd.c */
26 #ifndef CMSG_DATA
27 # define CMSG_DATA(cmsg) ((cmsg)->cmsg_data)
28 #endif
29
30 #ifndef CMSG_NXTHDR
31 # define CMSG_NXTHDR(mhdr, cmsg) __cmsg_nxthdr (mhdr, cmsg)
32 #endif
33
34 #ifndef CMSG_FIRSTHDR
35 # define CMSG_FIRSTHDR(mhdr) \
36 ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) \
37 ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) NULL)
38 #endif
39
40 #ifndef CMSG_ALIGN
41 # define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) \
42 & ~(sizeof (size_t) - 1))
43 #endif
44
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
49
50 #ifndef CMSG_LEN
51 # define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
52 #endif
53
54 struct msghdr {
55 void *msg_name; /* Address to send to/receive from. */
56 socklen_t msg_namelen; /* Length of address data. */
57
58 struct iovec *msg_iov; /* Vector of data to send/receive into. */
59 size_t msg_iovlen; /* Number of elements in the vector. */
60
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
65 with this. */
66
67 int msg_flags; /* Flags on received message. */
68 };
69
70 struct iovec {
71 void *iov_base;
72 size_t iov_len;
73 };
74 struct sockaddr_un {
75 char sun_family;
76 char sun_path[256]; /* pathname */
77 };
78 # define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \
79 + strlen ((ptr)->sun_path))
80
81 #endif /* CMSG_SPACE */
82
83 #ifndef SCM_RIGHTS
84 #define SCM_RIGHTS 1
85 #endif
86 #ifndef SCM_CREDENTIALS
87 #define SCM_CREDENTIALS 2
88 #endif
89 #ifndef SCM_SECURITY
90 #define SCM_SECURITY 3
91 #endif
92
93 #ifndef AF_LOCAL
94 #define AF_LOCAL 1
95 #endif
96
97 #endif /* CMSG_H_ */
98
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.
102
103 #if HAVE_CONSTANT_CMSG_SPACE
104 #define SQUID_CMSG_SPACE CMSG_SPACE
105 #else
106 // add 16 bytes for header and data alignment
107 #define SQUID_CMSG_SPACE(len) (sizeof(struct cmsghdr) + (len) + 16)
108 #endif
109
110 #endif /* SQUID_COMPAT_CMSG_H */