summaryrefslogtreecommitdiff
path: root/src/network/core/udp.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-04-03 01:24:52 +0000
committerrubidium <rubidium@openttd.org>2009-04-03 01:24:52 +0000
commit632d74c6b1a17f3bc3419158dfc1bb5a2e5f77b5 (patch)
tree3d2dcf19488a31930bdb82d46f8ddc4b53aba59a /src/network/core/udp.cpp
parentba5aafb9bba4887b502dba32e56747fe10af604e (diff)
downloadopenttd-632d74c6b1a17f3bc3419158dfc1bb5a2e5f77b5.tar.xz
(svn r15922) -Codechange: unify the ways to listen on a socket
Diffstat (limited to 'src/network/core/udp.cpp')
-rw-r--r--src/network/core/udp.cpp29
1 files changed, 5 insertions, 24 deletions
diff --git a/src/network/core/udp.cpp b/src/network/core/udp.cpp
index 4818767d9..473d438ea 100644
--- a/src/network/core/udp.cpp
+++ b/src/network/core/udp.cpp
@@ -17,45 +17,26 @@
/**
* Start listening on the given host and port.
- * @param host the host (ip) to listen on
- * @param port the port to listen on
+ * @param address the host to listen on
* @param broadcast whether to allow broadcast sending/receiving
* @return true if the listening succeeded
*/
-bool NetworkUDPSocketHandler::Listen(const uint32 host, const uint16 port, const bool broadcast)
+bool NetworkUDPSocketHandler::Listen(NetworkAddress address, bool broadcast)
{
- struct sockaddr_in sin;
-
/* Make sure socket is closed */
this->Close();
- this->sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
- if (!this->IsConnected()) {
- DEBUG(net, 0, "[udp] failed to start UDP listener");
- return false;
- }
-
- SetNonBlocking(this->sock);
-
- sin.sin_family = AF_INET;
- /* Listen on all IPs */
- sin.sin_addr.s_addr = host;
- sin.sin_port = htons(port);
-
- if (bind(this->sock, (struct sockaddr*)&sin, sizeof(sin)) != 0) {
- DEBUG(net, 0, "[udp] bind failed on %s:%i", inet_ntoa(*(struct in_addr *)&host), port);
- return false;
- }
+ this->sock = address.Listen(AF_INET, SOCK_DGRAM);
if (broadcast) {
/* Enable broadcast */
unsigned long val = 1;
#ifndef BEOS_NET_SERVER /* will work around this, some day; maybe. */
- setsockopt(this->sock, SOL_SOCKET, SO_BROADCAST, (char *) &val , sizeof(val));
+ setsockopt(this->sock, SOL_SOCKET, SO_BROADCAST, (char *) &val, sizeof(val));
#endif
}
- DEBUG(net, 1, "[udp] listening on port %s:%d", inet_ntoa(*(struct in_addr *)&host), port);
+ DEBUG(net, 1, "[udp] listening on port %s", address.GetAddressAsString());
return true;
}