lib/packetgen/header/header_methods.rb in packetgen-0.3.0 vs lib/packetgen/header/header_methods.rb in packetgen-1.0.0
- old
+ new
@@ -1,5 +1,10 @@
+# This file is part of PacketGen
+# See https://github.com/sdaubert/packetgen for more informations
+# Copyright (C) 2016 Sylvain Daubert <sylvain.daubert@laposte.net>
+# This program is published under MIT license.
+
module PacketGen
module Header
# Mixin for various headers
# @author Sylvain Daubert
@@ -43,9 +48,20 @@
def ip_header(header)
hid = header_id(header)
iph = packet.headers[0...hid].reverse.find { |h| h.is_a? IP or h.is_a? IPv6 }
raise FormatError, 'no IP or IPv6 header in packet' if iph.nil?
iph
+ end
+
+ # Common inspect method for headers
+ # @return [String]
+ def inspect
+ str = Inspect.dashed_line(self.class, 2)
+ to_h.each do |attr, value|
+ next if attr == :body
+ str << Inspect.inspect_attribute(attr, value, 2)
+ end
+ str
end
end
end
end