import "github.com/mickep76/netlink"
interfaces.go netlink.go parse_newlink.go
const (
// NetlinkRoute return socket descriptor.
NetlinkRoute = 0
// RtmGrpLink Rtnetlink multicast group.
RtmGrpLink = 0x1
)
func Interfaces() ([]Interface, error)
Interfaces connect using rtnetlink and retrieve all network interfaces.
type Conn struct {
Family int
Groups uint32
FileDescr int
SocketAddr *unix.SockaddrNetlink
Pid uint32
}
Conn provides an interface for connecting to netlink socket.
func Dial(family int, groups uint32) (*Conn, error)
Dial netlink socket.
func (c *Conn) Bind() error
Bind to netlink socket.
func (c *Conn) Close() error
Close netlink socket.
func (c *Conn) Receive() ([]syscall.NetlinkMessage, error)
Receive messages from netlink socket.
type Flags uint
Flags type for network interface state.
const (
// FlagUp interface is up (administratively).
FlagUp Flags = 1 << iota
// FlagBroadcast broadcast address valid.
FlagBroadcast
// FlagDebug turn on debugging.
FlagDebug
// FlagLoopback is a loopback net.
FlagLoopback
// FlagPointToPoint interface is has p-p link.
FlagPointToPoint
// FlagNoTrailers avoid use of trailers.
FlagNoTrailers
// FlagRunning interface RFC2863 OPER_UP.
FlagRunning
// FlagNoArp no ARP protocol.
FlagNoArp
// FlagPromisc receive all packets.
FlagPromisc
// FlagAllMulti receive all multicast packets.
FlagAllMulti
// FlagMaster master of a load balancer.
FlagMaster
// FlagSlave slave of a load balancer.
FlagSlave
// FlagMulticast supports multicast.
FlagMulticast
// FlagPortSel can set media type.
FlagPortSel
// FlagAutoMedia auto media select active.
FlagAutoMedia
// FlagDynamic dialup device with changing addresses.
FlagDynamic
// FlagLowerUp driver signals L1 up.
FlagLowerUp
// FlagDormant driver signals dormant.
FlagDormant
// FlagEcho echo sent packets.
FlagEcho
)
func (Flags) MarshalJSON
func (f Flags) MarshalJSON() ([]byte, error)
MarshalJSON marshal flags into JSON.
func (f Flags) Slice() []string
Slice return a list of all flags.
func (f Flags) String() string
String return a string of all flags.
type HwAddr []byte
HwAddr hardware address type.
func (HwAddr) MarshalJSON
func (a HwAddr) MarshalJSON() ([]byte, error)
MarshalJSON marshal hardware address into JSON.
func (a HwAddr) String() string
type Interface struct {
Index int `json:"index"`
MTU int `json:"mtu"`
Name string `json:"name"`
HwAddr HwAddr `json:"hwaddr,omitempty"`
Flags Flags `json:"flags"`
NetInterface *net.Interface `json:"-"`
}
Interface provides information about a network interface.
func ParseNewLink(ifim *syscall.IfInfomsg, attrs []syscall.NetlinkRouteAttr) *Interface
ParseNewLink parse interface info message.
- Parse messages based on Go package net.
- Socket connection based on Go package mdlayher/netlink.