diff options
author | rubidium <rubidium@openttd.org> | 2009-04-08 00:26:49 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-04-08 00:26:49 +0000 |
commit | 1eb4aa971ea329f18dd77b58bf7fc84d6240ea57 (patch) | |
tree | 1ad07f3d117ba228cdefef45c50d0fbc2baeed17 /src/network/core/udp.cpp | |
parent | d466fa96727cdf0087367cb40dcba286ecec1878 (diff) | |
download | openttd-1eb4aa971ea329f18dd77b58bf7fc84d6240ea57.tar.xz |
(svn r15975) -Codechange: register each of the IPs we have bound to to the masterserver
Diffstat (limited to 'src/network/core/udp.cpp')
-rw-r--r-- | src/network/core/udp.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp index 4a5570002..9fd58eb8d 100644 --- a/src/network/core/udp.cpp +++ b/src/network/core/udp.cpp @@ -26,6 +26,9 @@ NetworkUDPSocketHandler::NetworkUDPSocketHandler(NetworkAddressList *bind) *this->bind.Append() = *addr; } } else { + /* As hostname NULL and port 0/NULL don't go well when + * resolving it we need to add an address for each of + * the address families we support. */ *this->bind.Append() = NetworkAddress(NULL, 0, AF_INET); } } @@ -76,8 +79,12 @@ void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool a if (this->sockets.Length() == 0) this->Listen(); for (SocketList::iterator s = this->sockets.Begin(); s != this->sockets.End(); s++) { + /* Make a local copy because if we resolve it we cannot + * easily unresolve it so we can resolve it later again. */ + NetworkAddress send(*recv); + /* Not the same type */ - if (s->first.GetAddress()->ss_family != recv->GetAddress()->ss_family) continue; + if (!send.IsFamily(s->first.GetAddress()->ss_family)) continue; p->PrepareToSend(); @@ -90,10 +97,11 @@ void NetworkUDPSocketHandler::SendPacket(Packet *p, NetworkAddress *recv, bool a #endif /* Send the buffer */ - int res = sendto(s->second, (const char*)p->buffer, p->size, 0, (struct sockaddr *)recv->GetAddress(), recv->GetAddressLength()); + int res = sendto(s->second, (const char*)p->buffer, p->size, 0, (struct sockaddr *)send.GetAddress(), send.GetAddressLength()); + DEBUG(net, 7, "[udp] sendto(%s)", send.GetAddressAsString()); /* Check for any errors, but ignore it otherwise */ - if (res == -1) DEBUG(net, 1, "[udp] sendto(%s) failed with: %i", recv->GetAddressAsString(), GET_LAST_ERROR()); + if (res == -1) DEBUG(net, 1, "[udp] sendto(%s) failed with: %i", send.GetAddressAsString(), GET_LAST_ERROR()); if (!all) break; } |