Commit 80f79ad3 authored by Mikio Hara's avatar Mikio Hara Committed by Russ Cox

net: make use of IPv4len, IPv6len

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/4926046
parent 6ecd5f9f
......@@ -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 {
......
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