Added ability to have static IP hosts

pull/492/head
Jim Jacobsen 2016-09-27 23:56:17 -05:00
rodzic 2d03dde95a
commit bab827d492
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
}