]>
Commit | Line | Data |
---|---|---|
189935b1 | 1 | dnl |
2 | dnl Macro: unet_NONBLOCKING | |
3 | dnl | |
4 | dnl Check whether we have posix, bsd or sysv non-blocking sockets and | |
5 | dnl define respectively NBLOCK_POSIX, NBLOCK_BSD or NBLOCK_SYSV. | |
6 | dnl | |
7 | AC_DEFUN(unet_NONBLOCKING, | |
8 | [dnl Do we have posix, bsd or sysv non-blocking stuff ? | |
9 | AC_CACHE_CHECK([for posix non-blocking], unet_cv_sys_nonblocking_posix, | |
10 | [AC_TRY_RUN([#include <sys/types.h> | |
11 | #include <sys/socket.h> | |
12 | #include <fcntl.h> | |
13 | #include <sys/ioctl.h> | |
14 | #include <sys/file.h> | |
15 | #include <signal.h> | |
16 | $ac_cv_type_signal alarmed() { exit(1); } | |
17 | int main(void) | |
18 | { | |
19 | char b[12]; | |
20 | struct sockaddr x; | |
21 | size_t l = sizeof(x); | |
22 | int f = socket(AF_INET, SOCK_DGRAM, 0); | |
23 | if (f >= 0 && !(fcntl(f, F_SETFL, O_NONBLOCK))) | |
24 | { | |
25 | signal(SIGALRM, alarmed); | |
26 | alarm(2); | |
27 | recvfrom(f, b, 12, 0, &x, &l); | |
28 | alarm(0); | |
29 | exit(0); | |
30 | } | |
31 | exit(1); | |
32 | }], unet_cv_sys_nonblocking_posix=yes, unet_cv_sys_nonblocking_posix=no)]) | |
33 | if test $unet_cv_sys_nonblocking_posix = yes; then | |
34 | AC_DEFINE([NBLOCK_POSIX],,[Define if you have POSIX non-blocking sockets.]) | |
35 | else | |
36 | AC_CACHE_CHECK([for bsd non-blocking], unet_cv_sys_nonblocking_bsd, | |
37 | [AC_TRY_RUN([#include <sys/types.h> | |
38 | #include <sys/socket.h> | |
39 | #include <fcntl.h> | |
40 | #include <sys/ioctl.h> | |
41 | #include <sys/file.h> | |
42 | #include <signal.h> | |
43 | $ac_cv_type_signal alarmed() { exit(1); } | |
44 | int main(void) | |
45 | { | |
46 | char b[12]; | |
47 | struct sockaddr x; | |
48 | size_t l = sizeof(x); | |
49 | int f = socket(AF_INET, SOCK_DGRAM, 0); | |
50 | if (f >= 0 && !(fcntl(f, F_SETFL, O_NDELAY))) | |
51 | { | |
52 | signal(SIGALRM, alarmed); | |
53 | alarm(2); | |
54 | recvfrom(f, b, 12, 0, &x, &l); | |
55 | alarm(0); | |
56 | exit(0); | |
57 | } | |
58 | exit(1); | |
59 | }], unet_cv_sys_nonblocking_bsd=yes, unet_cv_sys_nonblocking_bsd=no)]) | |
60 | if test $unet_cv_sys_nonblocking_bsd = yes; then | |
61 | AC_DEFINE([NBLOCK_BSD],,[Define if you have BSD non-blocking sockets.]) | |
62 | else | |
63 | AC_DEFINE([NBLOCK_SYSV],,[Define if you have SysV non-blocking sockets.]) | |
64 | fi | |
65 | fi]) | |
66 | ||
67 | dnl | |
68 | dnl Macro: unet_SIGNALS | |
69 | dnl | |
70 | dnl Check if we have posix signals, reliable bsd signals or | |
71 | dnl unreliable sysv signals and define respectively POSIX_SIGNALS, | |
72 | dnl BSD_RELIABLE_SIGNALS or SYSV_UNRELIABLE_SIGNALS. | |
73 | dnl | |
74 | AC_DEFUN(unet_SIGNALS, | |
75 | [dnl Do we have posix signals, reliable bsd signals or unreliable sysv signals ? | |
76 | AC_CACHE_CHECK([for posix signals], unet_cv_sys_signal_posix, | |
77 | [AC_TRY_COMPILE([#include <signal.h>], | |
78 | [sigaction(SIGTERM, (struct sigaction *)0L, (struct sigaction *)0L)], | |
79 | unet_cv_sys_signal_posix=yes, unet_cv_sys_signal_posix=no)]) | |
80 | if test $unet_cv_sys_signal_posix = yes; then | |
81 | AC_DEFINE([POSIX_SIGNALS],,[Define if you have POSIX signals.]) | |
82 | else | |
83 | AC_CACHE_CHECK([for bsd reliable signals], unet_cv_sys_signal_bsd, | |
84 | [AC_TRY_RUN([#include <signal.h> | |
85 | int calls = 0; | |
86 | $ac_cv_type_signal handler() | |
87 | { | |
88 | if (calls) return; | |
89 | calls++; | |
90 | kill(getpid(), SIGTERM); | |
91 | sleep(1); | |
92 | } | |
93 | int main(void) | |
94 | { | |
95 | signal(SIGTERM, handler); | |
96 | kill(getpid(), SIGTERM); | |
97 | exit (0); | |
98 | }], unet_cv_sys_signal_bsd=yes, unet_cv_sys_signal_bsd=no)]) | |
99 | if test $unet_cv_sys_signal_bsd = yes; then | |
100 | AC_DEFINE([BSD_RELIABLE_SIGNALS],,[Define if you have (reliable) BSD signals.]) | |
101 | else | |
102 | AC_DEFINE([SYSV_UNRELIABLE_SIGNALS],,[Define if you have (unreliable) SysV signals.]) | |
103 | fi | |
104 | fi]) | |
105 | ||
106 | dnl | |
107 | dnl Macro: unet_CHECK_TYPE_SIZES | |
108 | dnl | |
109 | dnl Check the size of several types and define a valid int16_t and int32_t. | |
110 | dnl | |
111 | AC_DEFUN(unet_CHECK_TYPE_SIZES, | |
112 | [dnl Check type sizes | |
113 | AC_CHECK_SIZEOF(short) | |
114 | AC_CHECK_SIZEOF(int) | |
115 | AC_CHECK_SIZEOF(long) | |
116 | AC_CHECK_SIZEOF(void *) | |
117 | AC_CHECK_SIZEOF(int64_t) | |
118 | AC_CHECK_SIZEOF(long long) | |
119 | if test "$ac_cv_sizeof_int" = 2 ; then | |
120 | AC_CHECK_TYPE(int16_t, int) | |
121 | AC_CHECK_TYPE(uint16_t, unsigned int) | |
122 | elif test "$ac_cv_sizeof_short" = 2 ; then | |
123 | AC_CHECK_TYPE(int16_t, short) | |
124 | AC_CHECK_TYPE(uint16_t, unsigned short) | |
125 | else | |
126 | AC_MSG_ERROR([Cannot find a type with size of 16 bits]) | |
127 | fi | |
128 | if test "$ac_cv_sizeof_int" = 4 ; then | |
129 | AC_CHECK_TYPE(int32_t, int) | |
130 | AC_CHECK_TYPE(uint32_t, unsigned int) | |
131 | elif test "$ac_cv_sizeof_short" = 4 ; then | |
132 | AC_CHECK_TYPE(int32_t, short) | |
133 | AC_CHECK_TYPE(uint32_t, unsigned short) | |
134 | elif test "$ac_cv_sizeof_long" = 4 ; then | |
135 | AC_CHECK_TYPE(int32_t, long) | |
136 | AC_CHECK_TYPE(uint32_t, unsigned long) | |
137 | else | |
138 | AC_MSG_ERROR([Cannot find a type with size of 32 bits]) | |
139 | fi | |
140 | if test "$ac_cv_sizeof_int64_t" = 8 ; then | |
141 | AC_CHECK_TYPE(int64_t) | |
142 | AC_CHECK_TYPE(uint64_t) | |
143 | elif test "$ac_cv_sizeof_long_long" = 8 ; then | |
144 | AC_CHECK_TYPE(int64_t, long long) | |
145 | AC_CHECK_TYPE(uint64_t, unsigned long long) | |
146 | else | |
147 | AC_MSG_ERROR([Cannot find a type with size of 64 bits]) | |
148 | fi]) | |
149 | ||
150 | dnl Written by John Hawkinson <jhawk@mit.edu>. This code is in the Public | |
151 | dnl Domain. | |
152 | dnl | |
153 | dnl This test is for network applications that need socket() and | |
154 | dnl gethostbyname() -ish functions. Under Solaris, those applications need to | |
155 | dnl link with "-lsocket -lnsl". Under IRIX, they should *not* link with | |
156 | dnl "-lsocket" because libsocket.a breaks a number of things (for instance: | |
157 | dnl gethostbyname() under IRIX 5.2, and snoop sockets under most versions of | |
158 | dnl IRIX). | |
159 | dnl | |
160 | dnl Unfortunately, many application developers are not aware of this, and | |
161 | dnl mistakenly write tests that cause -lsocket to be used under IRIX. It is | |
162 | dnl also easy to write tests that cause -lnsl to be used under operating | |
163 | dnl systems where neither are necessary (or useful), such as SunOS 4.1.4, which | |
164 | dnl uses -lnsl for TLI. | |
165 | dnl | |
166 | dnl This test exists so that every application developer does not test this in | |
167 | dnl a different, and subtly broken fashion. | |
168 | dnl | |
169 | dnl It has been argued that this test should be broken up into two seperate | |
170 | dnl tests, one for the resolver libraries, and one for the libraries necessary | |
171 | dnl for using Sockets API. Unfortunately, the two are carefully intertwined and | |
172 | dnl allowing the autoconf user to use them independantly potentially results in | |
173 | dnl unfortunate ordering dependancies -- as such, such component macros would | |
174 | dnl have to carefully use indirection and be aware if the other components were | |
175 | dnl executed. Since other autoconf macros do not go to this trouble, and almost | |
176 | dnl no applications use sockets without the resolver, this complexity has not | |
177 | dnl been implemented. | |
178 | dnl | |
179 | dnl The check for libresolv is in case you are attempting to link statically | |
180 | dnl and happen to have a libresolv.a lying around (and no libnsl.a). | |
181 | dnl | |
182 | AC_DEFUN(AC_LIBRARY_NET, [ | |
183 | # Most operating systems have gethostbyname() in the default searched | |
184 | # libraries (i.e. libc): | |
185 | AC_CHECK_FUNC(gethostbyname, , | |
186 | # Some OSes (eg. Solaris) place it in libnsl: | |
187 | AC_CHECK_LIB(nsl, gethostbyname, , | |
188 | # Some strange OSes (SINIX) have it in libsocket: | |
189 | AC_CHECK_LIB(socket, gethostbyname, , | |
190 | # Unfortunately libsocket sometimes depends on libnsl. | |
191 | # AC_CHECK_LIB's API is essentially broken so the following | |
192 | # ugliness is necessary: | |
193 | AC_CHECK_LIB(socket, gethostbyname, | |
194 | LIBS="-lsocket -lnsl $LIBS", | |
195 | AC_CHECK_LIB(resolv, gethostbyname), | |
196 | -lnsl) | |
197 | ) | |
198 | ) | |
199 | ) | |
200 | AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket, , | |
201 | AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl))) | |
202 | ]) |