Hi,
I'm wondering if there is any way to determine the local host address (or addresses) used when I create a socket with :local-host *wildcard-host* . When I try to call get-local-address on such a socket, I just get #(0 0 0 0).
Thanks.
Elliott,
to my knowledge, usocket does not provide an API to get a list of all network interfaces, which is what you need to do if you want to know the local IP address(es).
One quick workaround is to invoke ifconfig and parse the output. I know that this is not a very satisfying or portable approach, but it is quick.
-Hans
On Sun, Mar 7, 2010 at 07:20, Elliott Slaughter elliottslaughter@gmail.com wrote:
Hi, I'm wondering if there is any way to determine the local host address (or addresses) used when I create a socket with :local-host *wildcard-host* . When I try to call get-local-address on such a socket, I just get #(0 0 0 0). Thanks.
-- Elliott Slaughter
"Don't worry about what anybody else is going to do. The best way to predict the future is to invent it." - Alan Kay
usocket-devel mailing list usocket-devel@common-lisp.net http://common-lisp.net/cgi-bin/mailman/listinfo/usocket-devel
On Sat, Mar 6, 2010 at 10:44 PM, Hans Hübner hans.huebner@gmail.com wrote:
Elliott,
to my knowledge, usocket does not provide an API to get a list of all network interfaces, which is what you need to do if you want to know the local IP address(es).
One quick workaround is to invoke ifconfig and parse the output. I know that this is not a very satisfying or portable approach, but it is quick.
Thanks. I wanted to make sure I wasn't missing something.
Supposing that I wanted to find a more portable solution, would I need to write a custom CFFI wrapper over gethostbyname or getaddrinfo? And would this sort of functionality be considered for inclusion in usocket?
On Sat, Mar 6, 2010 at 11:10 PM, Elliott Slaughter < elliottslaughter@gmail.com> wrote:
On Sat, Mar 6, 2010 at 10:44 PM, Hans Hübner hans.huebner@gmail.comwrote:
Elliott,
to my knowledge, usocket does not provide an API to get a list of all network interfaces, which is what you need to do if you want to know the local IP address(es).
One quick workaround is to invoke ifconfig and parse the output. I know that this is not a very satisfying or portable approach, but it is quick.
Thanks. I wanted to make sure I wasn't missing something.
Wait -- what about the following?
* (usocket::get-hosts-by-name (usocket::get-host-name))
(#(192 168 1 100) #(5 223 109 11) #(192 168 56 1))
I know these functions aren't exported from usocket, but is there any reason why they couldn't be?
On Sun, Mar 7, 2010 at 08:20, Elliott Slaughter elliottslaughter@gmail.com wrote:
Wait -- what about the following?
- (usocket::get-hosts-by-name (usocket::get-host-name))
(#(192 168 1 100) #(5 223 109 11) #(192 168 56 1)) I know these functions aren't exported from usocket, but is there any reason why they couldn't be?
Is USOCKET::GET-HOSTS-BY-NAME implemented by all backends?
See my previous post about the lack of robustness of hostname based solutions.
-Hans
On Sun, Mar 7, 2010 at 08:10, Elliott Slaughter elliottslaughter@gmail.com wrote:
Supposing that I wanted to find a more portable solution, would I need to write a custom CFFI wrapper over gethostbyname or getaddrinfo? And would this sort of functionality be considered for inclusion in usocket?
Using gethostbyname is not a robust approach in the first place. Many systems have no usable host name or multiple network interfaces. You will need to iterate over the list of interfaces and give the user a way to use any of the addresses that the local machine has. Add Windows and ABCL to the mix, and you'll have more issues to solve.
If you're really interested in a solution, you'll have to find something that does not depend on CFFI. Erik can give you more information on usocket's policies.
-Hans
Elliott Slaughter writes:
On Sat, Mar 6, 2010 at 10:44 PM, Hans Hübner hans.huebner@gmail.com wrote:
Elliott,
to my knowledge, usocket does not provide an API to get a list of all network interfaces, which is what you need to do if you want to know the local IP address(es).
One quick workaround is to invoke ifconfig and parse the output. I know that this is not a very satisfying or portable approach, but it is quick.
Thanks. I wanted to make sure I wasn't missing something.
Supposing that I wanted to find a more portable solution, would I need to write a custom CFFI wrapper over gethostbyname or getaddrinfo? And would this sort of functionality be considered for inclusion in usocket?
That seems more appropriate for IOLIB's socket interface.
-T.
On Sat, 2010-03-06 at 22:20 -0800, Elliott Slaughter wrote:
Hi,
I'm wondering if there is any way to determine the local host address (or addresses) used when I create a socket with :local-host *wildcard-host* . When I try to call get-local-address on such a socket, I just get #(0 0 0 0).
When you bind a socket to the wildcard address(i.e. 0.0.0.0), you're listening simultaneously on all interfaces so you can't ask for "the" host address because there might be more than just one. Furthermore, the socket doesn't keep trace of the local interfaces that were active when it was created.