[ccan] [PATCH 2/2] net: Extend to allow convenient binding to a specified local address

Rusty Russell rusty at rustcorp.com.au
Wed Sep 25 13:14:28 EST 2013


David Gibson <david at gibson.dropbear.id.au> writes:
> On Tue, Sep 24, 2013 at 02:12:20PM +0930, Paul 'Rusty' Russell wrote:
>> David Gibson <david at gibson.dropbear.id.au> writes:
>> > Currently the server/bind side functions in the net module always bind to
>> > the "wildcard" address listening on all interfaces / local addresses.  This
>> > patch adds a new net_server_lookup_addr() function to also allow listening
>> > on only a specified local address.
>> >
>> > Signed-off-by: David Gibson <david at gibson.dropbear.id.au>
>> 
>> Gah, getaddrinfo() is a terrible interface.
>> 
>> What you really want to do is specify an interface to use (ie. loopback
>> in your examples).  By specifying addr as "127.0.0.1" it's unclear to me
>> if we'll see any IPv6 addresses.
>
> Well.  The interface I have in mind here does take an explicit address
> (well, optionally) in which case, yes, you'll only get either an IPv4
> or an IPv6 address.
>
> I did think of taking an interface name and binding to all addresses
> (v4 or v6) on that interface as a possible extension.  But for the use
> I have in mind, I really do want to specify a single address.

But the whole point of this module is to be v6 and v4 transparent?

Since we accept standard struct addrinfo *, you should probably just
getaddrinfo() yourself if you want anything unusual, rather than using
net_server_lookup(), which is really just a minor helper.

I think net_server_lookup_iface() or net_server_lookup_local() would be
a good addition.

>> Yet if we really want to join to struct addrinfo, the user can't use
>> freeaddrinfo() on it: we need to supply a free function.  I guess we'll
>> do that, too.
>
> I'm not sure what you mean here.

We tell people they can call freeaddrinfo() on the return from
net_server_lookup().  If we have to generate struct addrinfo *'s
ourselves, they can't call freeaddrinfo() on them...

Cheers,
Rusty.


More information about the ccan mailing list