etc/protocols - sync with NetBSD-8
[minix.git] / external / bsd / dhcpcd / dist / dhcpcd-hooks / 29-lookup-hostname
blobf20a867c4cbee02e58b78752d66ba7a263a42988
1 # $NetBSD: 29-lookup-hostname,v 1.7 2014/12/09 20:21:05 roy Exp $
3 # Lookup the hostname in DNS if not set
5 lookup_hostname()
7         [ -z "$new_ip_address" ] && return 1
8         local h=
9         # Silly ISC programs love to send error text to stdout
10         if type dig >/dev/null 2>&1; then
11                 h=$(dig +short -x $new_ip_address)
12                 if [ $? = 0 ]; then
13                         echo "$h" | sed 's/\.$//'
14                         return 0
15                 fi
16         elif type host >/dev/null 2>&1; then
17                 h=$(host $new_ip_address)
18                 if [ $? = 0 ]; then 
19                         echo "$h" \
20                         | sed 's/.* domain name pointer \(.*\)./\1/'
21                         return 0
22                 fi
23         elif type getent >/dev/null 2>&1; then
24                 h=$(getent hosts $new_ip_address)
25                 if [ $? = 0 ]; then
26                         echo "$h" | sed 's/[^ ]* *\([^ ]*\).*/\1/'
27                         return 0
28                  fi
29         fi
30         return 1
33 set_hostname()
35         if [ -z "$new_host_name" -a -z "$new_fqdn_name" ]; then
36                 export new_host_name="$(lookup_hostname)"
37         fi
40 if $if_up; then
41         set_hostname