mnetlink

package
v0.0.0-...-b320325 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	EInvalidAttribute = errors.New("Invalid netlink attribute")
)
View Source
var (
	EInvalidMessage = errors.New("Invalid netlink message")
)

Functions

func AlignAttr

func AlignAttr(len int) int

func AlignMsg

func AlignMsg(len int) int

func Bytes2Str

func Bytes2Str(b []byte) string

func Hbo

func Hbo() binary.ByteOrder

func HostByteOrder

func HostByteOrder() (res binary.ByteOrder)

Detect host byteorder (used by netlink)

func Str2Bytes

func Str2Bytes(s string) []byte

Types

type Attr

type Attr struct {
	Type uint16
	Len  uint16
	// contains filtered or unexported fields
}

func (Attr) GetData

func (a Attr) GetData() []byte

func (Attr) GetDataAttrs

func (a Attr) GetDataAttrs() (attrs []Attr, err error)

func (Attr) GetDataDump

func (a Attr) GetDataDump() string

func (Attr) GetDataString

func (a Attr) GetDataString() string

func (Attr) GetDataUint16

func (a Attr) GetDataUint16() uint16

func (Attr) GetDataUint32

func (a Attr) GetDataUint32() uint32

func (Attr) GetDataUint8

func (a Attr) GetDataUint8() uint8

func (*Attr) MarshalBinary

func (a *Attr) MarshalBinary() (data []byte, err error)

func (*Attr) SetData

func (a *Attr) SetData(data []byte) (err error)

func (*Attr) UnmarshalBinary

func (a *Attr) UnmarshalBinary(data []byte) (err error)

type Client

type Client struct {
	Family int
	// contains filtered or unexported fields
}

func NewNl

func NewNl(family int) (res *Client, err error)

func (*Client) AddGroupMembership

func (c *Client) AddGroupMembership(groupid int) (err error)

func (*Client) Close

func (c *Client) Close() (err error)

func (*Client) DropGroupMembership

func (c *Client) DropGroupMembership(groupid int) (err error)

func (*Client) Open

func (c *Client) Open() (err error)

func (*Client) Read

func (c *Client) Read() (res []byte)
func (c *Client) Receive2() (msgs []Message, err error) {
	for {
		//fmt.Println("Reading")
		raw_in := c.Read()
		msg := Message{}
		msg.UnmarshalBinary(raw_in)

		if msg.IsTypeError() {
			return nil,errors.New(fmt.Sprintf("Error response: %+v %+v", msg.GetData(), msg.GetErrNo()))

		}

		msgs = append(msgs, msg)
		fmt.Printf("Received raw: \n%v\n", hex.Dump(raw_in))
		fmt.Printf("Received %+v\nData:\n%+v\n", msg, hex.Dump(msg.data))

		// check if last message
		if msg.IsTypeDone() || !msg.HasFlagMulti() {
			break
		}
	}
	return
}

func (*Client) Receive

func (c *Client) Receive() (msgs []Message, err error)

func (*Client) Send

func (c *Client) Send(msg Message) (err error)

func (*Client) Sendmsg

func (c *Client) Sendmsg(p, oob []byte, to unix.Sockaddr, flags int) (err error)

type Message

type Message struct {
	Len   uint32
	Type  uint16
	Flags uint16
	Seq   uint32
	Pid   uint32
	// contains filtered or unexported fields
}

func (Message) GetData

func (m Message) GetData() []byte

func (Message) GetErrNo

func (m Message) GetErrNo() error

func (Message) HasFlagAck

func (m Message) HasFlagAck() bool

func (Message) HasFlagDump

func (m Message) HasFlagDump() bool

func (Message) HasFlagMulti

func (m Message) HasFlagMulti() bool

func (Message) IsTypeDone

func (m Message) IsTypeDone() bool

func (Message) IsTypeError

func (m Message) IsTypeError() bool

func (Message) IsTypeNoop

func (m Message) IsTypeNoop() bool

func (*Message) MarshalBinary

func (m *Message) MarshalBinary() (data []byte, err error)

func (*Message) SetData

func (m *Message) SetData(data []byte) (err error)

func (*Message) UnmarshalBinary

func (m *Message) UnmarshalBinary(src []byte) (err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL