summaryrefslogtreecommitdiff
path: root/src/network/network.cpp
diff options
context:
space:
mode:
authortruelight <truelight@openttd.org>2007-02-08 12:27:53 +0000
committertruelight <truelight@openttd.org>2007-02-08 12:27:53 +0000
commitc46a1cc2f685b4351b429b382a28a468fbf2c623 (patch)
tree18108e9e6f3d116f39e99f84eb6540da848e01cf /src/network/network.cpp
parent2a7682be799ed35b6a63373be232332657b262da (diff)
downloadopenttd-c46a1cc2f685b4351b429b382a28a468fbf2c623.tar.xz
(svn r8631) -Add: added parameter -l ip[:port] to ./openttd, which redirects DEBUG() to a remote connection over TCP
For example, launch on 192.168.0.1 with, say, netcat a listener: netcat -l -p 3982 Launch OpenTTD on a remote host (say, PSP): ./openttd -l 192.168.0.1 -d9 And you get all debug information on 192.168.0.1. Very useful for debugging Portable systems.
Diffstat (limited to 'src/network/network.cpp')
-rw-r--r--src/network/network.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp
index 76a29f3af..1ea36b50e 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -1317,6 +1317,37 @@ static void NetworkGenerateUniqueId(void)
snprintf(_network_unique_id, sizeof(_network_unique_id), "%s", hex_output);
}
+void NetworkStartDebugLog(const char *hostname, uint16 port)
+{
+ extern SOCKET _debug_socket; // Comes from debug.c
+ SOCKET s;
+ struct sockaddr_in sin;
+
+ DEBUG(net, 0, "Redirecting DEBUG() to %s:%d", hostname, port);
+
+ s = socket(AF_INET, SOCK_STREAM, 0);
+ if (s == INVALID_SOCKET) {
+ DEBUG(net, 0, "Failed to open socket for redirection DEBUG()");
+ return;
+ }
+
+ if (!SetNoDelay(s)) DEBUG(net, 1, "Setting TCP_NODELAY failed");
+
+ sin.sin_family = AF_INET;
+ sin.sin_addr.s_addr = NetworkResolveHost(hostname);
+ sin.sin_port = htons(port);
+
+ if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) != 0) {
+ DEBUG(net, 0, "Failed to redirection DEBUG() to %s:%d", hostname, port);
+ return;
+ }
+
+ if (!SetNonBlocking(s)) DEBUG(net, 0, "Setting non-blocking mode failed");
+ _debug_socket = s;
+
+ DEBUG(net, 0, "DEBUG() is now redirected");
+}
+
/** This tries to launch the network for a given OS */
void NetworkStartUp(void)
{