xref: /unit/auto/sockets (revision 2026)
10Sigor@sysoev.ru
20Sigor@sysoev.ru# Copyright (C) Igor Sysoev
30Sigor@sysoev.ru# Copyright (C) NGINX, Inc.
40Sigor@sysoev.ru
50Sigor@sysoev.ru
60Sigor@sysoev.ruif [ $NXT_INET6 = YES ]; then
70Sigor@sysoev.ru
80Sigor@sysoev.ru    nxt_feature="AF_INET6"
90Sigor@sysoev.ru    nxt_feature_name=NXT_INET6
100Sigor@sysoev.ru    nxt_feature_run=
110Sigor@sysoev.ru    nxt_feature_incs=
120Sigor@sysoev.ru    nxt_feature_libs=
130Sigor@sysoev.ru    nxt_feature_test="#include <stdio.h>
140Sigor@sysoev.ru                      #include <sys/socket.h>
150Sigor@sysoev.ru                      #include <sys/types.h>
160Sigor@sysoev.ru                      #include <netinet/in.h>
170Sigor@sysoev.ru
180Sigor@sysoev.ru                      int main() {
190Sigor@sysoev.ru                          struct sockaddr_in6  sin6;
200Sigor@sysoev.ru
210Sigor@sysoev.ru                          sin6.sin6_family = AF_INET6;
220Sigor@sysoev.ru                          printf(\"%d\", sin6.sin6_family);
230Sigor@sysoev.ru                          return 0;
240Sigor@sysoev.ru                      }"
250Sigor@sysoev.ru    . auto/feature
260Sigor@sysoev.rufi
270Sigor@sysoev.ru
280Sigor@sysoev.ru
290Sigor@sysoev.ru# FreeBSD, MacOSX, NetBSD, OpenBSD.
300Sigor@sysoev.ru
310Sigor@sysoev.runxt_feature="sockaddr.sa_len"
320Sigor@sysoev.runxt_feature_name=NXT_SOCKADDR_SA_LEN
330Sigor@sysoev.runxt_feature_run=
340Sigor@sysoev.runxt_feature_incs=
350Sigor@sysoev.runxt_feature_libs=
360Sigor@sysoev.runxt_feature_test="#include <stdio.h>
370Sigor@sysoev.ru                  #include <sys/socket.h>
380Sigor@sysoev.ru
390Sigor@sysoev.ru                  int main() {
400Sigor@sysoev.ru                      struct sockaddr  sa;
410Sigor@sysoev.ru
420Sigor@sysoev.ru                      sa.sa_len = 0;
430Sigor@sysoev.ru                      printf(\"%d\", sa.sa_len);
440Sigor@sysoev.ru                      return 0;
450Sigor@sysoev.ru                  }"
460Sigor@sysoev.ru. auto/feature
470Sigor@sysoev.ru
480Sigor@sysoev.ru
490Sigor@sysoev.runxt_feature="struct sockaddr size"
500Sigor@sysoev.runxt_feature_name=NXT_HAVE_SOCKADDR
510Sigor@sysoev.runxt_feature_run=value
520Sigor@sysoev.runxt_feature_incs=
530Sigor@sysoev.runxt_feature_libs=
540Sigor@sysoev.runxt_feature_test="#include <stdio.h>
550Sigor@sysoev.ru                  #include <sys/socket.h>
560Sigor@sysoev.ru
570Sigor@sysoev.ru                  int main() {
580Sigor@sysoev.ru                      printf(\"%d\", (int) sizeof(struct sockaddr));
590Sigor@sysoev.ru                      return 0;
600Sigor@sysoev.ru                  }"
610Sigor@sysoev.ru. auto/feature
620Sigor@sysoev.ru
630Sigor@sysoev.ru
640Sigor@sysoev.runxt_feature="struct sockaddr_in size"
650Sigor@sysoev.runxt_feature_name=NXT_HAVE_SOCKADDR_IN
660Sigor@sysoev.runxt_feature_run=value
670Sigor@sysoev.runxt_feature_incs=
680Sigor@sysoev.runxt_feature_libs=
690Sigor@sysoev.runxt_feature_test="#include <stdio.h>
700Sigor@sysoev.ru                  #include <sys/types.h>
710Sigor@sysoev.ru                  #include <netinet/in.h>
720Sigor@sysoev.ru
730Sigor@sysoev.ru                  int main() {
740Sigor@sysoev.ru                      printf(\"%d\", (int) sizeof(struct sockaddr_in));
750Sigor@sysoev.ru                      return 0;
760Sigor@sysoev.ru                  }"
770Sigor@sysoev.ru. auto/feature
780Sigor@sysoev.ru
790Sigor@sysoev.ru
800Sigor@sysoev.runxt_feature="struct sockaddr_in6 size"
810Sigor@sysoev.runxt_feature_name=NXT_HAVE_SOCKADDR_IN6
820Sigor@sysoev.runxt_feature_run=value
830Sigor@sysoev.runxt_feature_incs=
840Sigor@sysoev.runxt_feature_libs=
850Sigor@sysoev.runxt_feature_test="#include <stdio.h>
860Sigor@sysoev.ru                  #include <sys/types.h>
870Sigor@sysoev.ru                  #include <netinet/in.h>
880Sigor@sysoev.ru
890Sigor@sysoev.ru                  int main() {
900Sigor@sysoev.ru                      printf(\"%d\", (int) sizeof(struct sockaddr_in6));
910Sigor@sysoev.ru                      return 0;
920Sigor@sysoev.ru                  }"
930Sigor@sysoev.ru. auto/feature
940Sigor@sysoev.ru
950Sigor@sysoev.ru
960Sigor@sysoev.runxt_feature="struct sockaddr_un size"
970Sigor@sysoev.runxt_feature_name=NXT_HAVE_SOCKADDR_UN
980Sigor@sysoev.runxt_feature_run=value
990Sigor@sysoev.runxt_feature_incs=
1000Sigor@sysoev.runxt_feature_libs=
1010Sigor@sysoev.runxt_feature_test="#include <stdio.h>
1020Sigor@sysoev.ru                  #include <sys/types.h>
1030Sigor@sysoev.ru                  #include <sys/un.h>
1040Sigor@sysoev.ru
1050Sigor@sysoev.ru                  int main() {
1060Sigor@sysoev.ru                      printf(\"%d\", (int) sizeof(struct sockaddr_un));
1070Sigor@sysoev.ru                      return 0;
1080Sigor@sysoev.ru                  }"
1090Sigor@sysoev.ru. auto/feature
1100Sigor@sysoev.ru
1110Sigor@sysoev.ru
1120Sigor@sysoev.runxt_feature="struct sockaddr_storage size"
1130Sigor@sysoev.runxt_feature_name=NXT_HAVE_SOCKADDR_STORAGE
1140Sigor@sysoev.runxt_feature_run=value
1150Sigor@sysoev.runxt_feature_incs=
1160Sigor@sysoev.runxt_feature_libs=
1170Sigor@sysoev.runxt_feature_test="#include <stdio.h>
1180Sigor@sysoev.ru                  #include <sys/socket.h>
1190Sigor@sysoev.ru
1200Sigor@sysoev.ru                  int main() {
1210Sigor@sysoev.ru                      printf(\"%d\", (int) sizeof(struct sockaddr_storage));
1220Sigor@sysoev.ru                      return 0;
1230Sigor@sysoev.ru                  }"
1240Sigor@sysoev.ru. auto/feature
1250Sigor@sysoev.ru
1260Sigor@sysoev.ru
1270Sigor@sysoev.runxt_feature="socketpair(AF_UNIX, SOCK_SEQPACKET)"
1280Sigor@sysoev.runxt_feature_name=NXT_HAVE_AF_UNIX_SOCK_SEQPACKET
1290Sigor@sysoev.runxt_feature_run=yes
1300Sigor@sysoev.runxt_feature_incs=
1310Sigor@sysoev.runxt_feature_libs=
1320Sigor@sysoev.runxt_feature_test="#include <stdio.h>
1330Sigor@sysoev.ru                  #include <sys/socket.h>
1340Sigor@sysoev.ru
1350Sigor@sysoev.ru                  int main() {
1360Sigor@sysoev.ru                      int  pair[2];
1370Sigor@sysoev.ru
1380Sigor@sysoev.ru                      if (socketpair(AF_UNIX, SOCK_SEQPACKET, 0, pair) != 0)
1390Sigor@sysoev.ru                          return 1;
1400Sigor@sysoev.ru                      return 0;
1410Sigor@sysoev.ru                  }"
1420Sigor@sysoev.ru. auto/feature
1430Sigor@sysoev.ru
1440Sigor@sysoev.ru
1450Sigor@sysoev.runxt_feature="struct msghdr.msg_control"
1460Sigor@sysoev.runxt_feature_name=NXT_HAVE_MSGHDR_MSG_CONTROL
1470Sigor@sysoev.runxt_feature_run=
1480Sigor@sysoev.runxt_feature_incs=
1490Sigor@sysoev.runxt_feature_libs=
1500Sigor@sysoev.runxt_feature_test="#include <stdio.h>
1510Sigor@sysoev.ru                  #include <sys/socket.h>
1520Sigor@sysoev.ru
1530Sigor@sysoev.ru                  int main() {
1540Sigor@sysoev.ru                      struct  msghdr  msg;
1550Sigor@sysoev.ru
1560Sigor@sysoev.ru                      printf(\"%d\", (int) sizeof(msg.msg_control));
1570Sigor@sysoev.ru                      return 0;
1580Sigor@sysoev.ru                  }"
1590Sigor@sysoev.ru. auto/feature
1600Sigor@sysoev.ru
1611996St.nateldemoura@f5.comif [ $nxt_found = no ]; then
1621996St.nateldemoura@f5.com    $echo
1631996St.nateldemoura@f5.com    $echo $0: error: no msghdr.msg_control struct member.
1641996St.nateldemoura@f5.com    $echo
1651996St.nateldemoura@f5.com    exit 1;
1661996St.nateldemoura@f5.comfi
1671996St.nateldemoura@f5.com
1681996St.nateldemoura@f5.com
169*2026Smax.romanov@nginx.comif [ $NXT_SYSTEM != DragonFly ]; then
170*2026Smax.romanov@nginx.com    nxt_feature="sockopt SO_PASSCRED"
171*2026Smax.romanov@nginx.com    nxt_feature_name=NXT_HAVE_SOCKOPT_SO_PASSCRED
1721996St.nateldemoura@f5.com    nxt_feature_run=
1731996St.nateldemoura@f5.com    nxt_feature_incs=
1741996St.nateldemoura@f5.com    nxt_feature_libs=
1751996St.nateldemoura@f5.com    nxt_feature_test="#define _GNU_SOURCE
1761996St.nateldemoura@f5.com                      #include <sys/socket.h>
1771996St.nateldemoura@f5.com
1781996St.nateldemoura@f5.com                      int main() {
179*2026Smax.romanov@nginx.com                          return SO_PASSCRED == 0;
180*2026Smax.romanov@nginx.com                      }"
181*2026Smax.romanov@nginx.com    . auto/feature
182*2026Smax.romanov@nginx.com
183*2026Smax.romanov@nginx.com
184*2026Smax.romanov@nginx.com    if [ $nxt_found = yes ]; then
185*2026Smax.romanov@nginx.com        nxt_feature="struct ucred"
186*2026Smax.romanov@nginx.com        nxt_feature_name=NXT_HAVE_UCRED
187*2026Smax.romanov@nginx.com        nxt_feature_run=
188*2026Smax.romanov@nginx.com        nxt_feature_incs=
189*2026Smax.romanov@nginx.com        nxt_feature_libs=
190*2026Smax.romanov@nginx.com        nxt_feature_test="#define _GNU_SOURCE
191*2026Smax.romanov@nginx.com                          #include <sys/socket.h>
192*2026Smax.romanov@nginx.com                          #include <sys/un.h>
193*2026Smax.romanov@nginx.com
194*2026Smax.romanov@nginx.com                          int main() {
195*2026Smax.romanov@nginx.com                              return sizeof(struct ucred);
196*2026Smax.romanov@nginx.com                          }"
197*2026Smax.romanov@nginx.com        . auto/feature
198*2026Smax.romanov@nginx.com    fi
199*2026Smax.romanov@nginx.com
200*2026Smax.romanov@nginx.com
201*2026Smax.romanov@nginx.com    nxt_feature="struct cmsgcred"
202*2026Smax.romanov@nginx.com    nxt_feature_name=NXT_HAVE_MSGHDR_CMSGCRED
203*2026Smax.romanov@nginx.com    nxt_feature_run=
204*2026Smax.romanov@nginx.com    nxt_feature_incs=
205*2026Smax.romanov@nginx.com    nxt_feature_libs=
206*2026Smax.romanov@nginx.com    nxt_feature_test="#define _GNU_SOURCE
207*2026Smax.romanov@nginx.com                      #include <sys/socket.h>
208*2026Smax.romanov@nginx.com
209*2026Smax.romanov@nginx.com                      int main() {
210*2026Smax.romanov@nginx.com                          return sizeof(struct cmsgcred);
2111996St.nateldemoura@f5.com                      }"
2121996St.nateldemoura@f5.com    . auto/feature
2131996St.nateldemoura@f5.comfi
2141996St.nateldemoura@f5.com
2151996St.nateldemoura@f5.com
2160Sigor@sysoev.runxt_feature="sys/filio.h"
2170Sigor@sysoev.runxt_feature_name=NXT_HAVE_SYS_FILIO_H
2180Sigor@sysoev.runxt_feature_run=
2190Sigor@sysoev.runxt_feature_incs=
2200Sigor@sysoev.runxt_feature_libs=
2210Sigor@sysoev.runxt_feature_test="#include <sys/filio.h>
2220Sigor@sysoev.ru
2230Sigor@sysoev.ru                  int main() {
2240Sigor@sysoev.ru                      return 0;
2250Sigor@sysoev.ru                  }"
2260Sigor@sysoev.ru. auto/feature
2270Sigor@sysoev.ru
2280Sigor@sysoev.ruif [ $nxt_found = yes ]; then
2290Sigor@sysoev.ru    NXT_SYS_FILIO_H="#include <sys/filio.h>"
2300Sigor@sysoev.ruelse
2310Sigor@sysoev.ru    NXT_SYS_FILIO_H=
2320Sigor@sysoev.rufi
2330Sigor@sysoev.ru
2340Sigor@sysoev.ru
2350Sigor@sysoev.runxt_feature="ioctl(FIONBIO)"
2360Sigor@sysoev.runxt_feature_name=NXT_HAVE_FIONBIO
2370Sigor@sysoev.runxt_feature_run=
2380Sigor@sysoev.runxt_feature_incs=
2390Sigor@sysoev.runxt_feature_libs=
2400Sigor@sysoev.runxt_feature_test="#include <unistd.h>
2410Sigor@sysoev.ru                  #include <sys/socket.h>
2420Sigor@sysoev.ru                  $NXT_SYS_FILIO_H
2430Sigor@sysoev.ru                  #include <sys/ioctl.h>
2440Sigor@sysoev.ru
2450Sigor@sysoev.ru                  int main() {
2460Sigor@sysoev.ru                      int  nb;
2470Sigor@sysoev.ru
2480Sigor@sysoev.ru                      nb = 0;
2490Sigor@sysoev.ru                      ioctl(-1, FIONBIO, &nb);
2500Sigor@sysoev.ru                      return 0;
2510Sigor@sysoev.ru                  }"
2520Sigor@sysoev.ru. auto/feature
2530Sigor@sysoev.ru
2540Sigor@sysoev.ru
2550Sigor@sysoev.ru# socket(SOCK_NONBLOCK), Linux 2.6.27/glibc 2.10, NetBSD 6.0, FreeBSD 9.2.
2560Sigor@sysoev.ru
2570Sigor@sysoev.runxt_feature="socket(SOCK_NONBLOCK)"
2580Sigor@sysoev.runxt_feature_name=NXT_HAVE_SOCK_NONBLOCK
2590Sigor@sysoev.runxt_feature_run=
2600Sigor@sysoev.runxt_feature_incs=
2610Sigor@sysoev.runxt_feature_libs=
2620Sigor@sysoev.runxt_feature_test="#define _GNU_SOURCE
2630Sigor@sysoev.ru                  #include <sys/socket.h>
2640Sigor@sysoev.ru
2650Sigor@sysoev.ru                  int main() {
2660Sigor@sysoev.ru                      socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, 0);
2670Sigor@sysoev.ru                      return 0;
2680Sigor@sysoev.ru                  }"
2690Sigor@sysoev.ru. auto/feature
2700Sigor@sysoev.ru
2710Sigor@sysoev.ru
2720Sigor@sysoev.ru# accept4(), Linux 2.6.28/glibc 2.10, NetBSD 6.0, FreeBSD 9.2.
2730Sigor@sysoev.ru
2740Sigor@sysoev.runxt_feature="accept4()"
2750Sigor@sysoev.runxt_feature_name=NXT_HAVE_ACCEPT4
2760Sigor@sysoev.runxt_feature_run=
2770Sigor@sysoev.runxt_feature_incs=
2780Sigor@sysoev.runxt_feature_libs=
2790Sigor@sysoev.runxt_feature_test="#define _GNU_SOURCE
2800Sigor@sysoev.ru                  #include <stdlib.h>
2810Sigor@sysoev.ru                  #include <sys/socket.h>
2820Sigor@sysoev.ru
2830Sigor@sysoev.ru                  int main() {
2840Sigor@sysoev.ru                      accept4(0, NULL, NULL, SOCK_NONBLOCK);
2850Sigor@sysoev.ru                      return 0;
2860Sigor@sysoev.ru                  }"
2870Sigor@sysoev.ru. auto/feature
288