Merge pull request #492 from jamez70/allow_static_ip_hosts

Added ability to have static IP hosts
pull/501/head
cyoung 2016-10-01 11:47:04 -04:00 zatwierdzone przez GitHub
commit d67f2fe1db
1 zmienionych plików z 21 dodań i 0 usunięć

21
main/network.go 100644 → 100755
Wyświetl plik

@ -71,6 +71,7 @@ const (
NETWORK_AHRS_FFSIM = 2
NETWORK_AHRS_GDL90 = 4
dhcp_lease_file = "/var/lib/dhcp/dhcpd.leases"
extra_hosts_file = "/etc/stratux-static-hosts.conf"
)
// Read the "dhcpd.leases" file and parse out IP/hostname.
@ -97,6 +98,26 @@ func getDHCPLeases() (map[string]string, error) {
ret[block_ip] = ""
}
}
// Added the ability to have static IP hosts stored in /etc/stratux-static-hosts.conf
dat2, err := ioutil.ReadFile(extra_hosts_file)
if err != nil {
return ret, nil
}
iplines := strings.Split(string(dat2), "\n")
block_ip2 := ""
for _, ipline := range iplines {
spacedip := strings.Split(ipline, " ")
if len(spacedip) == 2 {
// The ip is in block_ip2
block_ip2 = spacedip[0]
// the hostname is here
ret[block_ip2] = spacedip[1]
}
}
return ret, nil
}