diff options
author | milek7 <me@milek7.pl> | 2021-05-20 23:34:50 +0000 |
---|---|---|
committer | rubidium42 <rubidium42@users.noreply.github.com> | 2021-05-24 08:56:18 +0200 |
commit | 760727738083e6b6a23eb913ca149a1f80bc1596 (patch) | |
tree | c60cdefeb9bb2a492d4e32e7bb516fdb5e44dc42 /src/network/core | |
parent | 886f5c104a1853f1ece9e8ed834c6481dbcb550e (diff) | |
download | openttd-760727738083e6b6a23eb913ca149a1f80bc1596.tar.xz |
Fix: Network on Haiku, remove old code for BeOS
Diffstat (limited to 'src/network/core')
-rw-r--r-- | src/network/core/host.cpp | 67 | ||||
-rw-r--r-- | src/network/core/os_abstraction.h | 7 |
2 files changed, 8 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 */ |