mirror of
https://github.com/golang/go
synced 2024-11-22 03:24:41 -07:00
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
This commit is contained in:
parent
6e3a7930eb
commit
610b5b2fd8
@ -5,8 +5,6 @@
|
||||
package net
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"sort"
|
||||
)
|
||||
@ -45,20 +43,22 @@ func reverseaddr(addr string) (arpa string, err error) {
|
||||
return "", &DNSError{Err: "unrecognized address", Name: addr}
|
||||
}
|
||||
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
|
||||
var buf bytes.Buffer
|
||||
buf := make([]byte, 0, len(ip)*4+len("ip6.arpa."))
|
||||
// Add it, in reverse, to the buffer
|
||||
for i := len(ip) - 1; i >= 0; i-- {
|
||||
s := fmt.Sprintf("%02x", ip[i])
|
||||
buf.WriteByte(s[1])
|
||||
buf.WriteByte('.')
|
||||
buf.WriteByte(s[0])
|
||||
buf.WriteByte('.')
|
||||
v := ip[i]
|
||||
buf = append(buf, hexDigit[v&0xF])
|
||||
buf = append(buf, '.')
|
||||
buf = append(buf, hexDigit[v>>4])
|
||||
buf = append(buf, '.')
|
||||
}
|
||||
// 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.
|
||||
|
@ -7,7 +7,6 @@
|
||||
package net
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
@ -194,7 +193,9 @@ func parseProcNetIGMP(path string, ifi *Interface) []Addr {
|
||||
name = f[1]
|
||||
case len(f[0]) == 8:
|
||||
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])}
|
||||
ifmat = append(ifmat, ifma.toAddr())
|
||||
}
|
||||
@ -218,10 +219,11 @@ func parseProcNetIGMP6(path string, ifi *Interface) []Addr {
|
||||
continue
|
||||
}
|
||||
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]}}
|
||||
ifmat = append(ifmat, ifma.toAddr())
|
||||
|
||||
}
|
||||
}
|
||||
return ifmat
|
||||
|
@ -9,7 +9,6 @@
|
||||
package net
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os"
|
||||
"syscall"
|
||||
"time"
|
||||
@ -98,7 +97,7 @@ func setIPv4MreqToInterface(mreq *syscall.IPMreq, ifi *Interface) error {
|
||||
}
|
||||
}
|
||||
done:
|
||||
if bytes.Equal(mreq.Multiaddr[:], IPv4zero.To4()) {
|
||||
if bytesEqual(mreq.Multiaddr[:], IPv4zero.To4()) {
|
||||
return errNoSuchMulticastInterface
|
||||
}
|
||||
return nil
|
||||
|
@ -9,7 +9,6 @@
|
||||
package net
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"syscall"
|
||||
@ -30,7 +29,7 @@ func sockaddrToTCP(sa syscall.Sockaddr) Addr {
|
||||
default:
|
||||
if sa != 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
|
||||
|
Loading…
Reference in New Issue
Block a user