"divine" is a utility for laptop users or people who use their machines in different networks all the time. DO NOT make divine setuid root. Divine contains tons of security holes like using system, it is meant as quick hack that will not hurt so much if it is run at boot time.
The idea is this:
- you describe the possible networks in /etc/divine.conf, including one or more machines that are probably up (routers and NIS servers come to mind).
- at boot time, you run divine.
- divine starts a thread that injects fake arp requests into the network. The thread will try again up to three times, pausing 1 second between retries. If the last try times out again, the thread will print an error message, leave the interface in the original state and exit cleanly.
- the main thread just looks for arp replies and exits if one is found.
- You have one resolv.conf per network, for example /etc/resolv.conf.default and /etc/resolv.conf.work, and divine will symlink one of them to /etc/resolv.conf for you.
- You can specify a proxy server plus port and divine will write the proxy server to /etc/proxy. This can be evaluated inside your shell startup script, like this (zsh): export http_proxy="http://`< /etc/proxy`/" The included perl script edit-netscape-proxy.pl will edit the proxy settings in your Netscape 4 preferences file.
- You can even specify an additional script to be run for each selection. You can use this to edit /etc/printcap or /etc/issue or do something else I forgot.
The point about divine in contrast to other solutions is that other solutions normally use ping or something like that. divine can check a large number of networks instantaneously, assuming that the machines you ping answer within one second (.4 seconds are normal on Ethernets). And pinging an unknown address will do an arp request anyway, so why not do an arp request in the first place?
divine was written under Linux and was originally very Linux specific. I then switched to libpcap and libnet, so the core is now portable, but the ifconfig and route calls are not. Those are implemented using system() ;-)
Do not make divine setuid root.
Divine need at least Linux 2.1 which sets the network route implicitly. If you get error messages from the route then this is probably the reason.
