mirror of
https://github.com/golang/go
synced 2024-11-19 23:34:40 -07:00
net: tweak variable declarations
R=golang-dev, bradfitz, rsc CC=golang-dev https://golang.org/cl/5617050
This commit is contained in:
parent
4b6cd239c5
commit
c2331bb77e
@ -18,8 +18,6 @@ import (
|
|||||||
// network interfaces. Otherwise it returns a mapping of a specific
|
// network interfaces. Otherwise it returns a mapping of a specific
|
||||||
// interface.
|
// interface.
|
||||||
func interfaceTable(ifindex int) ([]Interface, error) {
|
func interfaceTable(ifindex int) ([]Interface, error) {
|
||||||
var ift []Interface
|
|
||||||
|
|
||||||
tab, err := syscall.RouteRIB(syscall.NET_RT_IFLIST, ifindex)
|
tab, err := syscall.RouteRIB(syscall.NET_RT_IFLIST, ifindex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, os.NewSyscallError("route rib", err)
|
return nil, os.NewSyscallError("route rib", err)
|
||||||
@ -30,6 +28,7 @@ func interfaceTable(ifindex int) ([]Interface, error) {
|
|||||||
return nil, os.NewSyscallError("route message", err)
|
return nil, os.NewSyscallError("route message", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ift []Interface
|
||||||
for _, m := range msgs {
|
for _, m := range msgs {
|
||||||
switch v := m.(type) {
|
switch v := m.(type) {
|
||||||
case *syscall.InterfaceMessage:
|
case *syscall.InterfaceMessage:
|
||||||
@ -42,18 +41,16 @@ func interfaceTable(ifindex int) ([]Interface, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ift, nil
|
return ift, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newLink(m *syscall.InterfaceMessage) ([]Interface, error) {
|
func newLink(m *syscall.InterfaceMessage) ([]Interface, error) {
|
||||||
var ift []Interface
|
|
||||||
|
|
||||||
sas, err := syscall.ParseRoutingSockaddr(m)
|
sas, err := syscall.ParseRoutingSockaddr(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, os.NewSyscallError("route sockaddr", err)
|
return nil, os.NewSyscallError("route sockaddr", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ift []Interface
|
||||||
for _, s := range sas {
|
for _, s := range sas {
|
||||||
switch v := s.(type) {
|
switch v := s.(type) {
|
||||||
case *syscall.SockaddrDatalink:
|
case *syscall.SockaddrDatalink:
|
||||||
@ -75,7 +72,6 @@ func newLink(m *syscall.InterfaceMessage) ([]Interface, error) {
|
|||||||
ift = append(ift, ifi)
|
ift = append(ift, ifi)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ift, nil
|
return ift, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,8 +99,6 @@ func linkFlags(rawFlags int32) Flags {
|
|||||||
// for all network interfaces. Otherwise it returns addresses
|
// for all network interfaces. Otherwise it returns addresses
|
||||||
// for a specific interface.
|
// for a specific interface.
|
||||||
func interfaceAddrTable(ifindex int) ([]Addr, error) {
|
func interfaceAddrTable(ifindex int) ([]Addr, error) {
|
||||||
var ifat []Addr
|
|
||||||
|
|
||||||
tab, err := syscall.RouteRIB(syscall.NET_RT_IFLIST, ifindex)
|
tab, err := syscall.RouteRIB(syscall.NET_RT_IFLIST, ifindex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, os.NewSyscallError("route rib", err)
|
return nil, os.NewSyscallError("route rib", err)
|
||||||
@ -115,6 +109,7 @@ func interfaceAddrTable(ifindex int) ([]Addr, error) {
|
|||||||
return nil, os.NewSyscallError("route message", err)
|
return nil, os.NewSyscallError("route message", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ifat []Addr
|
||||||
for _, m := range msgs {
|
for _, m := range msgs {
|
||||||
switch v := m.(type) {
|
switch v := m.(type) {
|
||||||
case *syscall.InterfaceAddrMessage:
|
case *syscall.InterfaceAddrMessage:
|
||||||
@ -127,18 +122,16 @@ func interfaceAddrTable(ifindex int) ([]Addr, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ifat, nil
|
return ifat, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func newAddr(m *syscall.InterfaceAddrMessage) (Addr, error) {
|
func newAddr(m *syscall.InterfaceAddrMessage) (Addr, error) {
|
||||||
ifa := &IPNet{}
|
|
||||||
|
|
||||||
sas, err := syscall.ParseRoutingSockaddr(m)
|
sas, err := syscall.ParseRoutingSockaddr(m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, os.NewSyscallError("route sockaddr", err)
|
return nil, os.NewSyscallError("route sockaddr", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ifa := &IPNet{}
|
||||||
for i, s := range sas {
|
for i, s := range sas {
|
||||||
switch v := s.(type) {
|
switch v := s.(type) {
|
||||||
case *syscall.SockaddrInet4:
|
case *syscall.SockaddrInet4:
|
||||||
@ -166,6 +159,5 @@ func newAddr(m *syscall.InterfaceAddrMessage) (Addr, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ifa, nil
|
return ifa, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user