packetfu 1.1.8 → 1.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. data/README.rdoc +11 -12
  2. data/bench/octets.rb +9 -9
  3. data/examples/100kpackets.rb +13 -12
  4. data/examples/ackscan.rb +17 -16
  5. data/examples/arp.rb +36 -35
  6. data/examples/arphood.rb +37 -36
  7. data/examples/dissect_thinger.rb +7 -6
  8. data/examples/ethernet.rb +1 -0
  9. data/examples/examples.rb +1 -0
  10. data/examples/ifconfig.rb +1 -0
  11. data/examples/new-simple-stats.rb +24 -23
  12. data/examples/packetfu-shell.rb +26 -25
  13. data/examples/simple-sniffer.rb +10 -9
  14. data/examples/simple-stats.rb +24 -23
  15. data/examples/slammer.rb +4 -3
  16. data/lib/packetfu.rb +128 -127
  17. data/lib/packetfu/capture.rb +170 -169
  18. data/lib/packetfu/config.rb +53 -52
  19. data/lib/packetfu/inject.rb +57 -56
  20. data/lib/packetfu/packet.rb +529 -528
  21. data/lib/packetfu/pcap.rb +580 -579
  22. data/lib/packetfu/protos/arp.rb +91 -90
  23. data/lib/packetfu/protos/arp/header.rb +159 -158
  24. data/lib/packetfu/protos/arp/mixin.rb +37 -36
  25. data/lib/packetfu/protos/eth.rb +45 -44
  26. data/lib/packetfu/protos/eth/header.rb +244 -243
  27. data/lib/packetfu/protos/eth/mixin.rb +4 -3
  28. data/lib/packetfu/protos/hsrp.rb +70 -69
  29. data/lib/packetfu/protos/hsrp/header.rb +108 -107
  30. data/lib/packetfu/protos/hsrp/mixin.rb +30 -29
  31. data/lib/packetfu/protos/icmp.rb +72 -71
  32. data/lib/packetfu/protos/icmp/header.rb +83 -82
  33. data/lib/packetfu/protos/icmp/mixin.rb +15 -14
  34. data/lib/packetfu/protos/invalid.rb +50 -49
  35. data/lib/packetfu/protos/ip.rb +70 -69
  36. data/lib/packetfu/protos/ip/header.rb +292 -291
  37. data/lib/packetfu/protos/ip/mixin.rb +41 -40
  38. data/lib/packetfu/protos/ipv6.rb +51 -50
  39. data/lib/packetfu/protos/ipv6/header.rb +189 -188
  40. data/lib/packetfu/protos/ipv6/mixin.rb +30 -29
  41. data/lib/packetfu/protos/lldp.rb +3 -1
  42. data/lib/packetfu/protos/lldp/header.rb +1 -0
  43. data/lib/packetfu/protos/lldp/mixin.rb +1 -0
  44. data/lib/packetfu/protos/tcp.rb +177 -176
  45. data/lib/packetfu/protos/tcp/ecn.rb +36 -35
  46. data/lib/packetfu/protos/tcp/flags.rb +75 -74
  47. data/lib/packetfu/protos/tcp/header.rb +269 -268
  48. data/lib/packetfu/protos/tcp/hlen.rb +33 -32
  49. data/lib/packetfu/protos/tcp/mixin.rb +47 -46
  50. data/lib/packetfu/protos/tcp/option.rb +322 -321
  51. data/lib/packetfu/protos/tcp/options.rb +96 -95
  52. data/lib/packetfu/protos/tcp/reserved.rb +36 -35
  53. data/lib/packetfu/protos/udp.rb +117 -116
  54. data/lib/packetfu/protos/udp/header.rb +92 -91
  55. data/lib/packetfu/protos/udp/mixin.rb +4 -3
  56. data/lib/packetfu/structfu.rb +281 -280
  57. data/lib/packetfu/utils.rb +211 -208
  58. data/lib/packetfu/version.rb +42 -41
  59. data/packetfu.gemspec +1 -1
  60. data/spec/ethpacket_spec.rb +48 -48
  61. data/spec/packet_spec.rb +57 -57
  62. data/spec/packet_subclasses_spec.rb +8 -8
  63. data/spec/packetfu_spec.rb +59 -59
  64. data/spec/structfu_spec.rb +268 -268
  65. data/spec/tcp_spec.rb +75 -75
  66. data/test/all_tests.rb +13 -13
  67. data/test/func_lldp.rb +3 -3
  68. data/test/ptest.rb +2 -2
  69. data/test/test_arp.rb +116 -116
  70. data/test/test_capture.rb +45 -45
  71. data/test/test_eth.rb +68 -68
  72. data/test/test_hsrp.rb +9 -9
  73. data/test/test_icmp.rb +52 -52
  74. data/test/test_inject.rb +18 -18
  75. data/test/test_invalid.rb +16 -16
  76. data/test/test_ip.rb +36 -36
  77. data/test/test_ip6.rb +48 -48
  78. data/test/test_octets.rb +21 -21
  79. data/test/test_packet.rb +154 -154
  80. data/test/test_pcap.rb +170 -170
  81. data/test/test_structfu.rb +97 -97
  82. data/test/test_tcp.rb +320 -320
  83. data/test/test_udp.rb +76 -76
  84. metadata +2 -2
