Re: Getting multiple IP addresses using luasocket
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: Getting multiple IP addresses using luasocket
- From: Oliver Kroth <oliver.kroth@...>
- Date: 2014年1月13日 13:15:23 +0100
Hi Paul,
socket.dns.toip() calls internally something like gethostbyname, which
returns a pointer to a struct hostent.
This may (depending on OS) inlcude a list of other IP addresses for the
same name.
From this structure, the socket library's function inet_pushresolved()
creates a Lua table like
{
name="hostname";
alias={"hostname"; "othename"}
ip={"192.168.0.1"; "172.0.16.1"};
}
If you don't get this, you may have to change something in the socket
library's sources, or in your OS :-)
Oliver
Am 12.01.2014 23:47, schrieb Paul K:
Hi All,
I've been using socket.dns.toip(socket.dns.gethostname()) to get the
IP address of the computer my application is running on, but came
across several situations when the hostname doesn't resolve. It's
possible to configure it manually, but I'd prefer to have a way to
enumerate all known IP addresses and pick those that match some
conditions I'm interested in (for example, first ip4 non-loopback
address).
Is something like this possible with luasocket? I've seen other socket
libraries using getifaddrs (not sure about Windows, but there is
sockets.addressfamily with similar functionality [1]), but don't see
any of these methods being used in luasocket.
Paul.
[1] http://msdn.microsoft.com/en-us/library/system.net.sockets.addressfamily(v=vs.110).aspx