summaryrefslogtreecommitdiff
path: root/idle.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2020-06-12 01:19:20 +0200
committerDavid Härdeman <david@hardeman.nu>2020-06-12 01:19:20 +0200
commit4492ad9328e59edc4c8d3db8cd881941b7903741 (patch)
tree11220e4d521ee41b4c0ae9e4056b22c90a6f0f07 /idle.c
parent0894b8f5c0b18b7fbbfe505bf8291495c74a3f08 (diff)
Send real hostname and port in idle check
Diffstat (limited to 'idle.c')
-rw-r--r--idle.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/idle.c b/idle.c
index e1a73ea..0607a61 100644
--- a/idle.c
+++ b/idle.c
@@ -287,7 +287,8 @@ idle_check_connected_cb(struct cfg *cfg, struct connection *conn, bool connected
char buf[1024];
char *pos;
char *cmdbuf = idle->tbuf.buf;
- uint16_t port = 25565;
+ uint16_t port;
+ char hostname[INET6_ADDRSTRLEN];
if (!connected) {
fprintf(stderr, "%s: idle check connection to remote server failed\n",
@@ -298,11 +299,14 @@ idle_check_connected_cb(struct cfg *cfg, struct connection *conn, bool connected
fprintf(stderr, "%s: connected to remote %s\n", __func__, idle->conn.remotestr);
+ port = sockaddr_port(&conn->remote);
+ sockaddr_addr(&conn->remote, hostname, sizeof(hostname));
+
pos = buf;
write_byte(&pos, MC_HELO);
write_varint(&pos, -1); /* Protocol version, -1 = undefined */
- write_varint(&pos, strlen("hostname"));
- write_str(&pos, "hostname");
+ write_varint(&pos, strlen(hostname));
+ write_str(&pos, hostname);
write_byte(&pos, (port >> 8) & 0xff);
write_byte(&pos, (port >> 0) & 0xff);
write_byte(&pos, MC_NEXT_STATE_STATUS);