aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2016-08-18 15:55:50 +0200
committerKim Alvefur <zash@zash.se>2016-08-18 15:55:50 +0200
commita297b318cf661c57fbb54b0d5cc18f84d583db96 (patch)
tree2b50d4a4984da950fab9b61f8422aac06b8ff5ca /net
parentadf465bdfc3ce9b38c1fab0849f7d94c2faf3f58 (diff)
downloadprosody-a297b318cf661c57fbb54b0d5cc18f84d583db96.tar.gz
prosody-a297b318cf661c57fbb54b0d5cc18f84d583db96.zip
net.server_epoll: Collect and expose local and remote address and ports
Diffstat (limited to 'net')
-rw-r--r--net/server_epoll.lua30
1 files changed, 25 insertions, 5 deletions
diff --git a/net/server_epoll.lua b/net/server_epoll.lua
index 9b613c3f..d661d53a 100644
--- a/net/server_epoll.lua
+++ b/net/server_epoll.lua
@@ -114,11 +114,11 @@ local interface = {};
local interface_mt = { __index = interface };
function interface_mt:__tostring()
- if self.peer then
+ if self.peername then
if self.conn then
return ("%d %s [%s]:%d"):format(self:getfd(), tostring(self.conn), self.peer[1], self.peer[2]);
else
- return ("%d [%s]:%d"):format(self:getfd(), self.peer[1], self.peer[2]);
+ return ("%d [%s]:%d"):format(self:getfd(), self.peername, self.peerport);
end
end
return tostring(self:getfd());
@@ -147,7 +147,23 @@ function interface:getfd()
end
function interface:ip()
- return self.peer[1];
+ return self.peername or self.sockname;
+end
+
+function interface:port()
+ return self.sockport or self.peerport;
+end
+
+function interface:clientport()
+ return self.sockport;
+end
+
+function interface:serverport()
+ if self.sockport then
+ return self.sockport;
+ elseif self.server then
+ self.server:port();
+ end
end
function interface:socket()
@@ -396,7 +412,10 @@ local function wrapsocket(client, server, pattern, listeners, tls) -- luasocket
tls = tls;
}, interface_mt);
if client.getpeername then
- conn.peer = {client:getpeername()}
+ conn.peername, conn.peerport = client:getpeername();
+ end
+ if client.getsockname then
+ conn.sockname, conn.sockport = client:getsockname();
end
fds[conn:getfd()] = conn;
@@ -461,7 +480,8 @@ local function addserver(addr, port, listeners, pattern, tls)
_pattern = pattern;
onreadable = interface.onacceptable;
tls = tls;
- peer = { addr, port };
+ sockname = addr;
+ sockport = port;
}, interface_mt);
server:setflags(true, false);
fds[server:getfd()] = server;