Class: Scriptroute::IPv6
Constant Summary collapse
- IPPROTO_ICMP6 =
58
- @@creators =
Hash.new
Constants inherited from IP
Scriptroute::IP::IPPROTO_TCP, Scriptroute::IP::IPPROTO_UDP
Instance Attribute Summary collapse
-
#ip6_dst ⇒ Object
Returns the value of attribute ip6_dst.
-
#ip6_flow ⇒ Object
Returns the value of attribute ip6_flow.
-
#ip6_hlim ⇒ Object
Returns the value of attribute ip6_hlim.
-
#ip6_src ⇒ Object
Returns the value of attribute ip6_src.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(p) ⇒ IPv6
constructor
A new instance of IPv6.
-
#ip_ttl=(ttl) ⇒ Object
for simplicity.
- #ipv6_unmarshal(str) ⇒ Object
- #marshal ⇒ Object
- #to_s ⇒ Object
Methods inherited from IP
Constructor Details
#initialize(p) ⇒ IPv6
Returns a new instance of IPv6.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/scriptroute/packets.rb', line 47 def initialize(p) if(p.is_a?(Fixnum)) then @ip6_src = @ip6_dst = @ip6flow = nil @ip6_hlim = 64 @ip6_nxt = p # actually, unlikely 7 or 13 are at the moment # either, but let's start here. $stderr.puts "unlikely v6 protocol header type #{p} is supported" unless [ 7, 13, 58 ].include?(p) else raise "need a next header type for constructing a v6 packet" end end |
Instance Attribute Details
#ip6_dst ⇒ Object
Returns the value of attribute ip6_dst.
31 32 33 |
# File 'lib/scriptroute/packets.rb', line 31 def ip6_dst @ip6_dst end |
#ip6_flow ⇒ Object
Returns the value of attribute ip6_flow.
30 31 32 |
# File 'lib/scriptroute/packets.rb', line 30 def ip6_flow @ip6_flow end |
#ip6_hlim ⇒ Object
Returns the value of attribute ip6_hlim.
30 31 32 |
# File 'lib/scriptroute/packets.rb', line 30 def ip6_hlim @ip6_hlim end |
#ip6_src ⇒ Object
Returns the value of attribute ip6_src.
30 31 32 |
# File 'lib/scriptroute/packets.rb', line 30 def ip6_src @ip6_src end |
Class Method Details
.creator(str) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/scriptroute/packets.rb', line 33 def IPv6.creator(str) flow, plen, nxt, hlim, saddr, daddr = str.unpack("Nncca16a16") if(@@creators[nxt]) then pkt = (@@creators[nxt]).call(str[40..40+plen]) pkt.ipv6_unmarshal(str) pkt else raise "unknown IPv6 next header #%d in %s" % [ nxt, str.unpack("H*") ] end end |
Instance Method Details
#ip_ttl=(ttl) ⇒ Object
for simplicity.
60 61 62 |
# File 'lib/scriptroute/packets.rb', line 60 def ip_ttl=(ttl) @ip6_hlim = ttl end |
#ipv6_unmarshal(str) ⇒ Object
43 44 45 46 |
# File 'lib/scriptroute/packets.rb', line 43 def ipv6_unmarshal(str) @ip6_flow, @ip6_plen, @ip6_nxt, @ip6_hlim, ip6_saddr, ip6_daddr = str.unpack("Nncca16a16") @ip6_src, @ip6_dst = [ip6_saddr, ip6_daddr].map { |addr| IPAddr.new_ntoh(addr) } end |
#marshal ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/scriptroute/packets.rb', line 81 def marshal # probably should force src/dst internal # representation to be IPAddr via accessor methods # rather than reconvert here. puts "unlikely you wanted zero hlim" unless @ip6_hlim and @ip6_hlim > 0 puts "unlikely you wanted no next protocol" unless @ip6_nxt and @ip6_nxt > 0 puts "unlikely you wanted nil payload len" unless ip_payload_len v6packet = [ 6 << 4, 0, 0, ip_payload_len, @ip6_nxt, @ip6_hlim, IPAddr.new(@ip6_src, Socket::AF_INET6).hton, IPAddr.new(@ip6_dst, Socket::AF_INET6).hton ].pack("ccnncca16a16") end |
#to_s ⇒ Object
92 93 94 |
# File 'lib/scriptroute/packets.rb', line 92 def to_s "%s -> %s hlim=%d" % [ (@ip6_src or "::0"), (@ip6_dst or "::0"), @ip6_hlim ] end |