@@ -1,3 +1,4 @@
1
+ # -*- coding: binary -*-
1
2
  require 'packetfu/protos/eth/header'
2
3
  require 'packetfu/protos/eth/mixin'
3
4
 
@@ -6,109 +7,109 @@ require 'packetfu/protos/arp/mixin'
6
7
 
7
8
  module PacketFu
8
9
 
9
- # ARPPacket is used to construct ARP packets. They contain an EthHeader and an ARPHeader.
10
- # == Example
11
- #
10
+ # ARPPacket is used to construct ARP packets. They contain an EthHeader and an ARPHeader.
11
+ # == Example
12
+ #
12
13
  # require 'packetfu'
13
- # arp_pkt = PacketFu::ARPPacket.new(:flavor => "Windows")
14
- # arp_pkt.arp_saddr_mac="00:1c:23:44:55:66" # Your hardware address
15
- # arp_pkt.arp_saddr_ip="10.10.10.17" # Your IP address
16
- # arp_pkt.arp_daddr_ip="10.10.10.1" # Target IP address
17
- # arp_pkt.arp_opcode=1 # Request
18
- #
19
- # arp_pkt.to_w('eth0') # Inject on the wire. (requires root)
14
+ # arp_pkt = PacketFu::ARPPacket.new(:flavor => "Windows")
15
+ # arp_pkt.arp_saddr_mac="00:1c:23:44:55:66" # Your hardware address
16
+ # arp_pkt.arp_saddr_ip="10.10.10.17" # Your IP address
17
+ # arp_pkt.arp_daddr_ip="10.10.10.1" # Target IP address
18
+ # arp_pkt.arp_opcode=1 # Request
19
+ #
20
+ # arp_pkt.to_w('eth0') # Inject on the wire. (requires root)
20
21
  # arp_pkt.to_f('/tmp/arp.pcap') # Write to a file.
21
- #
22
- # == Parameters
23
- #
24
- # :flavor
25
- # Sets the "flavor" of the ARP packet. Choices are currently:
26
- # :windows, :linux, :hp_deskjet
27
- # :eth
28
- # A pre-generated EthHeader object. If not specified, a new one will be created.
29
- # :arp
30
- # A pre-generated ARPHeader object. If not specificed, a new one will be created.
31
- # :config
32
- # A hash of return address details, often the output of Utils.whoami?
33
- class ARPPacket < Packet
22
+ #
23
+ # == Parameters
24
+ #
25
+ # :flavor
26
+ # Sets the "flavor" of the ARP packet. Choices are currently:
27
+ # :windows, :linux, :hp_deskjet
28
+ # :eth
29
+ # A pre-generated EthHeader object. If not specified, a new one will be created.
30
+ # :arp
31
+ # A pre-generated ARPHeader object. If not specificed, a new one will be created.
32
+ # :config
33
+ # A hash of return address details, often the output of Utils.whoami?
34
+ class ARPPacket < Packet
34
35
  include ::PacketFu::EthHeaderMixin
35
36
  include ::PacketFu::ARPHeaderMixin
36
37
 
