Class: Arp
Constant Summary collapse
- HwSrc =
Class.new(Ethernet::Address)
- HwTgt =
Class.new(Ethernet::Address)
- ProtoSrc =
Class.new(IPAddr)
- ProtoTgt =
Class.new(IPAddr)
Instance Attribute Summary collapse
-
#hw_src ⇒ Object
readonly
Returns the value of attribute hw_src.
-
#hw_tgt ⇒ Object
readonly
Returns the value of attribute hw_tgt.
-
#opcode ⇒ Object
readonly
Returns the value of attribute opcode.
-
#proto_src ⇒ Object
readonly
Returns the value of attribute proto_src.
-
#proto_tgt ⇒ Object
readonly
Returns the value of attribute proto_tgt.
Class Method Summary collapse
Instance Method Summary collapse
- #encode ⇒ Object
-
#initialize(arg = {}) ⇒ Arp
constructor
A new instance of Arp.
- #parse(s) ⇒ Object
- #reply(hw_src) ⇒ Object
- #to_s ⇒ Object
Methods included from Args
Constructor Details
Instance Attribute Details
#hw_src ⇒ Object (readonly)
Returns the value of attribute hw_src.
15 16 17 |
# File 'lib/arp.rb', line 15 def hw_src @hw_src end |
#hw_tgt ⇒ Object (readonly)
Returns the value of attribute hw_tgt.
15 16 17 |
# File 'lib/arp.rb', line 15 def hw_tgt @hw_tgt end |
#opcode ⇒ Object (readonly)
Returns the value of attribute opcode.
15 16 17 |
# File 'lib/arp.rb', line 15 def opcode @opcode end |
#proto_src ⇒ Object (readonly)
Returns the value of attribute proto_src.
15 16 17 |
# File 'lib/arp.rb', line 15 def proto_src @proto_src end |
#proto_tgt ⇒ Object (readonly)
Returns the value of attribute proto_tgt.
15 16 17 |
# File 'lib/arp.rb', line 15 def proto_tgt @proto_tgt end |
Class Method Details
Instance Method Details
#encode ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/arp.rb', line 28 def encode s=[] hw_src = @hw_src.encode proto_src = @proto_src.hton hw_tgt = @hw_tgt.encode proto_tgt = @proto_tgt.hton s << eth_hdr s << [1,0x0800, 6, 4, @opcode, hw_src, proto_src, hw_tgt, proto_tgt].pack("nnCCn"+"a6a4"*2) s.join end |
#parse(s) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/arp.rb', line 39 def parse(s) s.slice!(0,14) if s.size>32 htype, ptype, hlen, plen, opcode = s.unpack('nnccn') hw_src, proto_src, hw_tgt, proto_tgt = s[8..-1].unpack("a#{hlen}a#{plen}"*2) raise RuntimeError, "Unsupported Hardware Type" unless htype == 1 && ptype == 0x0800 @hw_src = HwSrc.new(hw_src) @hw_tgt = HwTgt.new(hw_tgt) @proto_src = ProtoSrc.ntop(proto_src) @proto_tgt = ProtoTgt.ntop(proto_tgt) @opcode = opcode end |
#reply(hw_src) ⇒ Object
58 59 60 61 |
# File 'lib/arp.rb', line 58 def reply(hw_src) self.class.new_reply :hw_src=> hw_src, :proto_src=> "#{@proto_tgt}", :hw_tgt => "#{@hw_src}", :proto_tgt => "#{@proto_src}" end |
#to_s ⇒ Object
51 52 53 54 55 56 |
# File 'lib/arp.rb', line 51 def to_s case @opcode when 1 ; "ARP, Request who-has #{@proto_tgt} tell #{@proto_src}" when 2 ; "ARP, Reply #{@proto_src} is-at #{@hw_src}" end end |