diff --git a/netns.go b/netns.go index df04d2a..1ba6b26 100644 --- a/netns.go +++ b/netns.go @@ -46,6 +46,19 @@ func (ns NsHandle) String() string { return fmt.Sprintf("NS(%d: %d, %d)", ns, s.Dev, s.Ino) } +// UniqueId returns a string which uniquely identifies the namespace +// associated with the network handle. +func (ns NsHandle) UniqueId() string { + var s syscall.Stat_t + if ns == -1 { + return "NS(none)" + } + if err := syscall.Fstat(int(ns), &s); err != nil { + return "NS(unknown)" + } + return fmt.Sprintf("NS(%d:%d)", s.Dev, s.Ino) +} + // IsOpen returns true if Close() has not been called. func (ns NsHandle) IsOpen() bool { return ns != -1