Class: Nl::Protocols::Raw
- Inherits:
-
Object
- Object
- Nl::Protocols::Raw
- Defined in:
- lib/nl/protocols/raw.rb
Overview
The raw Netlink protocol
Direct Known Subclasses
Defined Under Namespace
Modules: DataTypes Classes: Ack, AttributeSet, Done, Message
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#protonum ⇒ Object
readonly
Returns the value of attribute protonum.
Instance Method Summary collapse
- #decode_message(decoder, message_class) ⇒ Object
- #encode_message(encoder, message) ⇒ Object
- #exchange_message(socket, type, request_class, reply_class, args) ⇒ Object
-
#initialize(name, protonum) ⇒ Raw
constructor
A new instance of Raw.
- #recv_message(socket, seq_pid, message_class) ⇒ Object
- #send_message(socket, message) ⇒ Object
Constructor Details
#initialize(name, protonum) ⇒ Raw
Returns a new instance of Raw.
15 16 17 18 |
# File 'lib/nl/protocols/raw.rb', line 15 def initialize(name, protonum) @name = name @protonum = protonum end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/nl/protocols/raw.rb', line 13 def name @name end |
#protonum ⇒ Object (readonly)
Returns the value of attribute protonum.
13 14 15 |
# File 'lib/nl/protocols/raw.rb', line 13 def protonum @protonum end |
Instance Method Details
#decode_message(decoder, message_class) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/nl/protocols/raw.rb', line 24 def (decoder, ) header = NlMsgHdr.decode(decoder) decoder.limit(header.len - Core::NLMSG_HDRLEN) do .decode(decoder, header) end end |
#encode_message(encoder, message) ⇒ Object
20 21 22 |
# File 'lib/nl/protocols/raw.rb', line 20 def (encoder, ) .encode(encoder) end |
#exchange_message(socket, type, request_class, reply_class, args) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/nl/protocols/raw.rb', line 80 def (socket, type, request_class, reply_class, args) flags = Core::NLM_F_REQUEST flags |= type == :dump ? Core::NLM_F_DUMP : Core::NLM_F_ACK request = request_class.from_params(args) request.nlmsg_header.flags = flags seq_pid = (socket, request) result = [] unless block_given? done = false begin (socket, seq_pid, reply_class) do || case when Done, Ack done = true when Exception raise else if block_given? yield else result << end end end end until done unless block_given? type == :dump ? result : result.first end end |
#recv_message(socket, seq_pid, message_class) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/nl/protocols/raw.rb', line 39 def (socket, seq_pid, ) data, = socket.recvmsg decoder = Decoder.new(IO::Buffer.for(data)) while decoder.available?(Core::NLMSG_HDRLEN) header = Core::NlMsgHdr.decode(decoder) decoder.align_to(Core::NLMSG_ALIGNTO) raise binding.irb unless [header.seq, header.pid] == seq_pid if header.type < Core::NLMSG_MIN_TYPE # Control messages case header.type when Core::NLMSG_ERROR errno = decoder.get_value(Endian::Host::SINT) if errno == 0 yield Ack.new else yield SystemCallError.new(-errno) end decoder.skip(header.len - Core::NLMSG_HDRLEN - 4) when Core::NLMSG_DONE yield Done.new decoder.skip(header.len - Core::NLMSG_HDRLEN) else # just ignore NLMSG_NOOP and other unknown control messages decoder.skip(header.len - Core::NLMSG_HDRLEN) end else # Subsystem-specific messages decoder.limit(header.len - Core::NLMSG_HDRLEN) do decoder.align_to(Core::NLMSG_ALIGNTO) yield .decode(decoder, header) end end end end |