x/net/icmp: make use of strconv
There is no circular dependencies, no need to hesitate to use it.
LGTM=iant
R=iant
CC=golang-codereviews
https://golang.org/cl/185900043
diff --git a/icmp/helper_unix.go b/icmp/helper_unix.go
index d3c5529..ced835c 100644
--- a/icmp/helper_unix.go
+++ b/icmp/helper_unix.go
@@ -8,6 +8,7 @@
import (
"net"
+ "strconv"
"syscall"
)
@@ -56,7 +57,10 @@
if ifi, err := net.InterfaceByName(zone); err == nil {
return uint32(ifi.Index)
}
- n, _, _ := dtoi(zone, 0)
+ n, err := strconv.Atoi(zone)
+ if err != nil {
+ return 0
+ }
return uint32(n)
}
@@ -69,19 +73,3 @@
}
return i
}
-
-const big = 0xFFFFFF
-
-func dtoi(s string, i0 int) (n int, i int, ok bool) {
- n = 0
- for i = i0; i < len(s) && '0' <= s[i] && s[i] <= '9'; i++ {
- n = n*10 + int(s[i]-'0')
- if n >= big {
- return 0, i, false
- }
- }
- if i == i0 {
- return 0, i, false
- }
- return n, i, true
-}