pio 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/.travis.yml +1 -0
  4. data/CONTRIBUTING.md +12 -0
  5. data/Gemfile +26 -23
  6. data/Guardfile +5 -0
  7. data/README.md +61 -19
  8. data/Rakefile +54 -56
  9. data/lib/pio/arp/frame.rb +8 -6
  10. data/lib/pio/arp/message.rb +9 -23
  11. data/lib/pio/arp/reply.rb +6 -15
  12. data/lib/pio/arp/request.rb +7 -16
  13. data/lib/pio/arp.rb +14 -17
  14. data/lib/pio/icmp/frame.rb +131 -0
  15. data/lib/pio/icmp/message.rb +100 -0
  16. data/lib/pio/icmp/reply.rb +17 -0
  17. data/lib/pio/icmp/request.rb +17 -0
  18. data/lib/pio/icmp.rb +27 -0
  19. data/lib/pio/ipv4_address.rb +22 -39
  20. data/lib/pio/lldp/chassis_id_tlv.rb +13 -16
  21. data/lib/pio/lldp/end_of_lldpdu_value.rb +4 -5
  22. data/lib/pio/lldp/frame.rb +21 -32
  23. data/lib/pio/lldp/management_address_value.rb +3 -4
  24. data/lib/pio/lldp/optional_tlv.rb +13 -22
  25. data/lib/pio/lldp/organizationally_specific_value.rb +3 -4
  26. data/lib/pio/lldp/port_description_value.rb +3 -4
  27. data/lib/pio/lldp/port_id_tlv.rb +6 -9
  28. data/lib/pio/lldp/system_capabilities_value.rb +3 -4
  29. data/lib/pio/lldp/system_description_value.rb +3 -4
  30. data/lib/pio/lldp/system_name_value.rb +3 -4
  31. data/lib/pio/lldp/ttl_tlv.rb +6 -9
  32. data/lib/pio/lldp.rb +20 -36
  33. data/lib/pio/mac.rb +30 -53
  34. data/lib/pio/message_util.rb +19 -0
  35. data/lib/pio/type/config.reek +4 -0
  36. data/lib/pio/type/ethernet_header.rb +7 -4
  37. data/lib/pio/type/ip_address.rb +5 -8
  38. data/lib/pio/type/ipv4_header.rb +37 -0
  39. data/lib/pio/type/mac_address.rb +7 -8
  40. data/lib/pio/util.rb +21 -0
  41. data/lib/pio/version.rb +2 -2
  42. data/lib/pio.rb +4 -4
  43. data/pio.gemspec +15 -17
  44. data/pio.org +499 -76
  45. data/pio.org_archive +86 -0
  46. data/rubocop-todo.yml +9 -0
  47. data/spec/pio/arp/reply_spec.rb +106 -118
  48. data/spec/pio/arp/request_spec.rb +90 -101
  49. data/spec/pio/arp_spec.rb +105 -113
  50. data/spec/pio/icmp/reply_spec.rb +132 -0
  51. data/spec/pio/icmp/request_spec.rb +131 -0
  52. data/spec/pio/icmp_spec.rb +159 -0
  53. data/spec/pio/ipv4_address_spec.rb +87 -97
  54. data/spec/pio/lldp_spec.rb +237 -186
  55. data/spec/pio/mac_spec.rb +82 -93
  56. data/spec/spec_helper.rb +10 -13
  57. 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:
@@ -1,6 +1,6 @@
1
- require "bindata"
2
- require "pio/mac"
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( octets.inject( "" ) { | str, each | str + ( "%02x" % each ) }.hex )
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
@@ -1,10 +1,10 @@
1
+ # -*- coding: utf-8 -*-
1
2
  # Base module.
2
3
  module Pio
3
4
  # gem version.
4
- VERSION = "0.2.7"
5
+ VERSION = '0.3.0'
5
6
  end
6
7
 
7
-
8
8
  ### Local variables:
9
9
  ### mode: Ruby
10
10
  ### coding: utf-8
data/lib/pio.rb CHANGED
@@ -1,13 +1,13 @@
1
- require "pio/arp"
2
- require "pio/lldp"
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( "../lib", __FILE__ )
2
- $LOAD_PATH.unshift( lib ) unless $LOAD_PATH.include?( lib )
3
- require "pio/version"
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 = "pio"
6
+ gem.name = 'pio'
8
7
  gem.version = Pio::VERSION
9
- gem.summary = "Packet parser and generator."
10
- gem.description = "Pure ruby packet parser and generator."
8
+ gem.summary = 'Packet parser and generator.'
9
+ gem.description = 'Pure ruby packet parser and generator.'
11
10
 
12
- gem.license = "GPL3"
11
+ gem.license = 'GPL3'
13
12
 
14
- gem.authors = [ "Yasuhito Takamiya" ]
15
- gem.email = [ "yasuhito@gmail.com" ]
16
- gem.homepage = "http://github.com/trema/pio"
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( "\n" )
17
+ gem.files = `git ls-files`.split("\n")
19
18
 
20
- gem.require_paths = [ "lib" ]
19
+ gem.require_paths = ['lib']
21
20
 
22
- gem.extra_rdoc_files = [ "README.md" ]
23
- gem.test_files = `git ls-files -- {spec,features}/*`.split( "\n" )
21
+ gem.extra_rdoc_files = ['README.md']
22
+ gem.test_files = `git ls-files -- {spec,features}/*`.split("\n")
24
23
 
25
- gem.add_dependency "bindata", "~> 1.6.0"
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