From c7cdb67a8aaab46944ae2a9f70b68d79f99a24ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 14 Jun 2007 16:54:04 +0000 Subject: [PATCH] NetAddress::IsLocal() did not work under BONE - we now work around this by using the route table to determine if an address is local or not (BONE incorrectly allows you to bind against non-existing and non-local interfaces). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21412 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../r5/src/test/netfs/shared/NetAddress.cpp | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/tests/add-ons/kernel/file_systems/userlandfs/r5/src/test/netfs/shared/NetAddress.cpp b/src/tests/add-ons/kernel/file_systems/userlandfs/r5/src/test/netfs/shared/NetAddress.cpp index 8089d2a08f..a3ac10f433 100644 --- a/src/tests/add-ons/kernel/file_systems/userlandfs/r5/src/test/netfs/shared/NetAddress.cpp +++ b/src/tests/add-ons/kernel/file_systems/userlandfs/r5/src/test/netfs/shared/NetAddress.cpp @@ -5,6 +5,12 @@ #include #include +#if defined(HAIKU_TARGET_PLATFORM_DANO) || defined(HAIKU_TARGET_PLATFORM_DANO) +# include +# include +# include +#endif + #include "AutoLocker.h" #include "Compatibility.h" #include "Locker.h" @@ -87,11 +93,42 @@ NetAddress::IsLocal() const int fd = socket(AF_INET, SOCK_STREAM, 0); if (fd < 0) return false; +#if defined(HAIKU_TARGET_PLATFORM_DANO) || defined(HAIKU_TARGET_PLATFORM_DANO) + // BONE does allow you to bind to any address! + // Therefore, we iterate over all routes, and see if there are any local + // ones for this address. + + bool result = false; + uint32 count; + if (ioctl(fd, SIOCGRTSIZE, &count) == 0) { + route_req_t* routes = (route_req_t*)malloc(count * sizeof(route_req_t)); + if (routes != NULL) { + route_table_req table; + table.rrtp = routes; + table.len = count * sizeof(route_req_t); + table.cnt = count; + if (ioctl(fd, SIOCGRTTABLE, &table) == 0) { + for (uint32 i = 0; i < table.cnt; i++) { + if ((routes[i].flags & RTF_LOCAL) == 0) + continue; + if (((sockaddr_in*)&routes[i].dst)->sin_addr.s_addr + == fAddress.sin_addr.s_addr) { + result = true; + break; + } + } + } + free(routes); + } + } +#else // bind it to a port sockaddr_in addr = fAddress; addr.sin_port = 0; bool result = (bind(fd, (sockaddr*)&addr, sizeof(addr)) == 0); +#endif closesocket(fd); + return result; }