pio 0.16.0 → 0.17.0

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.
data/lib/pio/udp.rb CHANGED
@@ -11,8 +11,8 @@ module Pio
11
11
  include UdpHeader
12
12
 
13
13
  endian :big
14
- ethernet_header ether_type: EthernetHeader::ETHER_TYPE_IP
15
- ipv4_header ip_protocol: IPv4Header::IP_PROTOCOL_UDP
14
+ ethernet_header ether_type: EtherType::IPV4
15
+ ipv4_header ip_protocol: ProtocolNumber::UDP
16
16
  udp_header
17
17
  rest :udp_payload
18
18
  end
@@ -11,7 +11,7 @@ module Pio
11
11
  ip_address :ip_source_address
12
12
  ip_address :ip_destination_address
13
13
  uint8 :padding
14
- uint8 :ip_protocol, value: 17
14
+ uint8 :ip_protocol, value: IPv4Header::ProtocolNumber::UDP
15
15
  uint16 :udp_length
16
16
  end
17
17
 
data/lib/pio/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # Base module.
2
2
  module Pio
3
3
  # gem version.
4
- VERSION = '0.16.0'.freeze
4
+ VERSION = '0.17.0'.freeze
5
5
  end
data/pio.gemspec CHANGED
@@ -37,11 +37,11 @@ Gem::Specification.new do |gem|
37
37
  gem.add_dependency 'bindata', '~> 2.1.0'
38
38
 
39
39
  gem.add_development_dependency 'rake'
40
- gem.add_development_dependency 'bundler', '~> 1.8.2'
40
+ gem.add_development_dependency 'bundler', '~> 1.8.4'
41
41
  gem.add_development_dependency 'pry', '~> 0.10.1'
42
42
 
43
43
  # Guard
44
- gem.add_development_dependency 'guard', '~> 2.12.1'
44
+ gem.add_development_dependency 'guard', '~> 2.12.4'
45
45
  gem.add_development_dependency 'guard-bundler', '~> 2.1.0'
46
46
  gem.add_development_dependency 'guard-cucumber', '~> 1.5.3'
47
47
  gem.add_development_dependency 'guard-rspec', '~> 4.5.0'
@@ -56,12 +56,12 @@ Gem::Specification.new do |gem|
56
56
  gem.add_development_dependency 'yard', '~> 0.8.7.6'
57
57
 
58
58
  # Test
59
- gem.add_development_dependency 'codeclimate-test-reporter', '~> 0.4.6'
60
- gem.add_development_dependency 'coveralls', '~> 0.7.9'
59
+ gem.add_development_dependency 'codeclimate-test-reporter', '~> 0.4.7'
60
+ gem.add_development_dependency 'coveralls', '~> 0.7.11'
61
61
  gem.add_development_dependency 'cucumber', '~> 1.3.19'
62
62
  gem.add_development_dependency 'flay', '~> 2.6.1'
63
63
  gem.add_development_dependency 'flog', '~> 4.3.2'
64
- gem.add_development_dependency 'reek', '~> 2.0.0'
64
+ gem.add_development_dependency 'reek', '~> 2.0.1'
65
65
  gem.add_development_dependency 'rspec', '~> 3.2.0'
66
66
  gem.add_development_dependency 'rspec-given', '~> 3.7.0'
67
67
  gem.add_development_dependency 'rubocop', '~> 0.29.1'
data/spec/pio/arp_spec.rb CHANGED
@@ -33,7 +33,7 @@ describe Pio::Arp do
33
33
  Then { arp_request.source_mac.to_s == '00:26:82:eb:ea:d1' }
34
34
  Then { arp_request.ether_type == 0x0806 }
35
35
  Then { arp_request.hardware_type == 1 }
36
- Then { arp_request.protocol_type == 0x800 }
36
+ Then { arp_request.protocol_type == 0x0800 }
37
37
  Then { arp_request.hardware_length == 6 }
38
38
  Then { arp_request.protocol_length == 4 }
39
39
  Then { arp_request.operation == 1 }
@@ -70,7 +70,7 @@ describe Pio::Arp do
70
70
  Then { arp_reply.source_mac.to_s == '00:16:9d:1d:9c:c4' }
71
71
  Then { arp_reply.ether_type == 0x0806 }
72
72
  Then { arp_reply.hardware_type == 1 }
73
- Then { arp_reply.protocol_type == 0x800 }
73
+ Then { arp_reply.protocol_type == 0x0800 }
74
74
  Then { arp_reply.hardware_length == 6 }
75
75
  Then { arp_reply.protocol_length == 4 }
76
76
  Then { arp_reply.operation == 2 }
@@ -1,302 +1,270 @@
1
1
  require 'pio/ipv4_address'
2
2
 
3
3
  describe Pio::IPv4Address do
4
- context '.new' do
5
- subject(:ipv4) { Pio::IPv4Address.new(ip_address) }
4
+ Given(:ipv4) { Pio::IPv4Address.new(ip_address) }
6
5
 
7
- context 'with 10.1.1.1' do
8
- let(:ip_address) { '10.1.1.1' }
6
+ context ".new('192.168.1.10')" do
7
+ Given(:ip_address) { '192.168.1.10' }
9
8
 
10
- describe '#to_s' do
11
- subject { super().to_s }
12
- it { is_expected.to eq '10.1.1.1' }
13
- end
9
+ describe '#to_s' do
10
+ When(:result) { ipv4.to_s }
11
+ Then { result == '192.168.1.10' }
12
+ end
14
13
 
15
- describe '#to_i' do
16
- subject { super().to_i }
17
- it { is_expected.to eq(((10 * 256 + 1) * 256 + 1) * 256 + 1) }
18
- end
14
+ describe '#to_i' do
15
+ When(:result) { ipv4.to_i }
16
+ Then { result == (((192 * 256 + 168) * 256 + 1) * 256 + 10) }
17
+ end
19
18
 
20
- describe '#prefixlen' do
21
- subject { super().prefixlen }
22
- it { is_expected.to eq 32 }
23
- end
19
+ describe '#to_range' do
20
+ When(:result) { ipv4.to_range }
21
+ Then { result == (ipv4..ipv4) }
22
+ end
24
23
 
25
- describe '#to_ary' do
26
- subject { super().to_ary }
27
- it { is_expected.to eq [0x0a, 0x01, 0x01, 0x01] }
28
- end
24
+ describe '#==' do
25
+ When(:result) { ipv4 == other }
29
26
 
30
- describe '#class_a?' do
31
- subject { super().class_a? }
32
- it { is_expected.to be_truthy }
27
+ context "with an IPv4Address ('192.168.1.10)" do
28
+ When(:other) { Pio::IPv4Address.new('192.168.1.10') }
29
+ Then { result == true }
33
30
  end
34
31
 
35
- describe '#class_b?' do
36
- subject { super().class_b? }
37
- it { is_expected.to be_falsey }
32
+ context "with an IPv4Address ('192.168.1.10/255.255.0.0)" do
33
+ When(:other) { Pio::IPv4Address.new('192.168.1.10/255.255.0.0') }
34
+ Then { result == false }
38
35
  end
39
36
 
40
- describe '#class_c?' do
41
- subject { super().class_c? }
42
- it { is_expected.to be_falsey }
37
+ context "with an IPv4Address ('10.0.1.1')" do
38
+ When(:other) { Pio::IPv4Address.new('10.0.1.1') }
39
+ Then { result == false }
43
40
  end
41
+ end
44
42
 
45
- describe '#class_d?' do
46
- subject { super().class_d? }
47
- it { is_expected.to be_falsey }
48
- end
43
+ describe '#eql?' do
44
+ When(:result) { ipv4.eql? other }
49
45
 
50
- describe '#class_e?' do
51
- subject { super().class_e? }
52
- it { is_expected.to be_falsey }
46
+ context "with an IPv4Address ('192.168.1.10)" do
47
+ When(:other) { Pio::IPv4Address.new('192.168.1.10') }
48
+ Then { result == true }
53
49
  end
54
50
 
55
- describe '#unicast?' do
56
- subject { super().unicast? }
57
- it { is_expected.to be_truthy }
51
+ context "with an IPv4Address ('192.168.1.10/255.255.0.0)" do
52
+ When(:other) { Pio::IPv4Address.new('192.168.1.10/255.255.0.0') }
53
+ Then { result == false }
58
54
  end
59
55
 
60
- describe '#multicast?' do
61
- subject { super().multicast? }
62
- it { is_expected.to be_falsey }
56
+ context "with an IPv4Address ('10.0.1.1')" do
57
+ When(:other) { Pio::IPv4Address.new('10.0.1.1') }
58
+ Then { result == false }
63
59
  end
60
+ end
64
61
 
