cmsg.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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.
7 */
8
9#ifndef SQUID_COMPAT_CMSG_H
10#define SQUID_COMPAT_CMSG_H
11
12/*
13 * Compatibility-layer for CMSG_
14 */
15
16// cmsg.h is found through sys/socket.h
17#if HAVE_SYS_SOCKET_H
18#include <sys/socket.h>
19#endif
20
21// mswsock.h defines WSA_CMSG definitions
22#if HAVE_MSWSOCK_H
23#include <mswsock.h>
24#endif
25#if HAVE_WINSOCK2_H
26#include <winsock2.h>
27#endif
28
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
33
34#if !HAVE_CMSGHDR
35struct cmsghdr {
36 unsigned int cmsg_len;
39 unsigned char cmsg_data[16]; /* dummy */
40 /* followed by UCHAR cmsg_data[]; */
41};
42#endif
43
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)
50#else
51# define SQUID_CMSG_DATA(cmsg) ((cmsg)->cmsg_data)
52#endif
53
54#ifndef CMSG_NXTHDR
55# define CMSG_NXTHDR(mhdr, X) __cmsg_nxthdr (mhdr, X)
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 *) nullptr)
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
69#ifndef CMSG_SPACE
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
74#endif
75
76#ifndef CMSG_LEN
77# define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
78#endif
79
80#if !HAVE_IOVEC
81struct iovec {
82 void *iov_base;
83 size_t iov_len;
84};
85#endif
86
87#if !HAVE_MSGHDR
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};
103#endif
104
105#if !HAVE_SOCKADDR_UN
108 char sun_path[256]; /* pathname */
109};
110#endif
111
112#ifndef SUN_LEN
113# define SUN_LEN(ptr) ((size_t) (((struct sockaddr_un *) 0)->sun_path) \
114 + strlen ((ptr)->sun_path))
115#endif
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
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
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 */
143
Definition: cmsg.h:35
unsigned char cmsg_data[16]
Definition: cmsg.h:39
int cmsg_type
Definition: cmsg.h:38
int cmsg_level
Definition: cmsg.h:37
unsigned int cmsg_len
Definition: cmsg.h:36
Definition: cmsg.h:81
void * iov_base
Definition: cmsg.h:82
size_t iov_len
Definition: cmsg.h:83
Definition: cmsg.h:88
struct iovec * msg_iov
Definition: cmsg.h:92
socklen_t msg_namelen
Definition: cmsg.h:90
void * msg_name
Definition: cmsg.h:89
int msg_flags
Definition: cmsg.h:101
size_t msg_controllen
Definition: cmsg.h:96
size_t msg_iovlen
Definition: cmsg.h:93
void * msg_control
Definition: cmsg.h:95
char sun_family
Definition: cmsg.h:107
char sun_path[256]
Definition: cmsg.h:108
int socklen_t
Definition: types.h:137

 

Introduction

Documentation

Support

Miscellaneous

Web Site Translations

Mirrors