I generally like my router to use dhcp, but this means finding it presents a problem. This OpenWrt package adds a daemon which implements a UDP-broadcast based discovery protocol for the router. A one-line change is needed to the udhcpc script (instructions in the tarball).
Source files can be found in svn
Copy them into the 'packages' directory and select from the menu ('emb-finder') when running 'make menuconfig' (find it under 'utilities').
Embfinder allows a PC to discover the location of embedded devices on the network.
A line is required in /etc/services so the daemon can decide which listening port to use:
embfinder 5122/udp # finder service.
If the line isn't found, the service uses the default 5122.
The client broadcasts a UDP request packet to this port. If the packet is the correct format a response is sent back to the originating port containing the IP address of the device.
A client is provided in Python - embfinder.py. It simply prints out the IP address returned, or times out in one second if it fails to get a response.
Unfortunately, udhcpc in default configuration does not seem to create a lease file anywhere, so you must create a file for emb-finder to read. You can do this on lease binding/renewal by changing /usr/share/udhcpc/default.script. You can do this by editing trunk/packages/base-files/files/usr/share/udhcpc/default.script then rebuilding the firmware. Add the line as follows:
renew|bound) ifconfig $interface $ip \ netmask ${subnet:-255.255.255.0} \ broadcast ${broadcast:-+} echo $ip > /var/myip.txt # <----- add this line
Maybe there is a better way of doing this, but I couldn't figure it out.