xref: /unit/auto/sockets (revision 2041:3ecccccc5d19)
1
2# Copyright (C) Igor Sysoev
3# Copyright (C) NGINX, Inc.
4
5
6if [ $NXT_INET6 = YES ]; then
7
8    nxt_feature="AF_INET6"
9    nxt_feature_name=NXT_INET6
10    nxt_feature_run=
11    nxt_feature_incs=
12    nxt_feature_libs=
13    nxt_feature_test="#include <stdio.h>
14                      #include <sys/socket.h>
15                      #include <sys/types.h>
16                      #include <netinet/in.h>
17
18                      int main() {
19                          struct sockaddr_in6  sin6;
20
21                          sin6.sin6_family = AF_INET6;
22                          printf(\"%d\", sin6.sin6_family);
23                          return 0;
24                      }"
25    . auto/feature
26fi
27
28
29# FreeBSD, MacOSX, NetBSD, OpenBSD.
30
31nxt_feature="sockaddr.sa_len"
32nxt_feature_name=NXT_SOCKADDR_SA_LEN
33nxt_feature_run=
34nxt_feature_incs=
35nxt_feature_libs=
36nxt_feature_test="#include <stdio.h>
37                  #include <sys/socket.h>
38
39                  int main() {
40                      struct sockaddr  sa;
41
42                      sa.sa_len = 0;
43                      printf(\"%d\", sa.sa_len);
44                      return 0;
45                  }"
46. auto/feature
47
48
49nxt_feature="struct sockaddr size"
50nxt_feature_name=NXT_HAVE_SOCKADDR
51nxt_feature_run=value
52nxt_feature_incs=
53nxt_feature_libs=
54nxt_feature_test="#include <stdio.h>
55                  #include <sys/socket.h>
56
57                  int main() {
58                      printf(\"%d\", (int) sizeof(struct sockaddr));
59                      return 0;
60                  }"
61. auto/feature
62
63
64nxt_feature="struct sockaddr_in size"
65nxt_feature_name=NXT_HAVE_SOCKADDR_IN
66nxt_feature_run=value
67nxt_feature_incs=
68nxt_feature_libs=
69nxt_feature_test="#include <stdio.h>
70                  #include <sys/types.h>
71                  #include <netinet/in.h>
72
73                  int main() {
74                      printf(\"%d\", (int) sizeof(struct sockaddr_in));
75                      return 0;
76                  }"
77. auto/feature
78
79
80nxt_feature="struct sockaddr_in6 size"
81nxt_feature_name=NXT_HAVE_SOCKADDR_IN6
82nxt_feature_run=value
83nxt_feature_incs=
84nxt_feature_libs=
85nxt_feature_test="#include <stdio.h>
86                  #include <sys/types.h>
87                  #include <netinet/in.h>
88
89                  int main() {
90                      printf(\"%d\", (int) sizeof(struct sockaddr_in6));
91                      return 0;
92                  }"
93. auto/feature
94
95
96nxt_feature="struct sockaddr_un size"
97nxt_feature_name=NXT_HAVE_SOCKADDR_UN
98nxt_feature_run=value
99nxt_feature_incs=
100nxt_feature_libs=
101nxt_feature_test="#include <stdio.h>
102                  #include <sys/types.h>
103                  #include <sys/un.h>
104
105                  int main() {
106                      printf(\"%d\", (int) sizeof(struct sockaddr_un));
107                      return 0;
108                  }"
109. auto/feature
110
111
112nxt_feature="struct sockaddr_storage size"
113nxt_feature_name=NXT_HAVE_SOCKADDR_STORAGE
114nxt_feature_run=value
115nxt_feature_incs=
116nxt_feature_libs=
117nxt_feature_test="#include <stdio.h>
118                  #include <sys/socket.h>
119
120                  int main() {
121                      printf(\"%d\", (int) sizeof(struct sockaddr_storage));
122                      return 0;
123                  }"
124. auto/feature
125
126
127nxt_feature="socketpair(AF_UNIX, SOCK_SEQPACKET)"
128nxt_feature_name=NXT_HAVE_AF_UNIX_SOCK_SEQPACKET
129nxt_feature_run=yes
130nxt_feature_incs=
131nxt_feature_libs=
132nxt_feature_test="#include <stdio.h>
133                  #include <sys/socket.h>
134
135                  int main() {
136                      int  pair[2];
137
138                      if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, pair) != 0)
139                          return 1;
140                      return 0;
141                  }"
142. auto/feature
143
144
145nxt_feature="struct msghdr.msg_control"
146nxt_feature_name=NXT_HAVE_MSGHDR_MSG_CONTROL
147nxt_feature_run=
148nxt_feature_incs=
149nxt_feature_libs=
150nxt_feature_test="#include <stdio.h>
151                  #include <sys/socket.h>
152
153                  int main() {
154                      struct  msghdr  msg;
155
156                      printf(\"%d\", (int) sizeof(msg.msg_control));
157                      return 0;
158                  }"
159. auto/feature
160
161if [ $nxt_found = no ]; then
162    $echo
163    $echo $0: error: no msghdr.msg_control struct member.
164    $echo
165    exit 1;
166fi
167
168
169if [ $NXT_SYSTEM != DragonFly ]; then
170    nxt_feature="sockopt SO_PASSCRED"
171    nxt_feature_name=NXT_HAVE_SOCKOPT_SO_PASSCRED
172    nxt_feature_run=
173    nxt_feature_incs=
174    nxt_feature_libs=
175    nxt_feature_test="#define _GNU_SOURCE
176                      #include <sys/socket.h>
177
178                      int main() {
179                          return SO_PASSCRED == 0;
180                      }"
181    . auto/feature
182
183
184    if [ $nxt_found = yes ]; then
185        nxt_feature="struct ucred"
186        nxt_feature_name=NXT_HAVE_UCRED
187        nxt_feature_run=
188        nxt_feature_incs=
189        nxt_feature_libs=
190        nxt_feature_test="#define _GNU_SOURCE
191                          #include <sys/socket.h>
192                          #include <sys/un.h>
193
194                          int main() {
195                              return sizeof(struct ucred);
196                          }"
197        . auto/feature
198    fi
199
200
201    nxt_feature="struct cmsgcred"
202    nxt_feature_name=NXT_HAVE_MSGHDR_CMSGCRED
203    nxt_feature_run=
204    nxt_feature_incs=
205    nxt_feature_libs=
206    nxt_feature_test="#define _GNU_SOURCE
207                      #include <sys/socket.h>
208
209                      int main() {
210                          return sizeof(struct cmsgcred);
211                      }"
212    . auto/feature
213fi
214
215
216nxt_feature="sys/filio.h"
217nxt_feature_name=NXT_HAVE_SYS_FILIO_H
218nxt_feature_run=
219nxt_feature_incs=
220nxt_feature_libs=
221nxt_feature_test="#include <sys/filio.h>
222
223                  int main() {
224                      return 0;
225                  }"
226. auto/feature
227
228if [ $nxt_found = yes ]; then
229    NXT_SYS_FILIO_H="#include <sys/filio.h>"
230else
231    NXT_SYS_FILIO_H=
232fi
233
234
235nxt_feature="ioctl(FIONBIO)"
236nxt_feature_name=NXT_HAVE_FIONBIO
237nxt_feature_run=
238nxt_feature_incs=
239nxt_feature_libs=
240nxt_feature_test="#include <unistd.h>
241                  #include <sys/socket.h>
242                  $NXT_SYS_FILIO_H
243                  #include <sys/ioctl.h>
244
245                  int main() {
246                      int  nb;
247
248                      nb = 0;
249                      ioctl(-1, FIONBIO, &nb);
250                      return 0;
251                  }"
252. auto/feature
253
254
255# socket(SOCK_NONBLOCK), Linux 2.6.27/glibc 2.10, NetBSD 6.0, FreeBSD 9.2.
256
257nxt_feature="socket(SOCK_NONBLOCK)"
258nxt_feature_name=NXT_HAVE_SOCK_NONBLOCK
259nxt_feature_run=
260nxt_feature_incs=
261nxt_feature_libs=
262nxt_feature_test="#define _GNU_SOURCE
263                  #include <sys/socket.h>
264
265                  int main() {
266                      socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
267                      return 0;
268                  }"
269. auto/feature
270
271
272# accept4(), Linux 2.6.28/glibc 2.10, NetBSD 6.0, FreeBSD 9.2.
273
274nxt_feature="accept4()"
275nxt_feature_name=NXT_HAVE_ACCEPT4
276nxt_feature_run=
277nxt_feature_incs=
278nxt_feature_libs=
279nxt_feature_test="#define _GNU_SOURCE
280                  #include <stdlib.h>
281                  #include <sys/socket.h>
282
283                  int main() {
284                      accept4(0, NULL, NULL, SOCK_NONBLOCK);
285                      return 0;
286                  }"
287. auto/feature
288