Skip to content

c-binding free API for golang to communicate with the conntrack subsystem

License

Notifications You must be signed in to change notification settings

open-ch/go-conntrack

 
 

Repository files navigation

go-conntrack Build Status GoDoc

This is go-conntrack and it is written in golang. It provides a C-binding free API to the conntrack subsystem of the Linux kernel.

Example

package main
import (
    "fmt"

    ct "github.com/florianl/go-conntrack"
)

func main() {
    // Opens the socket for the communication with the subsystem
    nfct, err := ct.Open()
    if err != nil {
        fmt.Println("Could not open socket:", err)
        return
    }
    defer nfct.Close()

    // Get all IPv4 sessions
    sessions, err := nfct.Dump(ct.Ct, ct.CtIPv4)
    if err != nil {
        fmt.Println("Could not dump sessions:", err)
        return
    }

    for _, x := range sessions {
        oSrcIP, _ := x.OrigSrcIP()
        oDstIP, _ := x.OrigDstIP()
        // Print source and destination for each IPv4 session
        fmt.Printf("src: %s\tdst: %s \n", oSrcIP, oDstIP)
    }
}

For documentation and more examples please take a look at GoDoc

About

c-binding free API for golang to communicate with the conntrack subsystem

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%