From 003a74c01d651d99053d2bc791995866dce2be15 Mon Sep 17 00:00:00 2001 From: Ashok Mudukutore Date: Fri, 29 Apr 2016 23:36:46 -0600 Subject: [PATCH] Added function UniqueId which returns a string that uniquely identifies (#14) the namespace associated with a network handle. --- netns.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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