2 dnl Macro: unet_NONBLOCKING
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.
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>
13 #include <sys/ioctl.h>
16 $ac_cv_type_signal alarmed() { exit(1); }
22 int f = socket(AF_INET, SOCK_DGRAM, 0);
23 if (f >= 0 && !(fcntl(f, F_SETFL, O_NONBLOCK)))
25 signal(SIGALRM, alarmed);
27 recvfrom(f, b, 12, 0, &x, &l);
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.])
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>
40 #include <sys/ioctl.h>
43 $ac_cv_type_signal alarmed() { exit(1); }
49 int f = socket(AF_INET, SOCK_DGRAM, 0);
50 if (f >= 0 && !(fcntl(f, F_SETFL, O_NDELAY)))
52 signal(SIGALRM, alarmed);
54 recvfrom(f, b, 12, 0, &x, &l);
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.])
63 AC_DEFINE([NBLOCK_SYSV],,[Define if you have SysV non-blocking sockets.])
68 dnl Macro: unet_SIGNALS
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.
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.])
83 AC_CACHE_CHECK([for bsd reliable signals], unet_cv_sys_signal_bsd,
84 [AC_TRY_RUN([#include <signal.h>
86 $ac_cv_type_signal handler()
90 kill(getpid(), SIGTERM);
95 signal(SIGTERM, handler);
96 kill(getpid(), SIGTERM);
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.])
102 AC_DEFINE([SYSV_UNRELIABLE_SIGNALS],,[Define if you have (unreliable) SysV signals.])
107 dnl Macro: unet_CHECK_TYPE_SIZES
109 dnl Check the size of several types and define a valid int16_t and int32_t.
111 AC_DEFUN([unet_CHECK_TYPE_SIZES],
112 [dnl Check type sizes
113 AC_CHECK_SIZEOF(short)
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)
126 AC_MSG_ERROR([Cannot find a type with size of 16 bits])
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)
138 AC_MSG_ERROR([Cannot find a type with size of 32 bits])
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)
147 AC_MSG_ERROR([Cannot find a type with size of 64 bits])
150 dnl Written by John Hawkinson <jhawk@mit.edu>. This code is in the Public
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
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.
166 dnl This test exists so that every application developer does not test this in
167 dnl a different, and subtly broken fashion.
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.
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).
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),
200 AC_CHECK_FUNC(socket, , AC_CHECK_LIB(socket, socket, ,
201 AC_CHECK_LIB(socket, socket, LIBS="-lsocket -lnsl $LIBS", , -lnsl)))