mirror of
https://github.com/golang/go
synced 2024-11-19 10:04:56 -07:00
net: simplify ipToSockaddr
Change-Id: I5dbcdf0ee0b46b760b2a7decb1d937aac2a6fa8d Reviewed-on: https://go-review.googlesource.com/20585 Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
parent
763afe13b9
commit
1f96c83bf6
@ -170,11 +170,8 @@ func ipToSockaddr(family int, ip IP, port int, zone string) (syscall.Sockaddr, e
|
|||||||
if ip = ip.To4(); ip == nil {
|
if ip = ip.To4(); ip == nil {
|
||||||
return nil, &AddrError{Err: "non-IPv4 address", Addr: ip.String()}
|
return nil, &AddrError{Err: "non-IPv4 address", Addr: ip.String()}
|
||||||
}
|
}
|
||||||
sa := new(syscall.SockaddrInet4)
|
sa := &syscall.SockaddrInet4{Port: port}
|
||||||
for i := 0; i < IPv4len; i++ {
|
copy(sa.Addr[:], ip)
|
||||||
sa.Addr[i] = ip[i]
|
|
||||||
}
|
|
||||||
sa.Port = port
|
|
||||||
return sa, nil
|
return sa, nil
|
||||||
case syscall.AF_INET6:
|
case syscall.AF_INET6:
|
||||||
if len(ip) == 0 {
|
if len(ip) == 0 {
|
||||||
@ -189,12 +186,8 @@ func ipToSockaddr(family int, ip IP, port int, zone string) (syscall.Sockaddr, e
|
|||||||
if ip = ip.To16(); ip == nil {
|
if ip = ip.To16(); ip == nil {
|
||||||
return nil, &AddrError{Err: "non-IPv6 address", Addr: ip.String()}
|
return nil, &AddrError{Err: "non-IPv6 address", Addr: ip.String()}
|
||||||
}
|
}
|
||||||
sa := new(syscall.SockaddrInet6)
|
sa := &syscall.SockaddrInet6{Port: port, ZoneId: uint32(zoneToInt(zone))}
|
||||||
for i := 0; i < IPv6len; i++ {
|
copy(sa.Addr[:], ip)
|
||||||
sa.Addr[i] = ip[i]
|
|
||||||
}
|
|
||||||
sa.Port = port
|
|
||||||
sa.ZoneId = uint32(zoneToInt(zone))
|
|
||||||
return sa, nil
|
return sa, nil
|
||||||
}
|
}
|
||||||
return nil, &AddrError{Err: "invalid address family", Addr: ip.String()}
|
return nil, &AddrError{Err: "invalid address family", Addr: ip.String()}
|
||||||
|
Loading…
Reference in New Issue
Block a user