Class: Nl::Raw::NlMsgHdr

Inherits:
Struct
  • Object
show all
Defined in:
nl/lib/nl/raw/wire.rb,
nl/lib/nl/raw/wire.rb

Overview

Fixed-format metadata header prepended to every Netlink message.

This corresponds to Linux's struct nlmsghdr.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#flags ⇒ Integer

Returns bitwise combination of NLM_F_ flags.

Returns:

  • (Integer) —

    bitwise combination of NLM_F_ flags



62
63
64
65
66
67
68
# File 'nl/lib/nl/raw/wire.rb', line 62

NlMsgHdr = Struct.new(
  :len, #: Integer
  :type, #: Integer
  :flags, #: Integer
  :seq, #: Integer
  :pid, #: Integer
)

#len ⇒ Integer

Returns message length in bytes, including this header.

Returns:

  • (Integer) —

    message length in bytes, including this header



62
63
64
65
66
67
68
# File 'nl/lib/nl/raw/wire.rb', line 62

NlMsgHdr = Struct.new(
  :len, #: Integer
  :type, #: Integer
  :flags, #: Integer
  :seq, #: Integer
  :pid, #: Integer
)

#pid ⇒ Integer

Returns sender's Netlink port ID.

Returns:

  • (Integer) —

    sender's Netlink port ID



62
63
64
65
66
67
68
# File 'nl/lib/nl/raw/wire.rb', line 62

NlMsgHdr = Struct.new(
  :len, #: Integer
  :type, #: Integer
  :flags, #: Integer
  :seq, #: Integer
  :pid, #: Integer
)

#seq ⇒ Integer

Returns sequence number used to correlate requests and replies.

Returns:

  • (Integer) —

    sequence number used to correlate requests and replies



62
63
64
65
66
67
68
# File 'nl/lib/nl/raw/wire.rb', line 62

NlMsgHdr = Struct.new(
  :len, #: Integer
  :type, #: Integer
  :flags, #: Integer
  :seq, #: Integer
  :pid, #: Integer
)

#type ⇒ Integer

Returns message content type.

Returns:

  • (Integer) —

    message content type



62
63
64
65
66
67
68
# File 'nl/lib/nl/raw/wire.rb', line 62

NlMsgHdr = Struct.new(
  :len, #: Integer
  :type, #: Integer
  :flags, #: Integer
  :seq, #: Integer
  :pid, #: Integer
)

Class Method Details

.decode(decoder) ⇒ NlMsgHdr

Decodes a header from the decoder's current position.

Parameters:

  • decoder (Decoder) —

    the source decoder

Returns:



85
86
87
88
89
# File 'nl/lib/nl/raw/wire.rb', line 85

def self.decode(decoder)
  obj = new(*decoder.get_values(FORMAT))
  decoder.align_to(Constants::NLMSG_ALIGNTO)
  obj
end

Instance Method Details

#encode(encoder) ⇒ void

This method returns an undefined value.

Encodes this header at the encoder's current position.

Parameters:

  • encoder (Encoder) —

    the destination encoder



96
97
98
99
100
# File 'nl/lib/nl/raw/wire.rb', line 96

def encode(encoder)
  encoder.reserve(Constants::NLMSG_HDRLEN)
  encoder.put_values(FORMAT, to_a)
  encoder.align_to(Constants::NLMSG_ALIGNTO)
end