From 7ffe40e0db5560f11c5a5a1e7e8fdb9eda06e641 Mon Sep 17 00:00:00 2001 From: litong Date: Thu, 18 Jul 2019 15:12:45 +0800 Subject: [PATCH] Add ifIndex support --- net/net.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/net.go b/net/net.go index fce86c7..f724d7f 100644 --- a/net/net.go +++ b/net/net.go @@ -26,7 +26,6 @@ type IOCountersStat struct { Dropout uint64 `json:"dropout"` // total number of outgoing packets which were dropped (always 0 on OSX and BSD) Fifoin uint64 `json:"fifoin"` // total number of FIFO buffers errors while receiving Fifoout uint64 `json:"fifoout"` // total number of FIFO buffers errors while sending - } // Addr is implemented compatibility to psutil @@ -58,6 +57,7 @@ type InterfaceAddr struct { } type InterfaceStat struct { + Index int `json:"index"` MTU int `json:"mtu"` // maximum transmission unit Name string `json:"name"` // e.g., "en0", "lo0", "eth0.100" HardwareAddr string `json:"hardwareaddr"` // IEEE MAC-48, EUI-48 and EUI-64 form @@ -121,6 +121,7 @@ func InterfacesWithContext(ctx context.Context) ([]InterfaceStat, error) { for _, ifi := range is { var flags []string + if ifi.Flags&net.FlagUp != 0 { flags = append(flags, "up") } @@ -138,6 +139,7 @@ func InterfacesWithContext(ctx context.Context) ([]InterfaceStat, error) { } r := InterfaceStat{ + Index: ifi.Index, Name: ifi.Name, MTU: ifi.MTU, HardwareAddr: ifi.HardwareAddr.String(),