File: conn.go

package info (click to toggle)
golang-github-jsimonetti-rtnetlink 2.0.5-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,284 kB
  • sloc: makefile: 2
file content (33 lines) | stat: -rw-r--r-- 790 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Package rtnl provides a convenient API on top of the rtnetlink library.
package rtnl

import (
	"github.com/jsimonetti/rtnetlink/v2"
	"github.com/mdlayher/netlink"
)

// Conn represents the underlying netlink connection
type Conn struct {
	Conn *rtnetlink.Conn // a route netlink connection
}

// Dial the netlink socket. Establishes a new connection. The typical initialisation is:
//
//	conn, err := rtnl.Dial(nil)
//	if err != nil {
//		log.Fatal("can't establish netlink connection: ", err)
//	}
//	defer conn.Close()
//	// use conn for your calls
func Dial(cfg *netlink.Config) (*Conn, error) {
	conn, err := rtnetlink.Dial(cfg)
	if err != nil {
		return nil, err
	}
	return &Conn{Conn: conn}, nil
}

// Close the connection.
func (c *Conn) Close() error {
	return c.Conn.Close()
}