summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-04-24 10:33:16 +0000
committerrubidium <rubidium@openttd.org>2009-04-24 10:33:16 +0000
commit5db32d1dc599fad0f688d6e1f73cdae5ba660922 (patch)
tree0b556c14559ae92d15c6599e0516bca42e2cbe62 /src/network
parentd21f406b038f9514c4180ff2ab16f2f9db91afb4 (diff)
downloadopenttd-5db32d1dc599fad0f688d6e1f73cdae5ba660922.tar.xz
(svn r16134) -Change: do not add duplicates to the broadcast list
Diffstat (limited to 'src/network')
-rw-r--r--src/network/core/address.h9
-rw-r--r--src/network/core/host.cpp12
2 files changed, 17 insertions, 4 deletions
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<NetworkAddress*>(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<NetworkAddress*>(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;
}
}