mirror of
https://github.com/golang/go
synced 2024-11-22 03:44:39 -07:00
net: make use of IPv4len, IPv6len
R=golang-dev, rsc CC=golang-dev https://golang.org/cl/4926046
This commit is contained in:
parent
6ecd5f9fe7
commit
80f79ad305
@ -113,7 +113,7 @@ func convertRR_A(records []dnsRR) []IP {
|
||||
func convertRR_AAAA(records []dnsRR) []IP {
|
||||
addrs := make([]IP, len(records))
|
||||
for i, rr := range records {
|
||||
a := make(IP, 16)
|
||||
a := make(IP, IPv6len)
|
||||
copy(a, rr.(*dnsRR_AAAA).AAAA[:])
|
||||
addrs[i] = a
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ func sockaddrToIP(sa syscall.Sockaddr) Addr {
|
||||
}
|
||||
|
||||
func (a *IPAddr) family() int {
|
||||
if a == nil || len(a.IP) <= 4 {
|
||||
if a == nil || len(a.IP) <= IPv4len {
|
||||
return syscall.AF_INET
|
||||
}
|
||||
if a.IP.To4() != nil {
|
||||
@ -158,7 +158,7 @@ func (c *IPConn) ReadFromIP(b []byte) (n int, addr *IPAddr, err os.Error) {
|
||||
switch sa := sa.(type) {
|
||||
case *syscall.SockaddrInet4:
|
||||
addr = &IPAddr{sa.Addr[0:]}
|
||||
if len(b) >= 4 { // discard ipv4 header
|
||||
if len(b) >= IPv4len { // discard ipv4 header
|
||||
hsize := (int(b[0]) & 0xf) * 4
|
||||
copy(b, b[hsize:])
|
||||
n -= hsize
|
||||
|
@ -23,7 +23,7 @@ func sockaddrToTCP(sa syscall.Sockaddr) Addr {
|
||||
}
|
||||
|
||||
func (a *TCPAddr) family() int {
|
||||
if a == nil || len(a.IP) <= 4 {
|
||||
if a == nil || len(a.IP) <= IPv4len {
|
||||
return syscall.AF_INET
|
||||
}
|
||||
if a.IP.To4() != nil {
|
||||
|
@ -23,7 +23,7 @@ func sockaddrToUDP(sa syscall.Sockaddr) Addr {
|
||||
}
|
||||
|
||||
func (a *UDPAddr) family() int {
|
||||
if a == nil || len(a.IP) <= 4 {
|
||||
if a == nil || len(a.IP) <= IPv4len {
|
||||
return syscall.AF_INET
|
||||
}
|
||||
if a.IP.To4() != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user