I'm using netplugd to monitor the plug and unplug events of my ethernet. Also using udhcpc to get IP from DHCP whenever plug in event is got, configuring static IP in case udhcpc fails in 5 retries to do so.
Here the problem is that in case the ethernet is not pluggen in at the boot time of the board, the static IP gets configured as per implementation. But afterwards if ethernet is plugged in, DHCP ip is configured and I'm able to ping google.com and other hostnames, but getaddrinfo used in one of my code reports error - unable to resolve hostname.
While there seems no problem if ethernet is plugged in at the boot time and then removed afterwards and plugged in again.
EDIT 1 This is the netplug script I'm using
PATH=/usr/bin:/bin:/usr/sbin:/sbin
export PATH
dev="$1"
action="$2"
case "$action" in
in)
if [ -x /sbin/ifconfig ]; then
killall udhcpc
udhcpc -B -S -n -t 8 -ieth0
if [ $? -ne 0 ]
then
j=`cat /sys/class/net/eth0/operstate`
if [ "$j" == "up" ]
then
/sbin/ifconfig $dev 192.168.1.1 up
fi
fi
else
echo "Please teach me how to plug in an interface!" 1>&2
exit 1
fi
;;
out)
if [ -x /sbin/ifconfig ]; then
echo "Ethernet Disconnected"
/sbin/ifconfig $dev 0.0.0.0 down
else
echo "Please teach me how to unplug an interface!" 1>&2
exit 1
fi
;;
probe)
exec /sbin/ip link set "$dev" up >/dev/null 2>&1
;;
*)
echo "I have been called with a funny action of '%s'!" 1>&2
exit 1
;;
esac
I have included the check for the operstate entry from sysfs so that static ip doesn't get configured in case the cable is not plugged in, but still the problem persists.