pio 0.2.7 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.travis.yml +1 -0
- data/CONTRIBUTING.md +12 -0
- data/Gemfile +26 -23
- data/Guardfile +5 -0
- data/README.md +61 -19
- data/Rakefile +54 -56
- data/lib/pio/arp/frame.rb +8 -6
- data/lib/pio/arp/message.rb +9 -23
- data/lib/pio/arp/reply.rb +6 -15
- data/lib/pio/arp/request.rb +7 -16
- data/lib/pio/arp.rb +14 -17
- data/lib/pio/icmp/frame.rb +131 -0
- data/lib/pio/icmp/message.rb +100 -0
- data/lib/pio/icmp/reply.rb +17 -0
- data/lib/pio/icmp/request.rb +17 -0
- data/lib/pio/icmp.rb +27 -0
- data/lib/pio/ipv4_address.rb +22 -39
- data/lib/pio/lldp/chassis_id_tlv.rb +13 -16
- data/lib/pio/lldp/end_of_lldpdu_value.rb +4 -5
- data/lib/pio/lldp/frame.rb +21 -32
- data/lib/pio/lldp/management_address_value.rb +3 -4
- data/lib/pio/lldp/optional_tlv.rb +13 -22
- data/lib/pio/lldp/organizationally_specific_value.rb +3 -4
- data/lib/pio/lldp/port_description_value.rb +3 -4
- data/lib/pio/lldp/port_id_tlv.rb +6 -9
- data/lib/pio/lldp/system_capabilities_value.rb +3 -4
- data/lib/pio/lldp/system_description_value.rb +3 -4
- data/lib/pio/lldp/system_name_value.rb +3 -4
- data/lib/pio/lldp/ttl_tlv.rb +6 -9
- data/lib/pio/lldp.rb +20 -36
- data/lib/pio/mac.rb +30 -53
- data/lib/pio/message_util.rb +19 -0
- data/lib/pio/type/config.reek +4 -0
- data/lib/pio/type/ethernet_header.rb +7 -4
- data/lib/pio/type/ip_address.rb +5 -8
- data/lib/pio/type/ipv4_header.rb +37 -0
- data/lib/pio/type/mac_address.rb +7 -8
- data/lib/pio/util.rb +21 -0
- data/lib/pio/version.rb +2 -2
- data/lib/pio.rb +4 -4
- data/pio.gemspec +15 -17
- data/pio.org +499 -76
- data/pio.org_archive +86 -0
- data/rubocop-todo.yml +9 -0
- data/spec/pio/arp/reply_spec.rb +106 -118
- data/spec/pio/arp/request_spec.rb +90 -101
- data/spec/pio/arp_spec.rb +105 -113
- data/spec/pio/icmp/reply_spec.rb +132 -0
- data/spec/pio/icmp/request_spec.rb +131 -0
- data/spec/pio/icmp_spec.rb +159 -0
- data/spec/pio/ipv4_address_spec.rb +87 -97
- data/spec/pio/lldp_spec.rb +237 -186
- data/spec/pio/mac_spec.rb +82 -93
- data/spec/spec_helper.rb +10 -13
- metadata +20 -2
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'pio/type/ip_address'
|
3
|
+
|
4
|
+
module Pio
|
5
|
+
module Type
|
6
|
+
# IP Version 4 Header Format
|
7
|
+
module IPv4Header
|
8
|
+
# rubocop:disable MethodLength
|
9
|
+
def ipv4_header(options)
|
10
|
+
endian :big
|
11
|
+
class_eval do
|
12
|
+
bit4 :ip_version, :initial_value => 0x4
|
13
|
+
bit4 :ip_header_length, :initial_value => 0x5
|
14
|
+
uint8 :ip_type_of_service, :initial_value => 0
|
15
|
+
uint16be :ip_total_length,
|
16
|
+
:initial_value => options[:ip_total_length]
|
17
|
+
uint16be :ip_identifier, :initial_value => 0
|
18
|
+
bit3 :ip_flag, :initial_value => 0
|
19
|
+
bit13 :ip_fragment, :initial_value => 0
|
20
|
+
uint8 :ip_ttl, :initial_value => 128
|
21
|
+
uint8 :ip_protocol, :value => options[:ip_protocol]
|
22
|
+
uint16be :ip_header_checksum,
|
23
|
+
:initial_value => options[:ip_header_checksum]
|
24
|
+
ip_address :ip_source_address
|
25
|
+
ip_address :ip_destination_address
|
26
|
+
end
|
27
|
+
end
|
28
|
+
# rubocop:enable MethodLength
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
### Local variables:
|
34
|
+
### mode: Ruby
|
35
|
+
### coding: utf-8-unix
|
36
|
+
### indent-tabs-mode: nil
|
37
|
+
### End:
|
data/lib/pio/type/mac_address.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'bindata'
|
3
|
+
require 'pio/mac'
|
4
4
|
|
5
5
|
module Pio
|
6
6
|
module Type
|
@@ -8,20 +8,19 @@ module Pio
|
|
8
8
|
class MacAddress < BinData::Primitive
|
9
9
|
array :octets, :type => :uint8, :initial_length => 6
|
10
10
|
|
11
|
-
|
12
|
-
def set value
|
11
|
+
def set(value)
|
13
12
|
self.octets = value
|
14
13
|
end
|
15
14
|
|
16
|
-
|
17
15
|
def get
|
18
|
-
Mac.new(
|
16
|
+
Mac.new(octets.reduce('') do |str, each|
|
17
|
+
str + sprintf('%02x', each)
|
18
|
+
end.hex)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
|
25
24
|
### Local variables:
|
26
25
|
### mode: Ruby
|
27
26
|
### coding: utf-8-unix
|
data/lib/pio/util.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module Pio
|
3
|
+
# Pio Read Util.
|
4
|
+
module Util
|
5
|
+
def read(raw_data)
|
6
|
+
begin
|
7
|
+
frame = const_get('Frame').read(raw_data)
|
8
|
+
rescue
|
9
|
+
raise Pio::ParseError, $ERROR_INFO.message
|
10
|
+
end
|
11
|
+
|
12
|
+
const_get('MESSAGE_TYPE')[frame.message_type].create_from frame
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
### Local variables:
|
18
|
+
### mode: Ruby
|
19
|
+
### coding: utf-8
|
20
|
+
### indent-tabs-mode: nil
|
21
|
+
### End:
|
data/lib/pio/version.rb
CHANGED
data/lib/pio.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'pio/arp'
|
3
|
+
require 'pio/lldp'
|
4
|
+
require 'pio/icmp'
|
4
5
|
|
5
6
|
module Pio
|
6
7
|
# Raised when the packet data is in wrong format.
|
7
8
|
class ParseError < StandardError; end
|
8
9
|
end
|
9
10
|
|
10
|
-
|
11
11
|
### Local variables:
|
12
12
|
### mode: Ruby
|
13
13
|
### coding: utf-8-unix
|
data/pio.gemspec
CHANGED
@@ -1,31 +1,29 @@
|
|
1
|
-
lib = File.expand_path(
|
2
|
-
$LOAD_PATH.unshift(
|
3
|
-
require
|
4
|
-
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'pio/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do | gem |
|
7
|
-
gem.name =
|
6
|
+
gem.name = 'pio'
|
8
7
|
gem.version = Pio::VERSION
|
9
|
-
gem.summary =
|
10
|
-
gem.description =
|
8
|
+
gem.summary = 'Packet parser and generator.'
|
9
|
+
gem.description = 'Pure ruby packet parser and generator.'
|
11
10
|
|
12
|
-
gem.license =
|
11
|
+
gem.license = 'GPL3'
|
13
12
|
|
14
|
-
gem.authors = [
|
15
|
-
gem.email = [
|
16
|
-
gem.homepage =
|
13
|
+
gem.authors = ['Yasuhito Takamiya']
|
14
|
+
gem.email = ['yasuhito@gmail.com']
|
15
|
+
gem.homepage = 'http://github.com/trema/pio'
|
17
16
|
|
18
|
-
gem.files = `git ls-files`.split(
|
17
|
+
gem.files = `git ls-files`.split("\n")
|
19
18
|
|
20
|
-
gem.require_paths = [
|
19
|
+
gem.require_paths = ['lib']
|
21
20
|
|
22
|
-
gem.extra_rdoc_files = [
|
23
|
-
gem.test_files = `git ls-files -- {spec,features}/*`.split(
|
21
|
+
gem.extra_rdoc_files = ['README.md']
|
22
|
+
gem.test_files = `git ls-files -- {spec,features}/*`.split("\n")
|
24
23
|
|
25
|
-
gem.add_dependency
|
24
|
+
gem.add_dependency 'bindata', '~> 1.6.0'
|
26
25
|
end
|
27
26
|
|
28
|
-
|
29
27
|
### Local variables:
|
30
28
|
### mode: Ruby
|
31
29
|
### coding: utf-8-unix
|