From 5db32d1dc599fad0f688d6e1f73cdae5ba660922 Mon Sep 17 00:00:00 2001 From: rubidium Date: Fri, 24 Apr 2009 10:33:16 +0000 Subject: (svn r16134) -Change: do not add duplicates to the broadcast list --- src/network/core/address.h | 9 +++++++++ src/network/core/host.cpp | 12 ++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'src/network/core') diff --git a/src/network/core/address.h b/src/network/core/address.h index 863c43427..ecf6efa60 100644 --- a/src/network/core/address.h +++ b/src/network/core/address.h @@ -207,6 +207,15 @@ public: { return const_cast(this)->CompareTo(address) == 0; } + /** + * Compare the address of this class with the address of another. + * @param address the other address. + * @return true if both do not match. + */ + bool operator != (NetworkAddress address) const + { + return const_cast(this)->CompareTo(address) != 0; + } /** * Compare the address of this class with the address of another. diff --git a/src/network/core/host.cpp b/src/network/core/host.cpp index 7b7f22784..917de0a2f 100644 --- a/src/network/core/host.cpp +++ b/src/network/core/host.cpp @@ -76,7 +76,8 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // BE sockaddr_storage address; memset(&address, 0, sizeof(address)); ((sockaddr_in*)&address)->sin_addr.s_addr = htonl(ip | ~netmask); - *broadcast->Append() = NetworkAddress(address, sizeof(sockaddr)); + NetworkAddress addr(address, sizeof(sockaddr)); + if (!broadcast->Contains(addr)) *broadcast->Append() = addr; index++; } if (read < 0) { @@ -100,7 +101,8 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // GE if (ifa->ifa_broadaddr == NULL) continue; if (ifa->ifa_broadaddr->sa_family != AF_INET) continue; - *broadcast->Append() = NetworkAddress(ifa->ifa_broadaddr, sizeof(sockaddr)); + NetworkAddress addr(ifa->ifa_broadaddr, sizeof(sockaddr)); + if (!broadcast->Contains(addr)) *broadcast->Append() = addr; } freeifaddrs(ifap); } @@ -135,7 +137,8 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // Wi /* iiBroadcast is unusable, because it always seems to be set to 255.255.255.255. */ memcpy(&address, &ifo[j].iiAddress.Address, sizeof(sockaddr)); ((sockaddr_in*)&address)->sin_addr.s_addr = ifo[j].iiAddress.AddressIn.sin_addr.s_addr | ~ifo[j].iiNetmask.AddressIn.sin_addr.s_addr; - *broadcast->Append() = NetworkAddress(address, sizeof(sockaddr)); + NetworkAddress addr(address, sizeof(sockaddr)); + if (!broadcast->Contains(addr)) *broadcast->Append() = addr; } free(ifo); @@ -172,7 +175,8 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // !G if (ioctl(sock, SIOCGIFFLAGS, &r) != -1 && r.ifr_flags & IFF_BROADCAST && ioctl(sock, SIOCGIFBRDADDR, &r) != -1) { - *broadcast->Append() = NetworkAddress(&r.ifr_broadaddr, sizeof(sockaddr)); + NetworkAddress addr(&r.ifr_broadaddr, sizeof(sockaddr)); + if (!broadcast->Contains(addr)) *broadcast->Append() = addr; } } -- cgit v1.2.3-70-g09d2