MCPcopy Index your code
hub / github.com/vishvananda/netns

github.com/vishvananda/netns @v0.0.5

Chat with this repo
repository ↗ · DeepWiki ↗ · release v0.0.5 ↗ · + Follow
42 symbols 77 edges 6 files 29 documented · 69% 107 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

netns - network namespaces in go

The netns package provides an ultra-simple interface for handling network namespaces in go. Changing namespaces requires elevated privileges, so in most cases this code needs to be run as root.

Local Build and Test

You can use go get command:

go get github.com/vishvananda/netns

Testing (requires root):

sudo -E go test github.com/vishvananda/netns

Example

package main

import (
    "fmt"
    "net"
    "runtime"

    "github.com/vishvananda/netns"
)

func main() {
    // Lock the OS Thread so we don't accidentally switch namespaces
    runtime.LockOSThread()
    defer runtime.UnlockOSThread()

    // Save the current network namespace
    origns, _ := netns.Get()
    defer origns.Close()

    // Create a new network namespace
    newns, _ := netns.New()
    defer newns.Close()

    // Do something with the network namespace
    ifaces, _ := net.Interfaces()
    fmt.Printf("Interfaces: %v\n", ifaces)

    // Switch back to the original namespace
    netns.Set(origns)
}

Core symbols most depended-on inside this repo

None
called by 5
nshandle_linux.go
Close
called by 4
nshandle_linux.go
Get
called by 3
netns_linux.go
GetFromPath
called by 3
netns_linux.go
Equal
called by 2
nshandle_linux.go
IsOpen
called by 2
nshandle_linux.go
New
called by 2
netns_linux.go
Set
called by 1
netns_linux.go

Shape

Function 30
Method 10
TypeAlias 2

Languages

Go100%

Modules by API surface

netns_linux.go14 symbols
netns_others.go11 symbols
nshandle_others.go7 symbols
nshandle_linux.go7 symbols
netns_linux_test.go3 symbols

For agents

$ claude mcp add netns \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page