From: Shengjing Zhu <zhsj@debian.org>
Date: Sun, 21 Aug 2022 22:43:58 +0800
Subject: Fix sort test

---
 ifaddrs_test.go | 4 ++--
 ipaddrs.go      | 5 ++++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/ifaddrs_test.go b/ifaddrs_test.go
index c89af4a..4d12e35 100644
--- a/ifaddrs_test.go
+++ b/ifaddrs_test.go
@@ -780,8 +780,8 @@ func TestGetAllInterfaces(t *testing.T) {
 	}
 
 	for i := initialLen - 1; i >= 0; i-- {
-		if !reflect.DeepEqual(descSorted[i], ifAddrs[i]) {
-			t.Errorf("wrong sort order: %d %v %v", i, descSorted[i], ifAddrs[i])
+		if !reflect.DeepEqual(ascSorted[i], ifAddrs[i]) {
+			t.Errorf("wrong sort order: %d %v %v", i, ascSorted[i], ifAddrs[i])
 		}
 	}
 }
diff --git a/ipaddrs.go b/ipaddrs.go
index 6eeb7dd..c8ef6e6 100644
--- a/ipaddrs.go
+++ b/ipaddrs.go
@@ -67,9 +67,12 @@ func (s SortIPAddrsByNetworkSize) Less(i, j int) bool {
 	// that have a port (e.g. a host with a /32 and port number is more
 	// specific and should sort first over a host with a /32 but no port
 	// set).
-	if s.IPAddrs[i].IPPort() == 0 || s.IPAddrs[j].IPPort() == 0 {
+	if s.IPAddrs[i].IPPort() == 0 {
 		return false
 	}
+	if s.IPAddrs[j].IPPort() == 0 {
+		return true
+	}
 	return s.IPAddrs[i].IPPort() < s.IPAddrs[j].IPPort()
 }
 
