From aab65a27287e8052ec96b9c0390849cb5e948308 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Mon, 29 Sep 2014 14:42:42 +0800 Subject: [PATCH] socket accept report addr:port --- examples/watchdog.lua | 1 + skynet-src/socket_server.c | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/watchdog.lua b/examples/watchdog.lua index f37de5bf..eaedd5db 100644 --- a/examples/watchdog.lua +++ b/examples/watchdog.lua @@ -10,6 +10,7 @@ local gate local agent = {} function SOCKET.open(fd, addr) + skynet.error("New client from : " .. addr) agent[fd] = skynet.newservice("agent") skynet.call(agent[fd], "lua", "start", gate, fd, proto) end diff --git a/skynet-src/socket_server.c b/skynet-src/socket_server.c index e1df3f67..11ba4b0b 100644 --- a/skynet-src/socket_server.c +++ b/skynet-src/socket_server.c @@ -831,7 +831,10 @@ report_accept(struct socket_server *ss, struct socket *s, struct socket_message result->data = NULL; void * sin_addr = (u.s.sa_family == AF_INET) ? (void*)&u.v4.sin_addr : (void *)&u.v6.sin6_addr; - if (inet_ntop(u.s.sa_family, sin_addr, ss->buffer, sizeof(ss->buffer))) { + int sin_port = ntohs((u.s.sa_family == AF_INET) ? u.v4.sin_port : u.v6.sin6_port); + char tmp[INET6_ADDRSTRLEN]; + if (inet_ntop(u.s.sa_family, sin_addr, tmp, sizeof(tmp))) { + snprintf(ss->buffer, sizeof(ss->buffer), "%s:%d", tmp, sin_port); result->data = ss->buffer; }