]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
We now use either dig or host to lookup the hostname in DNS again.
authorRoy Marples <roy@marples.name>
Sun, 13 Apr 2008 13:17:03 +0000 (13:17 +0000)
committerRoy Marples <roy@marples.name>
Sun, 13 Apr 2008 13:17:03 +0000 (13:17 +0000)
dhcpcd.8.in
dhcpcd.sh

index 36481bd005d9abb261058b3f0c00c81283cf6334..71d964de4845639be1327e96431963a071bb4ee5 100644 (file)
@@ -79,7 +79,8 @@ will also attempt to restart the respective services to notify them of the
 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.
@@ -231,7 +232,8 @@ dhcpcd itself never does any DNS updates.
 .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
index 12e90e4d2098ffdac8436800f1c9c8852416be8b..1861e3e16a1ec5d96c4d37fe1c2aaca79434da70 100755 (executable)
--- a/dhcpcd.sh
+++ b/dhcpcd.sh
@@ -1,5 +1,4 @@
 #!/bin/sh
-# 
 # dhcpcd - DHCP client daemon
 # Copyright 2006-2008 Roy Marples <roy@marples.name>
 # All rights reserved
@@ -230,11 +229,23 @@ need_hostname()
        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
 }