65
- context '.mask!' do
66
- subject { ipv4.mask!(mask) }
67
-
68
- let(:mask) { 8 }
69
-
70
- describe '#to_s' do
71
- subject { super().to_s }
72
- it { is_expected.to eq '10.0.0.0' }
73
- end
74
-
75
- describe '#to_i' do
76
- subject { super().to_i }
77
- it { is_expected.to eq 10 * 256 * 256 * 256 }
78
- end
79
-
80
- describe '#to_ary' do
81
- subject { super().to_ary }
82
- it { is_expected.to eq [0x0a, 0x00, 0x00, 0x00] }
83
- end
84
-
85
- describe '#class_a?' do
86
- subject { super().class_a? }
87
- it { is_expected.to be_truthy }
88
- end
89
-
90
- describe '#class_b?' do
91
- subject { super().class_b? }
92
- it { is_expected.to be_falsey }
93
- end
94
-
95
- describe '#class_c?' do
96
- subject { super().class_c? }
97
- it { is_expected.to be_falsey }
98
- end
99
-
100
- describe '#class_d?' do
101
- subject { super().class_d? }
102
- it { is_expected.to be_falsey }
103
- end
104
-
105
- describe '#class_e?' do
106
- subject { super().class_e? }
107
- it { is_expected.to be_falsey }
108
- end
109
-
110
- describe '#unicast?' do
111
- subject { super().unicast? }
112
- it { is_expected.to be_truthy }
113
- end
114
-
115
- describe '#multicast?' do
116
- subject { super().multicast? }
117
- it { is_expected.to be_falsey }
118
- end
119
- end
62
+ describe '#hash' do
63
+ When(:result) { ipv4.hash }
64
+ Then { result == Pio::IPv4Address.new('192.168.1.10').hash }
65
+ Then { result != Pio::IPv4Address.new('192.168.1.10/255.255.0.0').hash }
66
+ Then { result != Pio::IPv4Address.new('10.0.1.1').hash }
120
67
  end
121
68
 
122
- context 'with 172.20.1.1' do
123
- let(:ip_address) { '172.20.1.1' }
69
+ describe '#to_a' do
70
+ When(:result) { ipv4.to_a }
71
+ Then { result == [192, 168, 1, 10] }
72
+ end
124
73
 
125
- describe '#to_s' do
126
- subject { super().to_s }
127
- it { is_expected.to eq '172.20.1.1' }
128
- end
74
+ describe '#to_ary' do
75
+ When(:result) { ipv4.to_ary }
76
+ Then { result == [192, 168, 1, 10] }
77
+ end
129
78
 
130
- describe '#to_i' do
131
- subject { super().to_i }
132
- it { is_expected.to eq(((172 * 256 + 20) * 256 + 1) * 256 + 1) }
133
- end
79
+ describe '#mask' do
80
+ When(:result) { ipv4.mask(masklen) }
134
81
 
135
- describe '#to_ary' do
136
- subject { super().to_ary }
137
- it { is_expected.to eq [0xac, 0x14, 0x01, 0x01] }
82
+ context 'with 8' do
83
+ Given(:masklen) { 8 }
84
+ Then { result.to_s == '192.0.0.0' }
138
85
  end
139
86
 
140
- describe '#class_a?' do
141
- subject { super().class_a? }
142
- it { is_expected.to be_falsey }
87
+ context 'with 16' do
88
+ Given(:masklen) { 16 }
89
+ Then { result.to_s == '192.168.0.0' }
143
90
  end
144
91
 
145
- describe '#class_b?' do
146
- subject { super().class_b? }
147
- it { is_expected.to be_truthy }
92
+ context 'with 24' do
93
+ Given(:masklen) { 24 }
94
+ Then { result.to_s == '192.168.1.0' }
148
95
  end
96
+ end
97
+ end
149
98
 
150
- describe '#class_c?' do
151
- subject { super().class_c? }
152
- it { is_expected.to be_falsey }
153
- end
99
+ describe '#class_a?' do
100
+ When(:result) { ipv4.class_a? }
154
101
 
155
- describe '#class_d?' do
156
- subject { super().class_d? }
157
- it { is_expected.to be_falsey }
158
- end
102
+ context 'when IP address = 192.168.0.1' do
103
+ Given(:ip_address) { '192.168.0.1' }
104
+ Then { result == false }
105
+ end
159
106
 
160
- describe '#class_e?' do
161
- subject { super().class_e? }
162
- it { is_expected.to be_falsey }
163
- end
107
+ context 'when IP address = 0.0.0.0' do
108
+ Given(:ip_address) { '0.0.0.0' }
109
+ Then { result == true }
110
+ end
164
111
 
165
- describe '#unicast?' do
166
- subject { super().unicast? }
167
- it { is_expected.to be_truthy }
168
- end
112
+ context 'when IP address = 127.255.255.255' do
113
+ Given(:ip_address) { '127.255.255.255' }
114
+ Then { result == true }
115
+ end
116
+ end
169
117
 
