提交 5c1a9e70 编写于 作者: D Disconnect3d 提交者: disconnect3d

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.
上级 7e94bb8b
...@@ -696,7 +696,7 @@ func decodeAddress(family uint32, src string) (Addr, error) { ...@@ -696,7 +696,7 @@ func decodeAddress(family uint32, src string) (Addr, error) {
return Addr{}, fmt.Errorf("does not contain port, %s", src) return Addr{}, fmt.Errorf("does not contain port, %s", src)
} }
addr := t[0] addr := t[0]
port, err := strconv.ParseInt("0x"+t[1], 0, 64) port, err := strconv.ParseUint(t[1], 16, 16)
if err != nil { if err != nil {
return Addr{}, fmt.Errorf("invalid port, %s", src) return Addr{}, fmt.Errorf("invalid port, %s", src)
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册