class Scriptroute::IPv6
Constants
- IPPROTO_ICMP6
Attributes
ip6_dst[R]
ip6_flow[RW]
ip6_hlim[RW]
ip6_src[RW]
Public Class Methods
creator(str)
click to toggle source
# 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
new(p)
click to toggle source
# 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
Public Instance Methods
ip6_dst=(name_or_address)
click to toggle source
# File lib/scriptroute/packets.rb, line 63 def ip6_dst=(name_or_address) if name_or_address.is_a?(IPAddr) then if name_or_address.ipv4? then @ip6_dst = name_or_address.ipv4_mapped # try to use it. else @ip6_dst = name_or_address end elsif Resolv::IPv6::Regex =~ name_or_address then @ip6_dst = IPAddr.new(name_or_address, Socket::AF_INET6) else r = Resolv::DNS.new.getresource(name_or_address, Resolv::DNS::Resource::IN::AAAA) if r then @ip6_dst = IPAddr.new(r.address.to_s, Socket::AF_INET6) else raise "failed to lookup #{name_or_address} into a v6 address" end end end
ip_ttl=(ttl)
click to toggle source
for simplicity.
# File lib/scriptroute/packets.rb, line 60 def ip_ttl=(ttl) @ip6_hlim = ttl end
ipv6_unmarshal(str)
click to toggle source
# 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
to_s()
click to toggle source
# 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
Private Instance Methods
marshal()
click to toggle source
# 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