From 5c1a9e709df6cfabbc60a5335d86b34a60d65f61 Mon Sep 17 00:00:00 2001 From: Disconnect3d Date: Fri, 21 Aug 2020 00:12:20 +0200 Subject: [PATCH] net_linux.go: decode port as 16-bit uint Changes the port parsing from `/proc/net/*` files records from parsing them as 64-bit integers to parse them as 16-bit unsigned integers. While this is mostly a cosmetic change, it will also make so that the code fails faster in case the entry is malformed (for whatever reason). Note that the returned value is still casted to uint32 when an `Addr` object is created. It seems to me that the `Addr.port` field should be changed to `uint16` but maybe some other APIs/systems wants it to be `uint32` and also changing it there may require changes in users code if they update. This being said I am not changing that field's type. --- net/net_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/net_linux.go b/net/net_linux.go index f289a5d..ed5d027 100644 --- a/net/net_linux.go +++ b/net/net_linux.go @@ -696,7 +696,7 @@ func decodeAddress(family uint32, src string) (Addr, error) { return Addr{}, fmt.Errorf("does not contain port, %s", src) } addr := t[0] - port, err := strconv.ParseInt("0x"+t[1], 0, 64) + port, err := strconv.ParseUint(t[1], 16, 16) if err != nil { return Addr{}, fmt.Errorf("invalid port, %s", src) }