MCPcopy Create free account
hub / github.com/containerd/nerdctl / InspectNetNS

Function InspectNetNS

pkg/containerinspector/containerinspector_linux.go:30–64  ·  view source on GitHub ↗
(ctx context.Context, pid int)

Source from the content-addressed store, hash-verified

28)
29
30func InspectNetNS(ctx context.Context, pid int) (*native.NetNS, error) {
31 nsPath := fmt.Sprintf("/proc/%d/ns/net", pid)
32 res := &native.NetNS{}
33 fn := func(_ ns.NetNS) error {
34 intf, err := net.Interfaces()
35 if err != nil {
36 return err
37 }
38 res.Interfaces = make([]native.NetInterface, len(intf))
39 for i, f := range intf {
40 x := native.NetInterface{
41 Interface: f,
42 }
43 if f.HardwareAddr != nil {
44 x.HardwareAddr = f.HardwareAddr.String()
45 }
46 if x.Interface.Flags.String() != "0" {
47 x.Flags = strings.Split(x.Interface.Flags.String(), "|")
48 }
49 if addrs, err := x.Interface.Addrs(); err == nil {
50 x.Addrs = make([]string, len(addrs))
51 for j, a := range addrs {
52 x.Addrs[j] = a.String()
53 }
54 }
55 res.Interfaces[i] = x
56 }
57 res.PrimaryInterface = determinePrimaryInterface(res.Interfaces)
58 return nil
59 }
60 if err := ns.WithNetNSPath(nsPath, fn); err != nil {
61 return nil, err
62 }
63 return res, nil
64}
65
66// determinePrimaryInterface returns a net.Interface.Index value, not a slice index.
67// Zero means no primary interface was detected.

Callers 2

collectFunction · 0.92
InspectFunction · 0.70

Calls 2

StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…