37
- attr_accessor :eth_header, :arp_header
38
+ attr_accessor :eth_header, :arp_header
38
39
 
39
- def self.can_parse?(str)
40
- return false unless EthPacket.can_parse? str
41
- return false unless str.size >= 28
42
- return false unless str[12,2] == "\x08\x06"
43
- true
44
- end
40
+ def self.can_parse?(str)
41
+ return false unless EthPacket.can_parse? str
42
+ return false unless str.size >= 28
43
+ return false unless str[12,2] == "\x08\x06"
44
+ true
45
+ end
45
46
 
46
- def read(str=nil,args={})
47
- raise "Cannot parse `#{str}'" unless self.class.can_parse?(str)
48
- @eth_header.read(str)
49
- super(args)
50
- self
51
- end
47
+ def read(str=nil,args={})
48
+ raise "Cannot parse `#{str}'" unless self.class.can_parse?(str)
49
+ @eth_header.read(str)
50
+ super(args)
51
+ self
52
+ end
52
53
 
53
- def initialize(args={})
54
- @eth_header = EthHeader.new(args).read(args[:eth])
55
- @arp_header = ARPHeader.new(args).read(args[:arp])
56
- @eth_header.eth_proto = "\x08\x06"
57
- @eth_header.body=@arp_header
54
+ def initialize(args={})
55
+ @eth_header = EthHeader.new(args).read(args[:eth])
56
+ @arp_header = ARPHeader.new(args).read(args[:arp])
57
+ @eth_header.eth_proto = "\x08\x06"
58
+ @eth_header.body=@arp_header
58
59
 
59
- # Please send more flavors to todb+packetfu@planb-security.net.
60
- # Most of these initial fingerprints come from one (1) sample.
61
- case (args[:flavor].nil?) ? :nil : args[:flavor].to_s.downcase.intern
62
- when :windows; @arp_header.body = "\x00" * 64 # 64 bytes of padding
63
- when :linux; @arp_header.body = "\x00" * 4 + # 32 bytes of padding
64
- "\x00\x07\x5c\x14" + "\x00" * 4 +
65
- "\x00\x0f\x83\x34" + "\x00\x0f\x83\x74" +
66
- "\x01\x11\x83\x78" + "\x00\x00\x00\x0c" +
67
- "\x00\x00\x00\x00"
68
- when :hp_deskjet; # Pads up to 60 bytes.
69
- @arp_header.body = "\xe0\x90\x0d\x6c" +
70
- "\xff\xff\xee\xee" + "\x00" * 4 +
71
- "\xe0\x8f\xfa\x18\x00\x20"
72
- else; @arp_header.body = "\x00" * 18 # Pads up to 60 bytes.
73
- end
60
+ # Please send more flavors to todb+packetfu@planb-security.net.
61
+ # Most of these initial fingerprints come from one (1) sample.
62
+ case (args[:flavor].nil?) ? :nil : args[:flavor].to_s.downcase.intern
63
+ when :windows; @arp_header.body = "\x00" * 64 # 64 bytes of padding
64
+ when :linux; @arp_header.body = "\x00" * 4 + # 32 bytes of padding
65
+ "\x00\x07\x5c\x14" + "\x00" * 4 +
66
+ "\x00\x0f\x83\x34" + "\x00\x0f\x83\x74" +
67
+ "\x01\x11\x83\x78" + "\x00\x00\x00\x0c" +
68
+ "\x00\x00\x00\x00"
69
+ when :hp_deskjet; # Pads up to 60 bytes.
70
+ @arp_header.body = "\xe0\x90\x0d\x6c" +
71
+ "\xff\xff\xee\xee" + "\x00" * 4 +
72
+ "\xe0\x8f\xfa\x18\x00\x20"
73
+ else; @arp_header.body = "\x00" * 18 # Pads up to 60 bytes.
74
+ end
74
75
 
75
- @headers = [@eth_header, @arp_header]
76
- super
77
- end
76
+ @headers = [@eth_header, @arp_header]
77
+ super
78
+ end
78
79
 
