mirror of https://github.com/vishvananda/netns
Added function UniqueId which returns a string that uniquely identifies (#14)
the namespace associated with a network handle.
This commit is contained in:
parent
1fec6582c0
commit
003a74c01d
13
netns.go
13
netns.go
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue