From d4dea212ddb6d8408a2f1177b297bda43175c011 Mon Sep 17 00:00:00 2001 From: Daniel Date: Mon, 2 Nov 2020 14:16:35 +0100 Subject: [PATCH] Fix decoding IPv6 addresses --- network/proc/tables.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/network/proc/tables.go b/network/proc/tables.go index 94f3198b..8ea303d1 100644 --- a/network/proc/tables.go +++ b/network/proc/tables.go @@ -207,6 +207,7 @@ func procDelimiter(c rune) bool { } func convertIPv4(data string) net.IP { + // Decode and bullshit check the data length. decoded, err := hex.DecodeString(data) if err != nil { log.Warningf("proc: could not parse IPv4 %s: %s", data, err) @@ -216,11 +217,14 @@ func convertIPv4(data string) net.IP { log.Warningf("proc: decoded IPv4 %s has wrong length", decoded) return nil } + + // Build the IPv4 address with the reversed byte order. ip := net.IPv4(decoded[3], decoded[2], decoded[1], decoded[0]) return ip } func convertIPv6(data string) net.IP { + // Decode and bullshit check the data length. decoded, err := hex.DecodeString(data) if err != nil { log.Warningf("proc: could not parse IPv6 %s: %s", data, err) @@ -230,6 +234,11 @@ func convertIPv6(data string) net.IP { log.Warningf("proc: decoded IPv6 %s has wrong length", decoded) return nil } + + // Build the IPv6 address with the translated byte order. + for i := 0; i < 16; i += 4 { + decoded[i], decoded[i+1], decoded[i+2], decoded[i+3] = decoded[i+3], decoded[i+2], decoded[i+1], decoded[i] + } ip := net.IP(decoded) return ip }