Class: Netlink::NlMsgHdr

Inherits:
Object
  • Object
show all
Defined in:
lib/netlink/nlmsghdr.rb

Constant Summary collapse

SIZE =

Size of a nlmsgheader

16
PACK_STR =

nlmsghdr pack string

'LSSLL'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(length, type, flags, seq, pid) ⇒ NlMsgHdr

Returns a new instance of NlMsgHdr.

Parameters:

  • length (Integer)

    message length

  • type (Integer)

    message type

  • flags (Integer)

    message flags

  • seq (Integer)

    message sequence number

  • pid (Integer)

    message port id



26
27
28
29
30
31
32
# File 'lib/netlink/nlmsghdr.rb', line 26

def initialize(length, type, flags, seq, pid)
  @length = length
  @type = type
  @flags = flags
  @seq = seq
  @pid = pid
end

Instance Attribute Details

#flagsObject (readonly)

Returns the value of attribute flags.



6
7
8
# File 'lib/netlink/nlmsghdr.rb', line 6

def flags
  @flags
end

#lengthObject

Returns the value of attribute length.



5
6
7
# File 'lib/netlink/nlmsghdr.rb', line 5

def length
  @length
end

#pidObject (readonly)

Returns the value of attribute pid.



6
7
8
# File 'lib/netlink/nlmsghdr.rb', line 6

def pid
  @pid
end

#seqObject (readonly)

Returns the value of attribute seq.



6
7
8
# File 'lib/netlink/nlmsghdr.rb', line 6

def seq
  @seq
end

#typeObject (readonly)

Returns the value of attribute type.



6
7
8
# File 'lib/netlink/nlmsghdr.rb', line 6

def type
  @type
end

Class Method Details

.from_string(str) ⇒ NlMsgHdr

Create a nlmsghdr from a pack string

Parameters:

  • str (String)

Returns:



16
17
18
19
# File 'lib/netlink/nlmsghdr.rb', line 16

def self.from_string(str)
  ary = str.unpack(PACK_STR)
  new(*ary)
end

Instance Method Details

#compute_length(mesg) ⇒ Integer

Compute length field from mesg

Parameters:

  • mesg (String)

Returns:

  • (Integer)


42
43
44
# File 'lib/netlink/nlmsghdr.rb', line 42

def compute_length(mesg)
  @length = SIZE + mesg.size
end

#to_sString

Returns:

  • (String)


35
36
37
# File 'lib/netlink/nlmsghdr.rb', line 35

def to_s
  [@length, @type, @flags, @seq, @pid].pack(PACK_STR)
end