From a786eda7fd9b2036abd799928ac60f581e7b4f06 Mon Sep 17 00:00:00 2001 From: Carsten Moberg Hammer Date: Wed, 24 Apr 2024 09:11:42 +0200 Subject: [PATCH 1/3] Added more info to fatal log message --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index e1a8332..45b1cc7 100644 --- a/main.go +++ b/main.go @@ -229,7 +229,7 @@ func root(_ *cobra.Command, _ []string) { connections := append(connections4, connections6...) if len(connections) != 1 { - log.Fatalf("Unable to guess remote IP. %d results returned", len(connections)) + log.Fatalf("Unable to guess remote IP for %s. %d results returned, ipv4 connections '%v' , ipv6 connections '%v'", hostname, len(connections), connections4, connections6) } q.Add("remote_ip", connections[0].String()) From 1b8b5d2cff62d1d1bb35b9aa6cb5d267651fb2f6 Mon Sep 17 00:00:00 2001 From: Carsten Moberg Hammer Date: Fri, 26 Apr 2024 13:36:21 +0200 Subject: [PATCH 2/3] Ensure connections have unique ips --- main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 45b1cc7..5f424ce 100644 --- a/main.go +++ b/main.go @@ -226,10 +226,14 @@ func root(_ *cobra.Command, _ []string) { connections6 = nil } + var connectionsMap map[string]bool connections := append(connections4, connections6...) + for _, ip := range connections { + connectionsMap[ip.String()] = true + } - if len(connections) != 1 { - log.Fatalf("Unable to guess remote IP for %s. %d results returned, ipv4 connections '%v' , ipv6 connections '%v'", hostname, len(connections), connections4, connections6) + if len(connectionsMap) != 1 { + log.Fatalf("Unable to guess remote IP for %s. %d results returned, connectionMap '%v', ipv4 connections '%v' , ipv6 connections '%v'", hostname, len(connectionsMap), connectionsMap, connections4, connections6) } q.Add("remote_ip", connections[0].String()) From 99b6372c28dfafa8cfb5dbcd5b0cf9b9d6315bbe Mon Sep 17 00:00:00 2001 From: Carsten Moberg Hammer Date: Fri, 26 Apr 2024 13:58:05 +0200 Subject: [PATCH 3/3] Make map --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 5f424ce..728b63a 100644 --- a/main.go +++ b/main.go @@ -226,8 +226,8 @@ func root(_ *cobra.Command, _ []string) { connections6 = nil } - var connectionsMap map[string]bool connections := append(connections4, connections6...) + connectionsMap := make(map[string]bool, len(connections)) for _, ip := range connections { connectionsMap[ip.String()] = true }