170
- describe '#multicast?' do
171
- subject { super().multicast? }
172
- it { is_expected.to be_falsey }
173
- end
118
+ describe '#class_b?' do
119
+ When(:result) { ipv4.class_b? }
120
+
121
+ context 'when IP address = 223.255.255.255' do
122
+ Given(:ip_address) { '223.255.255.255' }
123
+ Then { result == false }
174
124
  end
175
125
 
176
- context 'with 192.168.1.1' do
177
- let(:ip_address) { '192.168.1.1' }
126
+ context 'when IP address = 128.0.0.0' do
127
+ Given(:ip_address) { '128.0.0.0' }
128
+ Then { result == true }
129
+ end
178
130
 
179
- describe '#to_s' do
180
- subject { super().to_s }
181
- it { is_expected.to eq '192.168.1.1' }
182
- end
131
+ context 'when IP address = 191.255.255.255' do
132
+ Given(:ip_address) { '191.255.255.255' }
133
+ Then { result == true }
134
+ end
135
+ end
183
136
 
184
- describe '#to_i' do
185
- subject { super().to_i }
186
- it { is_expected.to eq 3_232_235_777 }
187
- end
137
+ describe '#class_c?' do
138
+ When(:result) { ipv4.class_c? }
188
139
 
189
- describe '#to_ary' do
190
- subject { super().to_ary }
191
- it { is_expected.to eq [0xc0, 0xa8, 0x01, 0x01] }
192
- end
140
+ context 'when IP address = 10.1.1.1' do
141
+ Given(:ip_address) { '10.1.1.1' }
142
+ Then { result == false }
143
+ end
193
144
 
194
- describe '#class_a?' do
195
- subject { super().class_a? }
196
- it { is_expected.to be_falsey }
197
- end
145
+ context 'when IP address = 192.0.0.0' do
146
+ Given(:ip_address) { '192.0.0.0' }
147
+ Then { result == true }
148
+ end
198
149
 
199
- describe '#class_b?' do
200
- subject { super().class_b? }
201
- it { is_expected.to be_falsey }
202
- end
150
+ context 'when IP address = 223.255.255.255' do
151
+ Given(:ip_address) { '223.255.255.255' }
152
+ Then { result == true }
153
+ end
154
+ end
203
155
 
204
- describe '#class_c?' do
205
- subject { super().class_c? }
206
- it { is_expected.to be_truthy }
207
- end
156
+ describe '#class_d?' do
157
+ When(:result) { ipv4.class_d? }
208
158
 
209
- describe '#class_d?' do
210
- subject { super().class_d? }
211
- it { is_expected.to be_falsey }
212
- end
159
+ context 'when IP address = 10.1.1.1' do
160
+ Given(:ip_address) { '10.1.1.1' }
161
+ Then { result == false }
162
+ end
213
163
 
214
- describe '#class_e?' do
215
- subject { super().class_e? }
216
- it { is_expected.to be_falsey }
217
- end
164
+ context 'when IP address = 224.0.0.0' do
165
+ Given(:ip_address) { '224.0.0.0' }
166
+ Then { result == true }
167
+ end
218
168
 
219
- describe '#unicast?' do
220
- subject { super().unicast? }
221
- it { is_expected.to be_truthy }
222
- end
169
+ context 'when IP address = 239.255.255.255' do
170
+ Given(:ip_address) { '239.255.255.255' }
171
+ Then { result == true }
172
+ end
173
+ end
223
174
 
224
- describe '#multicast?' do
225
- subject { super().multicast? }
226
- it { is_expected.to be_falsey }
227
- end
175
+ describe '#class_e?' do
176
+ When(:result) { ipv4.class_e? }
177
+
178
+ context 'when IP address = 10.1.1.1' do
179
+ Given(:ip_address) { '10.1.1.1' }
180
+ Then { result == false }
228
181
  end
229
182
 
230
- context 'with 234.1.1.1' do
231
- let(:ip_address) { '234.1.1.1' }
183
+ context 'when IP address = 240.0.0.0' do
184
+ Given(:ip_address) { '240.0.0.0' }
185
+ Then { result == true }
186
+ end
232
187
 
233
- describe '#to_s' do
234
- subject { super().to_s }
235
- it { is_expected.to eq '234.1.1.1' }
236
- end
188
+ context 'when IP address = 255.255.255.255' do
189
+ Given(:ip_address) { '255.255.255.255' }
190
+ Then { result == true }
191
+ end
192
+ end
237
193
 
