Commit 610b5b2f authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net: remove all direct fmt and bytes imports

Once dnsMsg stops using reflect, we lose even more
indirect dependencies.

R=rsc
CC=golang-dev
https://golang.org/cl/5751043
parent 6e3a7930
...@@ -5,8 +5,6 @@ ...@@ -5,8 +5,6 @@
package net package net
import ( import (
"bytes"
"fmt"
"math/rand" "math/rand"
"sort" "sort"
) )
...@@ -45,20 +43,22 @@ func reverseaddr(addr string) (arpa string, err error) { ...@@ -45,20 +43,22 @@ func reverseaddr(addr string) (arpa string, err error) {
return "", &DNSError{Err: "unrecognized address", Name: addr} return "", &DNSError{Err: "unrecognized address", Name: addr}
} }
if ip.To4() != nil { if ip.To4() != nil {
return fmt.Sprintf("%d.%d.%d.%d.in-addr.arpa.", ip[15], ip[14], ip[13], ip[12]), nil return itoa(int(ip[15])) + "." + itoa(int(ip[14])) + "." + itoa(int(ip[13])) + "." +
itoa(int(ip[12])) + ".in-addr.arpa.", nil
} }
// Must be IPv6 // Must be IPv6
var buf bytes.Buffer buf := make([]byte, 0, len(ip)*4+len("ip6.arpa."))
// Add it, in reverse, to the buffer // Add it, in reverse, to the buffer
for i := len(ip) - 1; i >= 0; i-- { for i := len(ip) - 1; i >= 0; i-- {
s := fmt.Sprintf("%02x", ip[i]) v := ip[i]
buf.WriteByte(s[1]) buf = append(buf, hexDigit[v&0xF])
buf.WriteByte('.') buf = append(buf, '.')
buf.WriteByte(s[0]) buf = append(buf, hexDigit[v>>4])
buf.WriteByte('.') buf = append(buf, '.')
} }
// Append "ip6.arpa." and return (buf already has the final .) // Append "ip6.arpa." and return (buf already has the final .)
return buf.String() + "ip6.arpa.", nil buf = append(buf, "ip6.arpa."...)
return string(buf), nil
} }
// Find answer for name in dns message. // Find answer for name in dns message.
......
...@@ -7,7 +7,6 @@ ...@@ -7,7 +7,6 @@
package net package net
import ( import (
"fmt"
"os" "os"
"syscall" "syscall"
"unsafe" "unsafe"
...@@ -194,7 +193,9 @@ func parseProcNetIGMP(path string, ifi *Interface) []Addr { ...@@ -194,7 +193,9 @@ func parseProcNetIGMP(path string, ifi *Interface) []Addr {
name = f[1] name = f[1]
case len(f[0]) == 8: case len(f[0]) == 8:
if ifi == nil || name == ifi.Name { if ifi == nil || name == ifi.Name {
fmt.Sscanf(f[0], "%08x", &b) for i := 0; i+1 < len(f[0]); i += 2 {
b[i/2], _ = xtoi2(f[0][i:i+2], 0)
}
ifma := IPAddr{IP: IPv4(b[3], b[2], b[1], b[0])} ifma := IPAddr{IP: IPv4(b[3], b[2], b[1], b[0])}
ifmat = append(ifmat, ifma.toAddr()) ifmat = append(ifmat, ifma.toAddr())
} }
...@@ -218,10 +219,11 @@ func parseProcNetIGMP6(path string, ifi *Interface) []Addr { ...@@ -218,10 +219,11 @@ func parseProcNetIGMP6(path string, ifi *Interface) []Addr {
continue continue
} }
if ifi == nil || f[1] == ifi.Name { if ifi == nil || f[1] == ifi.Name {
fmt.Sscanf(f[2], "%32x", &b) for i := 0; i+1 < len(f[2]); i += 2 {
b[i/2], _ = xtoi2(f[2][i:i+2], 0)
}
ifma := IPAddr{IP: IP{b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15]}} ifma := IPAddr{IP: IP{b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], b[8], b[9], b[10], b[11], b[12], b[13], b[14], b[15]}}
ifmat = append(ifmat, ifma.toAddr()) ifmat = append(ifmat, ifma.toAddr())
} }
} }
return ifmat return ifmat
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
package net package net
import ( import (
"bytes"
"os" "os"
"syscall" "syscall"
"time" "time"
...@@ -98,7 +97,7 @@ func setIPv4MreqToInterface(mreq *syscall.IPMreq, ifi *Interface) error { ...@@ -98,7 +97,7 @@ func setIPv4MreqToInterface(mreq *syscall.IPMreq, ifi *Interface) error {
} }
} }
done: done:
if bytes.Equal(mreq.Multiaddr[:], IPv4zero.To4()) { if bytesEqual(mreq.Multiaddr[:], IPv4zero.To4()) {
return errNoSuchMulticastInterface return errNoSuchMulticastInterface
} }
return nil return nil
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
package net package net
import ( import (
"fmt"
"io" "io"
"os" "os"
"syscall" "syscall"
...@@ -30,7 +29,7 @@ func sockaddrToTCP(sa syscall.Sockaddr) Addr { ...@@ -30,7 +29,7 @@ func sockaddrToTCP(sa syscall.Sockaddr) Addr {
default: default:
if sa != nil { if sa != nil {
// Diagnose when we will turn a non-nil sockaddr into a nil. // Diagnose when we will turn a non-nil sockaddr into a nil.
panic(fmt.Sprintf("unexpected type in sockaddrToTCP: %T", sa)) panic("unexpected type in sockaddrToTCP")
} }
} }
return nil return nil
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment