Class: PacketGen::Header::BOOTP

Inherits:
Base
  • Object
show all
Defined in:
lib/packetgen/header/bootp.rb

Overview

Bootstrap Protocol, RFC 951

A BOOTP header consists of:

  • an operation code field (#op of type BinStruct::Int8Enum),

  • a hardware address type (#htype of type BinStruct::Int8),

  • a hardware address length (#hlen of type BinStruct::Int8),

  • a #hops field (BinStruct::Int8),

  • a transaction ID (#xid of type BinStruct::Int32),

  • a #secs field (BinStruct::Int16),

  • a #flags field (BinStruct::Int16):

    • a 1-bit broadcast flag (#b),

    • a 15-bit Must Be Zero field (#mbz),

  • a #ciaddr field (IP::Addr),

  • a #yiaddr field (IP::Addr),

  • a #siaddr field (IP::Addr),

  • a #giaddr field (IP::Addr),

  • a #chaddr field (16-byte BinStruct::String),

  • a #sname field (64-byte BinStruct::CString),

  • a #file field (128-byte BinStruct::CString),

  • and a body (BinStruct::String).

Examples:

Create a BOOTP header

# standalone
bootp = PacketGen::Header::BOOTP.new
# in a packet
pkt = PacketGen.gen('IP').add('UDP').add('BOOTP')
# access to BOOTP header
pkt.bootp.protocol_name      # => "BOOTP"

Author:

  • Sylvain Daubert

Since:

  • 2.2.0

Constant Summary collapse

UDP_SERVER_PORT =

Since:

  • 2.2.0

67
UDP_CLIENT_PORT =

Since:

  • 2.2.0

68
OPCODES =

DHCP opcodes

Since:

  • 2.2.0

{
  'BOOTREQUEST' => 1,
  'BOOTREPLY' => 2
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

bind, calculate_and_set_length, #header_id, inherited, #initialize, #ip_header, #ll_header

Methods included from PacketGen::Headerable

#added_to_packet, included, #method_name, #packet, #packet=, #parse?, #protocol_name, #read, #to_s

Constructor Details

This class inherits a constructor from PacketGen::Header::Base

Instance Attribute Details

#bObject

Broadcast flag, from #flags


91
# File 'lib/packetgen/header/bootp.rb', line 91

define_bit_attr :flags, b: 1, mbz: 15

#bodyString

Returns:

  • (String)

130
# File 'lib/packetgen/header/bootp.rb', line 130

define_attr :body, BinStruct::String

#chaddrString

client hardware address

Returns:

  • (String)

116
# File 'lib/packetgen/header/bootp.rb', line 116

define_attr :chaddr, BinStruct::String, static_length: 16

#ciaddrString

client IP address

Returns:

  • (String)

96
# File 'lib/packetgen/header/bootp.rb', line 96

define_attr :ciaddr, IP::Addr

#fileString

Boot file name, null terminated string

Returns:

  • (String)

126
# File 'lib/packetgen/header/bootp.rb', line 126

define_attr :file, BinStruct::CString, static_length: 128

#flagsInteger

16-bit flag field

Returns:

  • (Integer)

91
# File 'lib/packetgen/header/bootp.rb', line 91

define_bit_attr :flags, b: 1, mbz: 15

#giaddrString

Relay agent IP address, used in booting via a relay agent

Returns:

  • (String)

111
# File 'lib/packetgen/header/bootp.rb', line 111

define_attr :giaddr, IP::Addr

#hlenInteger

8-bit hardware address length

Returns:

  • (Integer)

65
# File 'lib/packetgen/header/bootp.rb', line 65

define_attr :hlen, BinStruct::Int8, default: 6

#hopsInteger

Returns:

  • (Integer)

69
# File 'lib/packetgen/header/bootp.rb', line 69

define_attr :hops, BinStruct::Int8

#htypeInteger

8-bit hardware address type

Returns:

  • (Integer)

60
# File 'lib/packetgen/header/bootp.rb', line 60

define_attr :htype, BinStruct::Int8, default: 1

#mbzObject

15-bit Must Be Zero bits, from #flags


91
# File 'lib/packetgen/header/bootp.rb', line 91

define_bit_attr :flags, b: 1, mbz: 15

#opInteger

8-bit opcode

Returns:

  • (Integer)

55
# File 'lib/packetgen/header/bootp.rb', line 55

define_attr :op, BinStruct::Int8Enum, enum: OPCODES

#secsInteger

16-bit integer: number of seconds elapsed since client began address acquisition or renewal process

Returns:

  • (Integer)

80
# File 'lib/packetgen/header/bootp.rb', line 80

define_attr :secs, BinStruct::Int16

#siaddrString

IP address of next server to use in bootstrap

Returns:

  • (String)

106
# File 'lib/packetgen/header/bootp.rb', line 106

define_attr :siaddr, IP::Addr

#snameString

optional server hostname, null-terminated string

Returns:

  • (String)

121
# File 'lib/packetgen/header/bootp.rb', line 121

define_attr :sname, BinStruct::CString, static_length: 64

#xidInteger

32-bit Transaction ID

Returns:

  • (Integer)

74
# File 'lib/packetgen/header/bootp.rb', line 74

define_attr :xid, BinStruct::Int32

#yiaddrString

‘your’ (client) IP address

Returns:

  • (String)

101
# File 'lib/packetgen/header/bootp.rb', line 101

define_attr :yiaddr, IP::Addr

Instance Method Details

#inspectString

Returns:

  • (String)

Since:

  • 2.2.0


133
134
135
136
137
138
139
# File 'lib/packetgen/header/bootp.rb', line 133

def inspect
  super do |attr|
    next unless (attr == :chaddr) && (self.hlen == 6)

    Inspect.inspect_attribute(attr, Eth::MacAddr.new.read(self[:chaddr][0, 6]))
  end
end

#reply!self

Invert opcode, if known

Returns:

  • (self)

Since:

  • 2.2.0


143
144
145
146
147
148
149
# File 'lib/packetgen/header/bootp.rb', line 143

def reply!
  case self.op
  when 1 then self.op = 2
  when 2 then self.op = 1
  end
  self
end