238
- describe '#to_i' do
239
- subject { super().to_i }
240
- it { is_expected.to eq(((234 * 256 + 1) * 256 + 1) * 256 + 1) }
241
- end
194
+ describe '#unicast?' do
195
+ When(:result) { ipv4.unicast? }
242
196
 
243
- describe '#to_ary' do
244
- subject { super().to_ary }
245
- it { is_expected.to eq [0xea, 0x01, 0x01, 0x01] }
246
- end
197
+ context 'when IP address = 10.1.1.1' do
198
+ Given(:ip_address) { '10.1.1.1' }
199
+ Then { result == true }
200
+ end
247
201
 
248
- describe '#class_a?' do
249
- subject { super().class_a? }
250
- it { is_expected.to be_falsey }
251
- end
202
+ context 'when IP address = 234.1.1.1' do
203
+ Given(:ip_address) { '234.1.1.1' }
204
+ Then { result == false }
205
+ end
206
+ end
252
207
 
253
- describe '#class_b?' do
254
- subject { super().class_b? }
255
- it { is_expected.to be_falsey }
256
- end
208
+ describe '#multicast?' do
209
+ When(:result) { ipv4.multicast? }
257
210
 
258
- describe '#class_c?' do
259
- subject { super().class_c? }
260
- it { is_expected.to be_falsey }
261
- end
211
+ context 'when IP address = 10.1.1.1' do
212
+ Given(:ip_address) { '10.1.1.1' }
213
+ Then { result == false }
214
+ end
262
215
 
263
- describe '#class_d?' do
264
- subject { super().class_d? }
265
- it { is_expected.to be_truthy }
266
- end
216
+ context 'when IP address = 234.1.1.1' do
217
+ Given(:ip_address) { '234.1.1.1' }
218
+ Then { result == true }
219
+ end
220
+ end
267
221
 
268
- describe '#class_e?' do
269
- subject { super().class_e? }
270
- it { is_expected.to be_falsey }
271
- end
222
+ describe '#prefixlen' do
223
+ When(:result) { ipv4.prefixlen }
272
224
 
273
- describe '#unicast?' do
274
- subject { super().unicast? }
275
- it { is_expected.to be_falsey }
276
- end
225
+ context 'IP address = with 10.1.1.1' do
226
+ Given(:ip_address) { '10.1.1.1' }
227
+ Then { result == 32 }
228
+ end
277
229
 
278
- describe '#multicast?' do
279
- subject { super().multicast? }
280
- it { is_expected.to be_truthy }
281
- end
230
+ context 'IP address = with 10.1.1.1/255.255.255.255' do
231
+ Given(:ip_address) { '10.1.1.1/255.255.255.255' }
232
+ Then { result == 32 }
282
233
  end
283
234
 
284
- context 'with 192.168.0.1/16' do
285
- let(:ip_address) { '192.168.0.1/16' }
235
+ context 'IP address = with 10.1.1.1/32' do
236
+ Given(:ip_address) { '10.1.1.1/32' }
237
+ Then { result == 32 }
238
+ end
286
239
 
287
- describe '#prefixlen' do
288
- subject { super().prefixlen }
289
- it { is_expected.to eq 16 }
290
- end
240
+ context 'when IP address = 192.168.0.1/255.255.255.0' do
241
+ Given(:ip_address) { '192.168.0.1/255.255.255.0' }
242
+ Then { result == 24 }
291
243
  end
292
244
 
293
- context 'with 192.168.0.1/255.255.255.0' do
294
- let(:ip_address) { '192.168.0.1/255.255.255.0' }
245
+ context 'when IP address = 192.168.0.1/24' do
246
+ Given(:ip_address) { '192.168.0.1/24' }
247
+ Then { result == 24 }
248
+ end
295
249
 
296
- describe '#prefixlen' do
297
- subject { super().prefixlen }
298
- it { is_expected.to eq 24 }
299
- end
250
+ context 'when IP address = 192.168.0.1/255.255.0.0' do
251
+ Given(:ip_address) { '192.168.0.1/255.255.0.0' }
252
+ Then { result == 16 }
253
+ end
254
+
255
+ context 'when IP address = 192.168.0.1/16' do
256
+ Given(:ip_address) { '192.168.0.1/16' }
257
+ Then { result == 16 }
258
+ end
259
+
260
+ context 'when IP address = 192.168.0.1/255.0.0.0' do
261
+ Given(:ip_address) { '192.168.0.1/255.0.0.0' }
262
+ Then { result == 8 }
263
+ end
264
+
265
+ context 'when IP address = 192.168.0.1/8' do
266
+ Given(:ip_address) { '192.168.0.1/8' }
267
+ Then { result == 8 }
300
268
  end
301
269
  end
302
270
  end