debugging on fqdn

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-06-02 20:07:13 -07:00
parent 1b48bec90b
commit 468842e572
3 changed files with 16 additions and 8 deletions

View File

@ -1,3 +1,5 @@
This thing segfault'd with fqdn lookup on weird network errors when I was at the office on wifi
2019/06/01 21:11:47 connecting to ws://v000185.testing.com.customers.wprod.wit.com:9000/event
2019/06/01 21:11:47 fqdn.Get() = librem15.lab.wit.com
INFO[0000] *** error: read udp [2604:bbc0:1:22::f5d3:7f44]:50435->[2001:500:12::d0d]:53: i/o timeout

18
fqdn.go
View File

@ -1,30 +1,36 @@
package main
import (
"net"
"os"
"strings"
)
import "net"
import "os"
import "strings"
import "log"
// Get Fully Qualified Domain Name
// returns "unknown" or hostanme in case of error
func FqdnGet() string {
func fqdnGet() string {
log.Println("fqdnGet() START")
hostname, err := os.Hostname()
if err != nil {
return "unknown"
}
log.Println("\tfqdnGet() net.LookupIP(hostname) hostname =", hostname)
addrs, err := net.LookupIP(hostname)
if err != nil {
log.Println("\tfqdnGet() net.LookupIP(hostname) err =", err)
return hostname
}
log.Println("\tfqdnGet() range addrs")
for _, addr := range addrs {
log.Println("\tfqdnGet() addr = ", addr)
if ipv4 := addr.To4(); ipv4 != nil {
ip, err := ipv4.MarshalText()
log.Println("\tfqdnGet() ip = ", string(ip))
if err != nil {
return hostname
}
log.Println("\tfqdnGet() net.LookupAddr = ", string(ip))
hosts, err := net.LookupAddr(string(ip))
if err != nil || len(hosts) == 0 {
return hostname

View File

@ -106,8 +106,8 @@ func main() {
// use this to discover what the OS thinks it's hostname is
// seems to be cross platform (?)
// Windows: WMIC computersystem where caption='current_pc_name' rename new_pc_name
hostname := FqdnGet()
log.Println("fqdn.Get() = ", hostname)
hostname := fqdnGet()
log.Println("fqdnGet() = ", hostname)
config.Hostname = hostname
// this is a recursive dig for the AAAA record