A zeroconf proof of concept

Matt Mackall mpm at selenic.com
Mon Jun 30 14:03:22 CDT 2008


On Mon, 2008-06-30 at 13:53 -0500, Augie Fackler wrote:
> On Jun 30, 2008, at 10:52 AM, Matt Mackall wrote:
> 
> > <snip instructions>
> >
> > Theoretically, this extension should work on Linux, Mac, and Windows,
> > but I've only tried it on Linux. Enjoy.
> 
> I've been poking it a bit on OS X, and it's failing on the line  
> s.connect(('1.0.0.1', 0)) with an exception claiming "Can't assign  
> requested address". I don't have more time to put into this now, but I  
> may get a chance to look at this tonight.

That's this code, which is admittedly a little odd: 

> > +        s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
> > +        s.connect(('1.0.0.1', 0))
> > +        ip = s.getsockname()[0]
> > +        localip = socket.inet_aton(ip)

What's needed is a way to find a meaningful IP address for the machine. 
There are various things that don't work great and this is one of them.
The idea is to open a dummy socket to a dummy address and find the
outgoing interface. The above on Linux doesn't even send a packet.

Other alternatives:

socket.gethostbyaddr(socket.gethostname())

This gives the completely useless result '127.0.1.1' on my machine and
will fail on other reasonably configured machines as well.

Another is to open a real socket to a real address. But that won't work
if you don't have working DNS and a real internet connection - rather
counter to the whole zeroconf notion.

We may need to just have two or three fallback techniques.

-- 
Mathematics is the supreme nostalgia of our time.



More information about the Mercurial-devel mailing list