1# Lookup the hostname in DNS if not set
2
3lookup_hostname()
4{
5	[ -z "$new_ip_address" ] && return 1
6	local h=
7	# Silly ISC programs love to send error text to stdout
8	if type dig >/dev/null 2>&1; then
9		h=$(dig +short -x $new_ip_address)
10		if [ $? = 0 ]; then
11			echo "$h" | sed 's/\.$//'
12			return 0
13		fi
14	elif type host >/dev/null 2>&1; then
15		h=$(host $new_ip_address)
16		if [ $? = 0 ]; then
17			echo "$h" \
18			| sed 's/.* domain name pointer \(.*\)./\1/'
19			return 0
20		fi
21	elif type getent >/dev/null 2>&1; then
22		h=$(getent hosts $new_ip_address)
23		if [ $? = 0 ]; then
24			echo "$h" | sed 's/[^ ]* *\([^ ]*\).*/\1/'
25			return 0
26		 fi
27	fi
28	return 1
29}
30
31set_hostname()
32{
33	if [ -z "$new_host_name" -a -z "$new_fqdn_name" ]; then
34		export new_host_name="$(lookup_hostname)"
35	fi
36}
37
38if $if_up; then
39	set_hostname
40fi
41