change.
If the hostname is currenly blank, (null) or localhost then
.Nm
-will set the hostname to the one supplied by the DHCP server.
+will set the hostname to the one supplied by the DHCP server, or look it up
+in DNS if none supplied.
.Nm
then daemonises and waits for the lease renewal time to lapse.
Then it attempts to renew its lease and reconfigure if the new lease changes.
.It Fl H , --sethostname
Forces
.Nm
-to set the hostname as supplied by the DHCP server.
+to set the hostname as supplied by the DHCP server, or look it up
+in DNS if none supplied.
.It Fl I , -clientid Ar clientid
Send
.Ar clientid
#!/bin/sh
-#
# dhcpcd - DHCP client daemon
# Copyright 2006-2008 Roy Marples <roy@marples.name>
# All rights reserved
return 1
}
+lookup_hostname()
+{
+ if type host >/dev/null 2>&1; then
+ host "${IPADDR}" | sed 's/.* domain name pointer \(.*\)./\1/'
+ elif type dig >/dev/null 2>&1; then
+ dig +short -x "${IPADDR}" | sed 's/\.$//'
+ else
+ return 1
+ fi
+}
+
make_hostname()
{
- [ -z "${HOSTNAME}" ] && return 0
- if need_hostname || yesno "${PEERHOSTNAME}"; then
- hostname "${HOSTNAME}"
+ if yesno "${PEERHOSTNAME}" || need_hostname; then
+ local name="${HOSTNAME}"
+ [ -z "${name}" ] && name="$(lookup_hostname)"
+ [ -n "${name}" ] && hostname "${name}"
fi
}