blob: f6886f8d3e3f5e662c86992fad7f51f428ba21e1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
package netboot
import (
"log"
"github.com/jsimonetti/rtnetlink"
)
// getOperState returns the operational state for the given interface index.
func getOperState(iface int) (rtnetlink.OperationalState, error) {
conn, err := rtnetlink.Dial(nil)
if err != nil {
return 0, err
}
defer func() {
err := conn.Close()
if err != nil {
log.Printf("failed to close rtnetlink connection: %v", err)
}
}()
msg, err := conn.Link.Get(uint32(iface))
if err != nil {
return 0, err
}
return msg.Attributes.OperationalState, nil
}
|