Class: SimpleCapture::IPv4Header

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_capture/header/ipv4_header.rb

Constant Summary collapse

ICMP =
1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(bytes: nil) ⇒ IPv4Header

Returns a new instance of IPv4Header.

Parameters:

  • 各バイトの数値の配列、[10, (Array<Integer>)

    46, …]

Raises:

  • (ArgumentError)


9
10
11
12
13
14
# File 'lib/simple_capture/header/ipv4_header.rb', line 9

def initialize(bytes: nil)
  # support 20Byte IPHeader only now.
  raise ArgumentError, "bytes's size must be 20Byte" unless bytes.size == 20

  convert_bytes_to_header(bytes) unless bytes.nil?
end

Instance Attribute Details

#checksumObject (readonly)

Returns the value of attribute checksum.



5
6
7
# File 'lib/simple_capture/header/ipv4_header.rb', line 5

def checksum
  @checksum
end

#dst_addrObject (readonly)

Returns the value of attribute dst_addr.



5
6
7
# File 'lib/simple_capture/header/ipv4_header.rb', line 5

def dst_addr
  @dst_addr
end

#flagsObject (readonly)

Returns the value of attribute flags.



5
6
7
# File 'lib/simple_capture/header/ipv4_header.rb', line 5

def flags
  @flags
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/simple_capture/header/ipv4_header.rb', line 5

def id
  @id
end

#ihlObject (readonly)

Returns the value of attribute ihl.



5
6
7
# File 'lib/simple_capture/header/ipv4_header.rb', line 5

def ihl
  @ihl
end

#lengthObject (readonly)

Returns the value of attribute length.



5
6
7
# File 'lib/simple_capture/header/ipv4_header.rb', line 5

def length
  @length
end

#offsetObject (readonly)

Returns the value of attribute offset.



5
6
7
# File 'lib/simple_capture/header/ipv4_header.rb', line 5

def offset
  @offset
end

#protocolObject (readonly)

Returns the value of attribute protocol.



5
6
7
# File 'lib/simple_capture/header/ipv4_header.rb', line 5

def protocol
  @protocol
end

#src_addrObject (readonly)

Returns the value of attribute src_addr.



5
6
7
# File 'lib/simple_capture/header/ipv4_header.rb', line 5

def src_addr
  @src_addr
end

#ttlObject (readonly)

Returns the value of attribute ttl.



5
6
7
# File 'lib/simple_capture/header/ipv4_header.rb', line 5

def ttl
  @ttl
end

#type_of_serviceObject (readonly)

Returns the value of attribute type_of_service.



5
6
7
# File 'lib/simple_capture/header/ipv4_header.rb', line 5

def type_of_service
  @type_of_service
end

#versionObject (readonly)

Returns the value of attribute version.



5
6
7
# File 'lib/simple_capture/header/ipv4_header.rb', line 5

def version
  @version
end

Instance Method Details

#dumpObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/simple_capture/header/ipv4_header.rb', line 16

def dump
  puts "■ipv4--------------------------------------".yellow
  print_version
  print_ihl
  print_type_of_service
  print_length
  print_id
  print_flags
  print_offset
  print_ttl
  print_protocol
  print_checksum
  print_src_addr
  print_dst_addr
end

#upper_layer_protocol_icmp?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/simple_capture/header/ipv4_header.rb', line 32

def upper_layer_protocol_icmp?
  protocol == ICMP
end