Commit 33a15eb6 authored by Mikio Hara's avatar Mikio Hara

net: make use of AF_UNSPEC instead of individual address family

R=fullung, rsc
CC=golang-dev
https://golang.org/cl/5034044
parent 46ed89b7
...@@ -150,7 +150,6 @@ func newAddr(m *syscall.InterfaceAddrMessage) ([]Addr, os.Error) { ...@@ -150,7 +150,6 @@ func newAddr(m *syscall.InterfaceAddrMessage) ([]Addr, os.Error) {
} }
for _, s := range sas { for _, s := range sas {
switch v := s.(type) { switch v := s.(type) {
case *syscall.SockaddrInet4: case *syscall.SockaddrInet4:
ifa := &IPAddr{IP: IPv4(v.Addr[0], v.Addr[1], v.Addr[2], v.Addr[3])} ifa := &IPAddr{IP: IPv4(v.Addr[0], v.Addr[1], v.Addr[2], v.Addr[3])}
......
...@@ -103,42 +103,29 @@ func linkFlags(rawFlags uint32) Flags { ...@@ -103,42 +103,29 @@ func linkFlags(rawFlags uint32) Flags {
// for a specific interface. // for a specific interface.
func interfaceAddrTable(ifindex int) ([]Addr, os.Error) { func interfaceAddrTable(ifindex int) ([]Addr, os.Error) {
var ( var (
tab []byte tab []byte
e int e int
err os.Error err os.Error
ifat4 []Addr ifat []Addr
ifat6 []Addr msgs []syscall.NetlinkMessage
msgs4 []syscall.NetlinkMessage
msgs6 []syscall.NetlinkMessage
) )
tab, e = syscall.NetlinkRIB(syscall.RTM_GETADDR, syscall.AF_INET) tab, e = syscall.NetlinkRIB(syscall.RTM_GETADDR, syscall.AF_UNSPEC)
if e != 0 { if e != 0 {
return nil, os.NewSyscallError("netlink rib", e) return nil, os.NewSyscallError("netlink rib", e)
} }
msgs4, e = syscall.ParseNetlinkMessage(tab)
if e != 0 {
return nil, os.NewSyscallError("netlink message", e)
}
ifat4, err = addrTable(msgs4, ifindex)
if err != nil {
return nil, err
}
tab, e = syscall.NetlinkRIB(syscall.RTM_GETADDR, syscall.AF_INET6) msgs, e = syscall.ParseNetlinkMessage(tab)
if e != 0 {
return nil, os.NewSyscallError("netlink rib", e)
}
msgs6, e = syscall.ParseNetlinkMessage(tab)
if e != 0 { if e != 0 {
return nil, os.NewSyscallError("netlink message", e) return nil, os.NewSyscallError("netlink message", e)
} }
ifat6, err = addrTable(msgs6, ifindex)
ifat, err = addrTable(msgs, ifindex)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return append(ifat4, ifat6...), nil return ifat, nil
} }
func addrTable(msgs []syscall.NetlinkMessage, ifindex int) ([]Addr, os.Error) { func addrTable(msgs []syscall.NetlinkMessage, ifindex int) ([]Addr, os.Error) {
......
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