Added function UniqueId which returns a string that uniquely identifies (#14)

the namespace associated with a network handle.
This commit is contained in:
Ashok Mudukutore 2016-04-29 23:36:46 -06:00 committed by Vish Ishaya
parent 1fec6582c0
commit 003a74c01d
1 changed files with 13 additions and 0 deletions

View File

@ -46,6 +46,19 @@ func (ns NsHandle) String() string {
return fmt.Sprintf("NS(%d: %d, %d)", ns, s.Dev, s.Ino) 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. // IsOpen returns true if Close() has not been called.
func (ns NsHandle) IsOpen() bool { func (ns NsHandle) IsOpen() bool {
return ns != -1 return ns != -1