79
- # Generates summary data for ARP packets.
80
- def peek_format
81
- peek_data = ["A "]
82
- peek_data << "%-5d" % self.to_s.size
83
- peek_data << arp_saddr_mac
84
- peek_data << "(#{arp_saddr_ip})"
85
- peek_data << "->"
86
- peek_data << case arp_daddr_mac
87
- when "00:00:00:00:00:00"; "Bcast00"
88
- when "ff:ff:ff:ff:ff:ff"; "BcastFF"
89
- else; arp_daddr_mac
90
- end
91
- peek_data << "(#{arp_daddr_ip})"
92
- peek_data << ":"
93
- peek_data << case arp_opcode
94
- when 1; "Requ"
95
- when 2; "Repl"
96
- when 3; "RReq"
97
- when 4; "RRpl"
98
- when 5; "IReq"
99
- when 6; "IRpl"
100
- else; "0x%02x" % arp_opcode
101
- end
102
- peek_data.join
103
- end
80
+ # Generates summary data for ARP packets.
81
+ def peek_format
82
+ peek_data = ["A "]
83
+ peek_data << "%-5d" % self.to_s.size
84
+ peek_data << arp_saddr_mac
85
+ peek_data << "(#{arp_saddr_ip})"
86
+ peek_data << "->"
87
+ peek_data << case arp_daddr_mac
88
+ when "00:00:00:00:00:00"; "Bcast00"
89
+ when "ff:ff:ff:ff:ff:ff"; "BcastFF"
90
+ else; arp_daddr_mac
91
+ end
92
+ peek_data << "(#{arp_daddr_ip})"
93
+ peek_data << ":"
94
+ peek_data << case arp_opcode
95
+ when 1; "Requ"
96
+ when 2; "Repl"
97
+ when 3; "RReq"
98
+ when 4; "RRpl"
99
+ when 5; "IReq"
100
+ when 6; "IRpl"
101
+ else; "0x%02x" % arp_opcode
102
+ end
103
+ peek_data.join
104
+ end
104
105
 
105
- # While there are lengths in ARPPackets, there's not
106
- # much to do with them.
107
- def recalc(args={})
108
- @headers[0].inspect
109
- end
106
+ # While there are lengths in ARPPackets, there's not
107
+ # much to do with them.
108
+ def recalc(args={})
109
+ @headers[0].inspect
110
+ end
110
111
 
111
- end
112
+ end
112
113
 
113
114
  end
114
115
 
@@ -1,160 +1,161 @@
1
+ # -*- coding: binary -*-
1
2
  module PacketFu
