Getting the remote socket address

82 views
Skip to first unread message

kiubiq

unread,
Jan 28, 2013, 8:49:40 AM1/28/13
to lu...@googlegroups.com
Is there a way to get the remote address from a socket?
Looking at the documentation it should be something like this:

local http = require("http")

http.createServer(function (req, res)
  p(req.socket:remoteAddress())
end):listen(8080)

Tim Caswell

unread,
Jan 28, 2013, 9:13:53 AM1/28/13
to lu...@googlegroups.com
At the C level I bind getsockname and getpeername.  https://github.com/luvit/luvit/blob/master/src/luv_tcp.c#L86-L156

In the net library which the http library uses there doesn't appear to be an alias for :remoteAddress(), but you can get at the uv API via the private socket._handle property. https://github.com/luvit/luvit/blob/master/lib/luvit/net.lua#L264

as _handle:getpeername() _handle:getsockname()  https://github.com/luvit/luvit/blob/master/lib/luvit/uv.lua#L144-L148



--
You received this message because you are subscribed to the Google Groups "luvit" group.
To unsubscribe from this group, send email to luvit+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Michael Eisendle

unread,
Jan 28, 2013, 9:18:52 AM1/28/13
to lu...@googlegroups.com
It works now, thank you :)


2013/1/28 Tim Caswell <t...@creationix.com>
To unsubscribe from this group and stop receiving emails from it, send an email to luvit+un...@googlegroups.com.

Brandon Philips

unread,
Jan 28, 2013, 9:22:17 AM1/28/13
to lu...@googlegroups.com
On Mon, Jan 28, 2013 at 6:13 AM, Tim Caswell <t...@creationix.com> wrote:
> In the net library which the http library uses there doesn't appear to be an
> alias for :remoteAddress(),

We try to make it property on the Socket object but it is always nil AFAICS:

https://github.com/luvit/luvit/blob/master/lib/luvit/net.lua#L42

We even try to test it in the tls library but I suspect it is just nil:

https://github.com/luvit/luvit/blob/master/tests/test-tls-remote.lua#L29
Reply all
Reply to author
Forward
0 new messages