diff options
-rw-r--r-- | src/network/core/host.cpp | 67 | ||||
-rw-r--r-- | src/network/core/os_abstraction.h | 7 | ||||
-rw-r--r-- | src/stdafx.h | 1 |
3 files changed, 9 insertions, 66 deletions
diff --git a/src/network/core/host.cpp b/src/network/core/host.cpp index 54a97aff0..4ff77a141 100644 --- a/src/network/core/host.cpp +++ b/src/network/core/host.cpp @@ -20,72 +20,7 @@ */ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast); -#if defined(__HAIKU__) /* doesn't have neither getifaddrs or net/if.h */ -/* Based on Andrew Bachmann's netstat+.c. Big thanks to him! */ -extern "C" int _netstat(int fd, char **output, int verbose); - -int seek_past_header(char **pos, const char *header) -{ - char *new_pos = strstr(*pos, header); - if (new_pos == 0) { - return B_ERROR; - } - *pos += strlen(header) + new_pos - *pos + 1; - return B_OK; -} - -static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // BEOS implementation -{ - int sock = socket(AF_INET, SOCK_DGRAM, 0); - - if (sock < 0) { - DEBUG(net, 0, "Could not create socket: %s", NetworkError::GetLast().AsString()); - return; - } - - char *output_pointer = nullptr; - int output_length = _netstat(sock, &output_pointer, 1); - if (output_length < 0) { - DEBUG(net, 0, "Error running _netstat()"); - return; - } - - char **output = &output_pointer; - if (seek_past_header(output, "IP Interfaces:") == B_OK) { - for (;;) { - uint32 n; - int fields, read; - uint8 i1, i2, i3, i4, j1, j2, j3, j4; - uint32 ip; - uint32 netmask; - - fields = sscanf(*output, "%u: %hhu.%hhu.%hhu.%hhu, netmask %hhu.%hhu.%hhu.%hhu%n", - &n, &i1, &i2, &i3, &i4, &j1, &j2, &j3, &j4, &read); - read += 1; - if (fields != 9) { - break; - } - - ip = (uint32)i1 << 24 | (uint32)i2 << 16 | (uint32)i3 << 8 | (uint32)i4; - netmask = (uint32)j1 << 24 | (uint32)j2 << 16 | (uint32)j3 << 8 | (uint32)j4; - - if (ip != INADDR_LOOPBACK && ip != INADDR_ANY) { - sockaddr_storage address; - memset(&address, 0, sizeof(address)); - ((sockaddr_in*)&address)->sin_addr.s_addr = htonl(ip | ~netmask); - NetworkAddress addr(address, sizeof(sockaddr)); - if (std::none_of(broadcast->begin(), broadcast->end(), [&addr](NetworkAddress const& elem) -> bool { return elem == addr; })) broadcast->push_back(addr); - } - if (read < 0) { - break; - } - *output += read; - } - closesocket(sock); - } -} - -#elif defined(HAVE_GETIFADDRS) +#if defined(HAVE_GETIFADDRS) static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // GETIFADDRS implementation { struct ifaddrs *ifap, *ifa; diff --git a/src/network/core/os_abstraction.h b/src/network/core/os_abstraction.h index 55d733501..8cf820255 100644 --- a/src/network/core/os_abstraction.h +++ b/src/network/core/os_abstraction.h @@ -108,6 +108,13 @@ typedef unsigned long in_addr_t; # undef FD_SETSIZE # define FD_SETSIZE 64 # endif + +/* Haiku says it supports FD_SETSIZE fds, but it really only supports 512. */ +# if defined(__HAIKU__) +# undef FD_SETSIZE +# define FD_SETSIZE 512 +# endif + #endif /* UNIX */ /* OS/2 stuff */ diff --git a/src/stdafx.h b/src/stdafx.h index 319d94edf..78188f8fa 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -33,6 +33,7 @@ #if defined(__HAIKU__) # include <SupportDefs.h> # include <unistd.h> +# define _DEFAULT_SOURCE # define _GNU_SOURCE # define TROUBLED_INTS #endif |