I have a device that can be used in two different scenarios.
One is that it is hooked up to an ordinary Ethernet LAN company network. This network has a DHCP server and the device is expected to be a DHCP client and automatically receive an IP address.
The second scenario is that the device is plugged directly into a PC/Laptop using an Ethernet LAN cable. In that case, it is expected that the device chooses its own IP and also gives the PC/Laptop an IP. In that case, the device must assume the role of a DHCP server.
You probably already see where this is going. I don't want the user of the device to have to configure anything. They should be able to just plug it in and it works for them. Now, the problem is, reliably finding out whether there is another DHCP server in your network is hard. Yes I can make DHCP requests and so on. I'll find the server 99% of the time. But this one time where I don't find it (e.g. due to packet loss or long packet travel times), if my device then becomes DHCP server, it poisons the entire company network by giving out IP addresses in the wrong range. How can I solve this problem? Are there any protocols or safety measures I can take to be guaranteed to not interfere with a company network?
My device is a client device offering a service, kind of like a printer. It runs OpenWRT. I compile it myself and I control all the config files. The users typically run Windows 7,8 or 10. How can I enable APIPA on OpenWRT? Or can I enable AVAHI and is that compatible with Windows' APIPA?