Page 1 of 1

Questions on Implementing Auto-IP

Posted: Tue Sep 13, 2011 6:32 pm
by sblair
I'm working on implementing Auto-IP (i.e. random 169.254.x.x IP selection). So far I haven't found reference to anyone else doing this.

In a nutshell, if DHCP fails then I want to generate an Auto-IP address. Once you pick a random address you do an ARP Probe to make sure no one else is using that IP already by sending an ARP Request with the configured IP as the source address. You have to be able to detect collisions and listen for matching ARP reply/requests/probes for the chosen IP.

Other than the ShowArp() which just prints the ARP table, I haven't found anything else documented on sending/processing ARP's. I've waded through ARP.cpp but am not quite certain which calls are appropriate for me to access to accomplish this.

SendGratuitousArp() ? or SendArp()? What is the best way to detect if there is a collision or determine if my IP is already in use other than just traversing the Arp table again?

Thanks.
Scott

Re: Questions on Implementing Auto-IP

Posted: Wed Sep 14, 2011 7:41 am
by Chris Ruff
Scott

I did this back in '04. Attached are some of the primitives I copied from my arp.cpp in the system library. One or more should be helpful

I built a task/state machine that spent all day arping about and either noting that DHCP was in charge, or generating link-local addresses, arping some more, and then doing the whole thing again. If you instantiate your own DhcpObject you can ->StartDHCP() and ->StopDHCP(), thereby restarting it on some number of minutes/seconds boundary when you are not getting an offer from DHCP.

You also need to pay attention within your application that if you are using a link-local socket set, you can't scuttle it and retry DHCP. You have to wait until nothing is going on.

You also will want to retry the same link-local address over and over. Once you have got one that is not used by someone else, well-behaved instruments around you will allow you to 'own' the link-local address.

Good luck, testing this is hard, and remember...don't hesitate to DEFEND your link-local address against aggressive powering-up instruments on your network

Chris

Re: Questions on Implementing Auto-IP

Posted: Wed Sep 14, 2011 2:40 pm
by sblair
Wow! Awesome! Thanks Chris!

I love Auto-IP for simple ad-hoc networks, especially when dealing with users that don't really understand networking that well to begin with. Just makes everything easier. This was the first time I've had to go implement the functionality myself, so thanks for the useful functions to make it easier.

Scott

Re: Questions on Implementing Auto-IP

Posted: Thu Sep 15, 2011 1:19 pm
by pbreed
#include <arp.h> has a function...

BOOL IsMyAddressUsedArpDetect(WORD timeout, int interface=0);

To do autoip, assign the IP address one wants to use and before doing anything else call

IsMyAddressUsedArpDetect


Then if its not used your good to go....

Should be easy a few lines of code. (Probably should add this to the default DHCP behavior in the library)