Module: PacketGen::Header

Defined in:
lib/packetgen/header.rb,
lib/packetgen/header/ip.rb,
lib/packetgen/header/arp.rb,
lib/packetgen/header/dns.rb,
lib/packetgen/header/dns.rb,
lib/packetgen/header/eap.rb,
lib/packetgen/header/eth.rb,
lib/packetgen/header/gre.rb,
lib/packetgen/header/llc.rb,
lib/packetgen/header/mld.rb,
lib/packetgen/header/tcp.rb,
lib/packetgen/header/tcp.rb,
lib/packetgen/header/udp.rb,
lib/packetgen/header/base.rb,
lib/packetgen/header/dhcp.rb,
lib/packetgen/header/icmp.rb,
lib/packetgen/header/igmp.rb,
lib/packetgen/header/ipv6.rb,
lib/packetgen/header/ipv6.rb,
lib/packetgen/header/mdns.rb,
lib/packetgen/header/snmp.rb,
lib/packetgen/header/tftp.rb,
lib/packetgen/header/bootp.rb,
lib/packetgen/header/dot11.rb,
lib/packetgen/header/dot1q.rb,
lib/packetgen/header/dot1x.rb,
lib/packetgen/header/mldv2.rb,
lib/packetgen/header/dhcpv6.rb,
lib/packetgen/header/dns/rr.rb,
lib/packetgen/header/icmpv6.rb,
lib/packetgen/header/igmpv3.rb,
lib/packetgen/header/ospfv2.rb,
lib/packetgen/header/ospfv3.rb,
lib/packetgen/header/dns/opt.rb,
lib/packetgen/header/eap/md5.rb,
lib/packetgen/header/eap/tls.rb,
lib/packetgen/header/ip/addr.rb,
lib/packetgen/header/dns/name.rb,
lib/packetgen/header/eap/fast.rb,
lib/packetgen/header/eap/ttls.rb,
lib/packetgen/header/asn1_base.rb,
lib/packetgen/header/igmpv3/mq.rb,
lib/packetgen/header/igmpv3/mr.rb,
lib/packetgen/header/ip/option.rb,
lib/packetgen/header/ipv6/addr.rb,
lib/packetgen/header/mldv2/mlq.rb,
lib/packetgen/header/mldv2/mlr.rb,
lib/packetgen/header/dns/option.rb,
lib/packetgen/header/dot11/data.rb,
lib/packetgen/header/http/verbs.rb,
lib/packetgen/header/ip/options.rb,
lib/packetgen/header/ospfv2/lsa.rb,
lib/packetgen/header/ospfv3/lsa.rb,
lib/packetgen/header/tcp/option.rb,
lib/packetgen/header/dhcp/option.rb,
lib/packetgen/header/dhcpv6/duid.rb,
lib/packetgen/header/tcp/options.rb,
lib/packetgen/header/dhcp/options.rb,
lib/packetgen/header/dhcpv6/relay.rb,
lib/packetgen/header/dns/question.rb,
lib/packetgen/header/http/headers.rb,
lib/packetgen/header/http/request.rb,
lib/packetgen/header/ospfv2/hello.rb,
lib/packetgen/header/ospfv3/hello.rb,
lib/packetgen/header/dhcpv6/option.rb,
lib/packetgen/header/dns/qdsection.rb,
lib/packetgen/header/dns/rrsection.rb,
lib/packetgen/header/dot11/control.rb,
lib/packetgen/header/dot11/element.rb,
lib/packetgen/header/http/response.rb,
lib/packetgen/header/ospfv2/ls_ack.rb,
lib/packetgen/header/ospfv3/ls_ack.rb,
lib/packetgen/header/dhcpv6/options.rb,
lib/packetgen/header/dot11/sub_mngt.rb,
lib/packetgen/header/ipv6/extension.rb,
lib/packetgen/header/ipv6/hop_by_hop.rb,
lib/packetgen/header/dot11/management.rb,
lib/packetgen/header/ospfv2/ls_update.rb,
lib/packetgen/header/ospfv3/ls_update.rb,
lib/packetgen/header/ospfv2/ls_request.rb,
lib/packetgen/header/ospfv2/lsa_header.rb,
lib/packetgen/header/ospfv3/ls_request.rb,
lib/packetgen/header/ospfv3/lsa_header.rb,
lib/packetgen/header/ospfv3/ipv6_prefix.rb,
lib/packetgen/header/igmpv3/group_record.rb,
lib/packetgen/header/ospfv2/db_description.rb,
lib/packetgen/header/ospfv3/db_description.rb,
lib/packetgen/header/mldv2/mcast_address_record.rb

Overview

Namespace for protocol header classes.

This namespace handles all buitlin headers, such as IP or TCP.

Add a foreign header class

PacketGen permits adding you own header classes. First, define the new header class. By example:

module MyModule
  class MyHeader < PacketGen::Header::Base
    define_field :field1, PacketGen::Types::Int32
    define_field :field2, PacketGen::Types::Int32
  end
 end

Then, class must be declared to PacketGen:

PacketGen::Header.add_class MyModule::MyHeader

Finally, bindings must be declared:

# bind MyHeader as IP protocol number 254 (needed by Packet#parse and Packet#add)
PacketGen::Header::IP.bind_header MyModule::MyHeader, protocol: 254

And use it:

pkt = Packet.gen('IP').add('MyHeader', field1: 0x12345678)
pkt.myheader.field2.read 0x01

Author:

  • Sylvain Daubert

Defined Under Namespace

Modules: HTTP, MLDv2 Classes: ARP, ASN1Base, BOOTP, Base, DHCP, DHCPv6, DNS, DissectError, Dot11, Dot1q, Dot1x, EAP, Eth, GRE, ICMP, ICMPv6, IGMP, IGMPv3, IP, IPv6, LLC, MDNS, MLD, OSPFv2, OSPFv3, PPI, RadioTap, SNAP, SNMP, TCP, TFTP, UDP

Class Method Summary collapse

Class Method Details

.add_class(klass) ⇒ void

This method returns an undefined value.

Add a foreign header class to known header classes. This is needed by Packet.gen and Packet#add.

Parameters:

  • klass (Class)

    a header class

Since:

  • 1.1.0


50
51
52
53
54
# File 'lib/packetgen/header.rb', line 50

def add_class(klass)
  protocol_name = klass.protocol_name
  @added_header_classes[protocol_name] = klass
  @header_classes = nil
end

.allArray<Class> Also known as: list

List all available headers.

Returns:

  • (Array<Class>)

38
39
40
41
42
# File 'lib/packetgen/header.rb', line 38

def all
  return @header_classes if defined?(@header_classes) && @header_classes

  @header_classes = @added_header_classes.values
end

.get_header_class_by_name(name) ⇒ Class?

Get header class from its name

Parameters:

  • name (String)

Returns:

  • (Class, nil)

Since:

  • 1.1.0


71
72
73
74
75
76
77
# File 'lib/packetgen/header.rb', line 71

def get_header_class_by_name(name)
  if Header.const_defined? name
    Header.const_get name
  else
    @added_header_classes[name]
  end
end

.remove_class(klass) ⇒ void

This method returns an undefined value.

Remove a foreign header (previously added by add_header_class from known header classes.

Parameters:

  • klass (Class)

Since:

  • 1.1.0


61
62
63
64
65
# File 'lib/packetgen/header.rb', line 61

def remove_class(klass)
  protocol_name = klass.protocol_name
  @added_header_classes.delete protocol_name
  @header_classes = nil
end