2
- # ARPHeader is a complete ARP struct, used in ARPPacket.
3
- #
4
- # ARP is used to discover the machine address of nearby devices.
5
- #
6
- # See http://www.networksorcery.com/enp/protocol/arp.htm for details.
7
- #
8
- # ==== Header Definition
9
- #
10
- # Int16 :arp_hw Default: 1 # Ethernet
11
- # Int16 :arp_proto, Default: 0x8000 # IP
12
- # Int8 :arp_hw_len, Default: 6
13
- # Int8 :arp_proto_len, Default: 4
14
- # Int16 :arp_opcode, Default: 1 # 1: Request, 2: Reply, 3: Request-Reverse, 4: Reply-Reverse
15
- # EthMac :arp_src_mac # From eth.rb
16
- # Octets :arp_src_ip # From ip.rb
17
- # EthMac :arp_dst_mac # From eth.rb
18
- # Octets :arp_dst_ip # From ip.rb
19
- # String :body
20
- class ARPHeader < Struct.new(:arp_hw, :arp_proto, :arp_hw_len,
21
- :arp_proto_len, :arp_opcode,
22
- :arp_src_mac, :arp_src_ip,
23
- :arp_dst_mac, :arp_dst_ip,
24
- :body)
25
- include StructFu
26
-
27
- def initialize(args={})
28
- src_mac = args[:arp_src_mac] || (args[:config][:eth_src] if args[:config])
29
- src_ip_bin = args[:arp_src_ip] || (args[:config][:ip_src_bin] if args[:config])
30
-
31
- super(
32
- Int16.new(args[:arp_hw] || 1),
33
- Int16.new(args[:arp_proto] ||0x0800),
34
- Int8.new(args[:arp_hw_len] || 6),
35
- Int8.new(args[:arp_proto_len] || 4),
36
- Int16.new(args[:arp_opcode] || 1),
37
- EthMac.new.read(src_mac),
38
- Octets.new.read(src_ip_bin),
39
- EthMac.new.read(args[:arp_dst_mac]),
40
- Octets.new.read(args[:arp_dst_ip]),
41
- StructFu::String.new.read(args[:body])
42
- )
43
- end
44
-
45
- # Returns the object in string form.
46
- def to_s
47
- self.to_a.map {|x| x.to_s}.join
48
- end
49
-
50
- # Reads a string to populate the object.
51
- def read(str)
52
- force_binary(str)
53
- return self if str.nil?
54
- self[:arp_hw].read(str[0,2])
55
- self[:arp_proto].read(str[2,2])
56
- self[:arp_hw_len].read(str[4,1])
57
- self[:arp_proto_len].read(str[5,1])
58
- self[:arp_opcode].read(str[6,2])
59
- self[:arp_src_mac].read(str[8,6])
60
- self[:arp_src_ip].read(str[14,4])
61
- self[:arp_dst_mac].read(str[18,6])
62
- self[:arp_dst_ip].read(str[24,4])
63
- self[:body].read(str[28,str.size])
64
- self
65
- end
66
-
67
- # Setter for the ARP hardware type.
68
- def arp_hw=(i); typecast i; end
69
- # Getter for the ARP hardware type.
70
- def arp_hw; self[:arp_hw].to_i; end
71
- # Setter for the ARP protocol.
72
- def arp_proto=(i); typecast i; end
73
- # Getter for the ARP protocol.
74
- def arp_proto; self[:arp_proto].to_i; end
75
- # Setter for the ARP hardware type length.
76
- def arp_hw_len=(i); typecast i; end
77
- # Getter for the ARP hardware type length.
78
- def arp_hw_len; self[:arp_hw_len].to_i; end
79
- # Setter for the ARP protocol length.
80
- def arp_proto_len=(i); typecast i; end
81
- # Getter for the ARP protocol length.
82
- def arp_proto_len; self[:arp_proto_len].to_i; end
83
- # Setter for the ARP opcode.
84
- def arp_opcode=(i); typecast i; end
85
- # Getter for the ARP opcode.
86
- def arp_opcode; self[:arp_opcode].to_i; end
87
- # Setter for the ARP source MAC address.
88
- def arp_src_mac=(i); typecast i; end
89
- # Getter for the ARP source MAC address.
90
- def arp_src_mac; self[:arp_src_mac].to_s; end
91
- # Getter for the ARP source IP address.
92
- def arp_src_ip=(i); typecast i; end
93
- # Setter for the ARP source IP address.
94
- def arp_src_ip; self[:arp_src_ip].to_s; end
95
- # Setter for the ARP destination MAC address.
96
- def arp_dst_mac=(i); typecast i; end
97
- # Setter for the ARP destination MAC address.
98
- def arp_dst_mac; self[:arp_dst_mac].to_s; end
99
- # Setter for the ARP destination IP address.
100
- def arp_dst_ip=(i); typecast i; end
101
- # Getter for the ARP destination IP address.
102
- def arp_dst_ip; self[:arp_dst_ip].to_s; end
103
-
104
- # Set the source MAC address in a more readable way.
105
- def arp_saddr_mac=(mac)
106
- mac = EthHeader.mac2str(mac)
107
- self[:arp_src_mac].read(mac)
108
- self.arp_src_mac
109
- end
110
-
111
- # Get a more readable source MAC address.
112
- def arp_saddr_mac
113
- EthHeader.str2mac(self[:arp_src_mac].to_s)
114
- end
115
-
116
- # Set the destination MAC address in a more readable way.
117
- def arp_daddr_mac=(mac)
118
- mac = EthHeader.mac2str(mac)
119
- self[:arp_dst_mac].read(mac)
120
- self.arp_dst_mac
121
- end
122
-
123
- # Get a more readable source MAC address.
124
- def arp_daddr_mac
125
- EthHeader.str2mac(self[:arp_dst_mac].to_s)
126
- end
127
-
128
- # Set a more readable source IP address.
129
- def arp_saddr_ip=(addr)
130
- self[:arp_src_ip].read_quad(addr)
131
- end
132
-
133
- # Get a more readable source IP address.
134
- def arp_saddr_ip
135
- self[:arp_src_ip].to_x
136
- end
137
-
138
- # Set a more readable destination IP address.
139
- def arp_daddr_ip=(addr)
140
- self[:arp_dst_ip].read_quad(addr)
141
- end
142
-
143
- # Get a more readable destination IP address.
144
- def arp_daddr_ip
145
- self[:arp_dst_ip].to_x
146
- end
147
-
148
- # Readability aliases
149
-
150
- alias :arp_src_mac_readable :arp_saddr_mac
151
- alias :arp_dst_mac_readable :arp_daddr_mac
152
- alias :arp_src_ip_readable :arp_saddr_ip
153
- alias :arp_dst_ip_readable :arp_daddr_ip
154
-
155
- def arp_proto_readable
156
- "0x%04x" % arp_proto
157
- end
158
-
159
- end # class ARPHeader
3
+ # ARPHeader is a complete ARP struct, used in ARPPacket.
4
+ #
5
+ # ARP is used to discover the machine address of nearby devices.
6
+ #
7
+ # See http://www.networksorcery.com/enp/protocol/arp.htm for details.
8
+ #
9
+ # ==== Header Definition
10
+ #
11
+ # Int16 :arp_hw Default: 1 # Ethernet
12
+ # Int16 :arp_proto, Default: 0x8000 # IP
13
+ # Int8 :arp_hw_len, Default: 6
14
+ # Int8 :arp_proto_len, Default: 4
15
+ # Int16 :arp_opcode, Default: 1 # 1: Request, 2: Reply, 3: Request-Reverse, 4: Reply-Reverse
16
+ # EthMac :arp_src_mac # From eth.rb
17
+ # Octets :arp_src_ip # From ip.rb
18
+ # EthMac :arp_dst_mac # From eth.rb
19
+ # Octets :arp_dst_ip # From ip.rb
20
+ # String :body
21
+ class ARPHeader < Struct.new(:arp_hw, :arp_proto, :arp_hw_len,
22
+ :arp_proto_len, :arp_opcode,
23
+ :arp_src_mac, :arp_src_ip,
24
+ :arp_dst_mac, :arp_dst_ip,
25
+ :body)
26
+ include StructFu
27
+
28
+ def initialize(args={})
29
+ src_mac = args[:arp_src_mac] || (args[:config][:eth_src] if args[:config])
30
+ src_ip_bin = args[:arp_src_ip] || (args[:config][:ip_src_bin] if args[:config])
31
+
32
+ super(
33
+ Int16.new(args[:arp_hw] || 1),
34
+ Int16.new(args[:arp_proto] ||0x0800),
35
+ Int8.new(args[:arp_hw_len] || 6),
36
+ Int8.new(args[:arp_proto_len] || 4),
37
+ Int16.new(args[:arp_opcode] || 1),
38
+ EthMac.new.read(src_mac),
39
+ Octets.new.read(src_ip_bin),
40
+ EthMac.new.read(args[:arp_dst_mac]),
41
+ Octets.new.read(args[:arp_dst_ip]),
42
+ StructFu::String.new.read(args[:body])
43
+ )
44
+ end
45
+
46
+ # Returns the object in string form.
47
+ def to_s
48
+ self.to_a.map {|x| x.to_s}.join
49
+ end
50
+
51
+ # Reads a string to populate the object.
52
+ def read(str)
53
+ force_binary(str)
54
+ return self if str.nil?
55
+ self[:arp_hw].read(str[0,2])
56
+ self[:arp_proto].read(str[2,2])
57
+ self[:arp_hw_len].read(str[4,1])
58
+ self[:arp_proto_len].read(str[5,1])
59
+ self[:arp_opcode].read(str[6,2])
60
+ self[:arp_src_mac].read(str[8,6])
61
+ self[:arp_src_ip].read(str[14,4])
62
+ self[:arp_dst_mac].read(str[18,6])
63
+ self[:arp_dst_ip].read(str[24,4])
64
+ self[:body].read(str[28,str.size])
65
+ self
66
+ end
67
+
68
+ # Setter for the ARP hardware type.
69
+ def arp_hw=(i); typecast i; end
70
+ # Getter for the ARP hardware type.
71
+ def arp_hw; self[:arp_hw].to_i; end
72
+ # Setter for the ARP protocol.
73
+ def arp_proto=(i); typecast i; end
74
+ # Getter for the ARP protocol.
75
+ def arp_proto; self[:arp_proto].to_i; end
76
+ # Setter for the ARP hardware type length.
77
+ def arp_hw_len=(i); typecast i; end
78
+ # Getter for the ARP hardware type length.
79
+ def arp_hw_len; self[:arp_hw_len].to_i; end
80
+ # Setter for the ARP protocol length.
81
+ def arp_proto_len=(i); typecast i; end
82
+ # Getter for the ARP protocol length.
83
+ def arp_proto_len; self[:arp_proto_len].to_i; end
84
+ # Setter for the ARP opcode.
85
+ def arp_opcode=(i); typecast i; end
86
+ # Getter for the ARP opcode.
87
+ def arp_opcode; self[:arp_opcode].to_i; end
88
+ # Setter for the ARP source MAC address.
89
+ def arp_src_mac=(i); typecast i; end
90
+ # Getter for the ARP source MAC address.
91
+ def arp_src_mac; self[:arp_src_mac].to_s; end
92
+ # Getter for the ARP source IP address.
93
+ def arp_src_ip=(i); typecast i; end
94
+ # Setter for the ARP source IP address.
95
+ def arp_src_ip; self[:arp_src_ip].to_s; end
96
+ # Setter for the ARP destination MAC address.
97
+ def arp_dst_mac=(i); typecast i; end
98
+ # Setter for the ARP destination MAC address.
99
+ def arp_dst_mac; self[:arp_dst_mac].to_s; end
100
+ # Setter for the ARP destination IP address.
101
+ def arp_dst_ip=(i); typecast i; end
102
+ # Getter for the ARP destination IP address.
103
+ def arp_dst_ip; self[:arp_dst_ip].to_s; end
104
+
105
+ # Set the source MAC address in a more readable way.
106
+ def arp_saddr_mac=(mac)
107
+ mac = EthHeader.mac2str(mac)
108
+ self[:arp_src_mac].read(mac)
109
+ self.arp_src_mac
110
+ end
111
+
112
+ # Get a more readable source MAC address.
113
+ def arp_saddr_mac
114
+ EthHeader.str2mac(self[:arp_src_mac].to_s)
115
+ end
116
+
117
+ # Set the destination MAC address in a more readable way.
118
+ def arp_daddr_mac=(mac)
119
+ mac = EthHeader.mac2str(mac)
120
+ self[:arp_dst_mac].read(mac)
121
+ self.arp_dst_mac
122
+ end
123
+
124
+ # Get a more readable source MAC address.
125
+ def arp_daddr_mac
126
+ EthHeader.str2mac(self[:arp_dst_mac].to_s)
127
+ end
128
+
129
+ # Set a more readable source IP address.
130
+ def arp_saddr_ip=(addr)
131
+ self[:arp_src_ip].read_quad(addr)
132
+ end
133
+
134
+ # Get a more readable source IP address.
135
+ def arp_saddr_ip
136
+ self[:arp_src_ip].to_x
137
+ end
138
+
139
+ # Set a more readable destination IP address.
140
+ def arp_daddr_ip=(addr)
141
+ self[:arp_dst_ip].read_quad(addr)
142
+ end
143
+
144
+ # Get a more readable destination IP address.
145
+ def arp_daddr_ip
146
+ self[:arp_dst_ip].to_x
147
+ end
148
+
149
+ # Readability aliases
150
+
151
+ alias :arp_src_mac_readable :arp_saddr_mac
152
+ alias :arp_dst_mac_readable :arp_daddr_mac
153
+ alias :arp_src_ip_readable :arp_saddr_ip
154
+ alias :arp_dst_ip_readable :arp_daddr_ip
155
+
156
+ def arp_proto_readable
157
+ "0x%04x" % arp_proto
158
+ end
159
+
160
+ end # class ARPHeader
160
161
  end