Class: Iphdr
- Inherits:
-
Object
- Object
- Iphdr
- Defined in:
- lib/emtraceroute/ip.rb
Instance Attribute Summary collapse
-
#cksum ⇒ Object
This represents an IP packet header.
-
#daddr ⇒ Object
This represents an IP packet header.
-
#data ⇒ Object
This represents an IP packet header.
-
#dst ⇒ Object
This represents an IP packet header.
-
#frag ⇒ Object
This represents an IP packet header.
-
#hlen ⇒ Object
This represents an IP packet header.
-
#id ⇒ Object
This represents an IP packet header.
-
#length ⇒ Object
This represents an IP packet header.
-
#proto ⇒ Object
This represents an IP packet header.
-
#saddr ⇒ Object
This represents an IP packet header.
-
#src ⇒ Object
This represents an IP packet header.
-
#tos ⇒ Object
This represents an IP packet header.
-
#ttl ⇒ Object
This represents an IP packet header.
-
#version ⇒ Object
This represents an IP packet header.
Class Method Summary collapse
Instance Method Summary collapse
- #assemble ⇒ Object
-
#initialize(proto = Socket::IPPROTO_ICMP, src = '0.0.0.0', dst = nil) ⇒ Iphdr
constructor
A new instance of Iphdr.
Constructor Details
#initialize(proto = Socket::IPPROTO_ICMP, src = '0.0.0.0', dst = nil) ⇒ Iphdr
Returns a new instance of Iphdr.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/emtraceroute/ip.rb', line 9 def initialize(proto=Socket::IPPROTO_ICMP, src='0.0.0.0', dst=nil) @version = 4 @hlen = 5 @tos = 0 @length = 20 @id = $$ @frag = 0 @ttl = 255 @proto = proto @cksum = 0 @src = src @saddr = Socket.inet_aton(src) @dst = dst || '0.0.0.0' @daddr = Socket.inet_aton(@dst) @data = '' end |
Instance Attribute Details
#cksum ⇒ Object
This represents an IP packet header.
Iphdr#assemble packages the packet Iphdr.disassemble disassembles the packet
7 8 9 |
# File 'lib/emtraceroute/ip.rb', line 7 def cksum @cksum end |
#daddr ⇒ Object
This represents an IP packet header.
Iphdr#assemble packages the packet Iphdr.disassemble disassembles the packet
7 8 9 |
# File 'lib/emtraceroute/ip.rb', line 7 def daddr @daddr end |
#data ⇒ Object
This represents an IP packet header.
Iphdr#assemble packages the packet Iphdr.disassemble disassembles the packet
7 8 9 |
# File 'lib/emtraceroute/ip.rb', line 7 def data @data end |
#dst ⇒ Object
This represents an IP packet header.
Iphdr#assemble packages the packet Iphdr.disassemble disassembles the packet
7 8 9 |
# File 'lib/emtraceroute/ip.rb', line 7 def dst @dst end |
#frag ⇒ Object
This represents an IP packet header.
Iphdr#assemble packages the packet Iphdr.disassemble disassembles the packet
7 8 9 |
# File 'lib/emtraceroute/ip.rb', line 7 def frag @frag end |
#hlen ⇒ Object
This represents an IP packet header.
Iphdr#assemble packages the packet Iphdr.disassemble disassembles the packet
7 8 9 |
# File 'lib/emtraceroute/ip.rb', line 7 def hlen @hlen end |
#id ⇒ Object
This represents an IP packet header.
Iphdr#assemble packages the packet Iphdr.disassemble disassembles the packet
7 8 9 |
# File 'lib/emtraceroute/ip.rb', line 7 def id @id end |
#length ⇒ Object
This represents an IP packet header.
Iphdr#assemble packages the packet Iphdr.disassemble disassembles the packet
7 8 9 |
# File 'lib/emtraceroute/ip.rb', line 7 def length @length end |
#proto ⇒ Object
This represents an IP packet header.
Iphdr#assemble packages the packet Iphdr.disassemble disassembles the packet
7 8 9 |
# File 'lib/emtraceroute/ip.rb', line 7 def proto @proto end |
#saddr ⇒ Object
This represents an IP packet header.
Iphdr#assemble packages the packet Iphdr.disassemble disassembles the packet
7 8 9 |
# File 'lib/emtraceroute/ip.rb', line 7 def saddr @saddr end |
#src ⇒ Object
This represents an IP packet header.
Iphdr#assemble packages the packet Iphdr.disassemble disassembles the packet
7 8 9 |
# File 'lib/emtraceroute/ip.rb', line 7 def src @src end |
#tos ⇒ Object
This represents an IP packet header.
Iphdr#assemble packages the packet Iphdr.disassemble disassembles the packet
7 8 9 |
# File 'lib/emtraceroute/ip.rb', line 7 def tos @tos end |
#ttl ⇒ Object
This represents an IP packet header.
Iphdr#assemble packages the packet Iphdr.disassemble disassembles the packet
7 8 9 |
# File 'lib/emtraceroute/ip.rb', line 7 def ttl @ttl end |
#version ⇒ Object
This represents an IP packet header.
Iphdr#assemble packages the packet Iphdr.disassemble disassembles the packet
7 8 9 |
# File 'lib/emtraceroute/ip.rb', line 7 def version @version end |
Class Method Details
.disassemble(data) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/emtraceroute/ip.rb', line 35 def self.disassemble data ip = Iphdr.new pkt = data[0..11].unpack('CCnnnCCn') ip.version = (pkt.first >> 4 & 0x0f) ip.hlen = (pkt.first & 0x0f) ip.tos, ip.length, ip.id, ip.frag, ip.ttl, ip.proto, ip.cksum = pkt[1..-1] ip.saddr = data[12..15] ip.daddr = data[16..19] ip.src = Socket.inet_ntoa(ip.saddr) ip.dst = Socket.inet_ntoa(ip.daddr) ip end |