From bf41851bd9eb764309e1fdf89000949ff0bef4b9 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 18 Aug 2012 22:02:02 +0900 Subject: [PATCH] Check for ioctl availability. This gets networking compiling. Now the build gets all the way to qfcc, where it dies with waidpid/execvp errors :P --- config.d/library_functions.m4 | 6 +++--- libs/net/nc/net_udp.c | 13 ++++++++++--- libs/net/nm/net_udp.c | 20 ++++++++++++++++---- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/config.d/library_functions.m4 b/config.d/library_functions.m4 index 26d1ee5c1..d8a1ba257 100644 --- a/config.d/library_functions.m4 +++ b/config.d/library_functions.m4 @@ -11,9 +11,9 @@ AC_FUNC_VA_COPY AC_FUNC__VA_COPY AC_CHECK_FUNCS( access _access gethostname gethostbyname connect gettimeofday getuid \ - getwd mkdir _mkdir ftime _ftime fcntl stat putenv select socket strerror \ - strcasestr strnlen strstr snprintf _snprintf vsnprintf _vsnprintf \ - strsep dlopen getaddrinfo getnameinfo mprotect getpagesize + getwd ioctl mkdir _mkdir ftime _ftime fcntl stat putenv select socket \ + strerror strcasestr strnlen strstr snprintf _snprintf vsnprintf \ + _vsnprintf strsep dlopen getaddrinfo getnameinfo mprotect getpagesize ) DL_LIBS="" diff --git a/libs/net/nc/net_udp.c b/libs/net/nc/net_udp.c index 2d4874506..b28c88b75 100644 --- a/libs/net/nc/net_udp.c +++ b/libs/net/nc/net_udp.c @@ -344,17 +344,24 @@ UDP_OpenSocket (int port) #ifdef _WIN32 #define ioctl ioctlsocket - unsigned long _true = true; + unsigned long flags; #else - int _true = 1; + int flags; #endif memset (&address, 0, sizeof(address)); if ((newsocket = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) Sys_Error ("UDP_OpenSocket: socket: %s", strerror (errno)); - if (ioctl (newsocket, FIONBIO, &_true) == -1) +#if defined (HAVE_IOCTL) || defined (_WIN32) + flags = 1; + if (ioctl (newsocket, FIONBIO, &flags) == -1) Sys_Error ("UDP_OpenSocket: ioctl FIONBIO: %s", strerror (errno)); +#else + flags = fcntl(newsocket, F_GETFL, 0); + if (fcntl (newsocket, F_SETFL, flags | O_NONBLOCK) == -1) + Sys_Error ("UDP_OpenSocket: fcntl O_NONBLOCK: %s", strerror (errno)); +#endif address.s4.sin_family = AF_INET; // ZOID -- check for interface binding option if ((i = COM_CheckParm ("-ip")) != 0 && i < com_argc) { diff --git a/libs/net/nm/net_udp.c b/libs/net/nm/net_udp.c index f3fe79570..7b4a2bebb 100644 --- a/libs/net/nm/net_udp.c +++ b/libs/net/nm/net_udp.c @@ -311,9 +311,9 @@ UDP_OpenSocket (int port) struct sockaddr_in address; #ifdef _WIN32 #define ioctl ioctlsocket - unsigned long _true = true; + unsigned long flags; #else - int _true = true; + int flags; #endif #ifdef HAVE_IN_PKTINFO int ip_pktinfo = 1; @@ -322,8 +322,15 @@ UDP_OpenSocket (int port) if ((newsocket = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) return -1; - if (ioctl (newsocket, FIONBIO, &_true) == -1) +#if defined (HAVE_IOCTL) || defined (_WIN32) + flags = 1; + if (ioctl (newsocket, FIONBIO, &flags) == -1) goto ErrorReturn; +#else + flags = fcntl (newsocket, F_GETFL, 0); + if (fcntl (newsocket, F_SETFL, flags | O_NONBLOCK) == -1) + goto ErrorReturn; +#endif #ifdef HAVE_IN_PKTINFO if (setsockopt (newsocket, SOL_IP, IP_PKTINFO, &ip_pktinfo, sizeof (ip_pktinfo)) == -1) { @@ -425,14 +432,16 @@ UDP_Connect (int socket, netadr_t *addr) int UDP_CheckNewConnections (void) { +#if defined (HAVE_IOCTL) || defined (_WIN32) int available; AF_address_t from; socklen_t fromlen = sizeof (from); char buff[1]; +#endif if (net_acceptsocket == -1) return -1; - +#if defined (HAVE_IOCTL) || defined (_WIN32) if (ioctl (net_acceptsocket, FIONREAD, &available) == -1) Sys_Error ("UDP: ioctlsocket (FIONREAD) failed"); if (available) @@ -443,6 +452,9 @@ UDP_CheckNewConnections (void) // we don't care about the interface on which the packet arrived recvfrom (net_acceptsocket, buff, 0, 0, &from.sa, &fromlen); return -1; +#else + return net_acceptsocket; +#endif } int