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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 73ce00f558de61b898267a5ad530362ace3e4c84
4
- data.tar.gz: 9df827c044267c93d109c49f343e758f08795efd
3
+ metadata.gz: 75af6278d342dd6e8c2b0c675d1f3f7d82ab3474
4
+ data.tar.gz: d5e0ee260a39d472ecf3d950e849f33f2558f52d
5
5
  SHA512:
6
- metadata.gz: 9baf83820618e20a64b952b43086c3fd3295b1bdf72fa45da093db3ce35da9dee338e5e512d5221616ae04acbfde492476d2c66bede1f2c4b98f6ff8e6306d54
7
- data.tar.gz: 20bc42f2e58a9c25513613689d54d65ee89f70782b2839590da3e64bb928e815105cecd63e61bece1ccc16afbd2669eea98652cc49774171d33ce12abe4f8d80
6
+ metadata.gz: 780986656174b5c659d486c2affca51f2fd70d09bb848198cf501668670628d5fcf6a3d640af5c8a709fcbad1ab241c4fe50921350964492278267207ed0883a
7
+ data.tar.gz: 59b6ddea90c19e05307ab2b2f2a8be7b201f5f872fd58824aca29acc1923a1d8eccc1c8a881bf0150568c7ddeab3a029afab45725067f971f95e9be979a9a072
data/.rubocop.yml ADDED
@@ -0,0 +1 @@
1
+ inherit_from: rubocop-todo.yml
data/.travis.yml CHANGED
@@ -3,6 +3,7 @@ language: ruby
3
3
  script: "rake travis"
4
4
 
5
5
  rvm:
6
+ - 1.8.7
6
7
  - 1.9.3
7
8
  - 2.0.0
8
9
 
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,12 @@
1
+ # Contributing to Pio
2
+
3
+ * Check out the latest develop to make sure the feature hasn't been
4
+ implemented or the bug hasn't been fixed yet.
5
+ * Check out the issue tracker to make sure someone already hasn't
6
+ requested it and/or contributed it.
7
+ * Fork the project.
8
+ * Commit and push until you are happy with your contribution.
9
+ * Make sure to add tests for it. This is important so I don't break it
10
+ in a future version unintentionally.
11
+ * Squash your commits.
12
+ * Create a pull-request.
data/Gemfile CHANGED
@@ -1,32 +1,35 @@
1
- source "https://rubygems.org"
2
-
1
+ source 'https://rubygems.org'
3
2
 
4
3
  gemspec
5
4
 
6
-
7
5
  group :development, :test do
8
- gem "coveralls", "~> 0.7.0", :require => false
9
- gem "flay", "~> 2.4.0"
10
- gem "flog", "~> 4.1.2"
11
- gem "fuubar", "~> 1.2.1"
12
- gem "guard", "~> 1.8"
13
- gem "guard-bundler", "~> 1.0.0"
14
- gem "guard-rspec", "~> 3.1.0"
15
- gem "json", "~> 1.8.0"
16
- gem "rake", "~> 10.1.0"
17
- gem "rb-fchange", "~> 0.0.6", :require => false
18
- gem "rb-fsevent", "~> 0.9.3", :require => false
19
- gem "rb-inotify", "~> 0.9.2", :require => false
20
- gem "redcarpet", "~> 2.3.0" if RUBY_VERSION < "1.9.0"
21
- gem "redcarpet", "~> 3.0.0" if RUBY_VERSION >= "1.9.0"
22
- gem "reek", "~> 1.3.3"
23
- gem "rspec", "~> 2.14.1"
24
- gem "rspec-instafail", "~> 0.2.4"
25
- gem "terminal-notifier-guard", "~> 1.5.3"
26
- gem "yard", "~> 0.8.7.2"
6
+ gem 'coveralls', '~> 0.7.0', :require => false
7
+ gem 'flay', '~> 2.4.0'
8
+ gem 'flog', '~> 4.2.0'
9
+ gem 'fuubar', '~> 1.2.1'
10
+ gem 'guard', '~> 1.8.3' if RUBY_VERSION < '1.9.0'
11
+ gem 'guard', '~> 2.2.2' if RUBY_VERSION >= '1.9.0'
12
+ gem 'guard-bundler', '~> 1.0.0' if RUBY_VERSION < '1.9.0'
13
+ gem 'guard-bundler', '~> 2.0.0' if RUBY_VERSION >= '1.9.0'
14
+ gem 'guard-rspec', '~> 3.1.0' if RUBY_VERSION < '1.9.0'
15
+ gem 'guard-rspec', '~> 4.0.3' if RUBY_VERSION >= '1.9.0'
16
+ gem 'json', '~> 1.8.1'
17
+ gem 'mime-types', '~> 1.25' if RUBY_VERSION < '1.9.0'
18
+ gem 'mime-types', '~> 2.0' if RUBY_VERSION >= '1.9.0'
19
+ gem 'rake', '~> 10.1.0'
20
+ gem 'rb-fchange', '~> 0.0.6', :require => false
21
+ gem 'rb-fsevent', '~> 0.9.3', :require => false
22
+ gem 'rb-inotify', '~> 0.9.2', :require => false
23
+ gem 'redcarpet', '~> 2.3.0' if RUBY_VERSION < '1.9.0'
24
+ gem 'redcarpet', '~> 3.0.0' if RUBY_VERSION >= '1.9.0'
25
+ gem 'reek', '~> 1.3.4'
26
+ gem 'rspec', '~> 2.14.1'
27
+ gem 'rspec-instafail', '~> 0.2.4'
28
+ gem 'rubocop', '~> 0.14.1' if RUBY_VERSION >= '1.9.0'
29
+ gem 'terminal-notifier-guard', '~> 1.5.3'
30
+ gem 'yard', '~> 0.8.7.3'
27
31
  end
28
32
 
29
-
30
33
  ### Local variables:
31
34
  ### mode: Ruby
32
35
  ### coding: utf-8-unix
data/Guardfile CHANGED
@@ -17,3 +17,8 @@ guard :rspec do
17
17
  watch(%r{^lib/pio/(.+)\.rb$}) { |m| "spec/pio/#{m[1]}_spec.rb" }
18
18
  watch('spec/spec_helper.rb') { "spec" }
19
19
  end
20
+
21
+ guard :bundler do
22
+ watch('Gemfile')
23
+ watch(/^.+\.gemspec/)
24
+ end
data/README.md CHANGED
@@ -10,6 +10,7 @@ Pio
10
10
 
11
11
  Pio is a ruby gem to easily parse and generate network packets. It supports the following packet formats:
12
12
 
13
+ * ICMP
13
14
  * ARP
14
15
  * LLDP
15
16
  * (...currently there are just a few formats supported but I'm sure this list will grow)
@@ -28,41 +29,80 @@ Features Overview
28
29
  format DSL so that it is easy to read and debug by human beings.
29
30
 
30
31
 
31
- Example
32
- -------
32
+ Examples
33
+ --------
33
34
 
34
35
  Its usage is dead simple.
35
36
 
37
+ ### ICMP
38
+
39
+ To parse an ICMP frame, use the API `Pio::Icmp.read` and you can
40
+ access each field of the parsed ICMP frame.
41
+
42
+ ```ruby
43
+ require 'pio'
44
+ icmp = Pio::Icmp.read(binary_data)
45
+ icmp.source_mac.to_s #=> '00:26:82:eb:ea:d1'
46
+ ```
47
+
48
+ Also you can use `Pio::Icmp::Request#new` or `Pio::Icmp::Reply#new` to
49
+ generate an Icmp Request/Reply frame like below:
50
+
51
+ ```ruby
52
+ require 'pio'
53
+
54
+ request = Pio::Icmp::Request.new(
55
+ source_mac: '00:26:82:eb:ea:d1',
56
+ destination_mac: '00:26:82:eb:ea:d1',
57
+ ip_source_address: '192.168.83.3',
58
+ ip_destination_address: '192.168.83.254'
59
+ )
60
+ request.to_binary #=> ICMP Request frame in binary format.
61
+
62
+ reply = Pio::Icmp::Reply.new(
63
+ destination_mac: '00:26:82:eb:ea:d1',
64
+ source_mac: '00:00:00:00:00:01',
65
+ ip_source_address: '192.168.0.1',
66
+ ip_destination_address: '192.168.0.2',
67
+ # The ICMP Identifier and the ICMP Sequence number
68
+ # should be same as those of the request.
69
+ icmp_identifier: request.icmp_identifier,
70
+ icmp_sequence_number: request.icmp_sequence_number,
71
+ echo_data: request.echo_data
72
+ )
73
+ reply.to_binary #=> ICMP Reply frame in binary format.
74
+ ```
75
+
36
76
  ### ARP
37
77
 
38
78
  To parse an ARP frame, use the API `Pio::Arp.read` and you can access
39
79
  each field of the parsed ARP frame.
40
80
 
41
81
  ```ruby
42
- require "pio"
82
+ require 'pio'
43
83
 
44
- arp = Pio::Arp.read( binary_data )
45
- arp.source_mac.to_s #=> "00:26:82:eb:ea:d1"
84
+ arp = Pio::Arp.read(binary_data)
85
+ arp.source_mac.to_s #=> '00:26:82:eb:ea:d1'
46
86
  ```
47
87
 
48
88
  Also you can use `Pio::Arp::Request#new` or `Pio::Arp::Reply#new` to
49
89
  generate an Arp Request/Reply frame like below:
50
90
 
51
91
  ```ruby
52
- require "pio"
92
+ require 'pio'
53
93
 
54
94
  request = Pio::Arp::Request.new(
55
- source_mac: "00:26:82:eb:ea:d1",
56
- sender_protocol_address: "192.168.83.3",
57
- target_protocol_address: "192.168.83.254"
95
+ source_mac: '00:26:82:eb:ea:d1',
96
+ sender_protocol_address: '192.168.83.3',
97
+ target_protocol_address: '192.168.83.254'
58
98
  )
59
99
  request.to_binary #=> Arp Request frame in binary format.
60
100
 
61
101
  reply = Pio::Arp::Reply.new(
62
- source_mac: "00:26:82:eb:ea:d1",
63
- destination_mac: "00:26:82:eb:ea:d1",
64
- sender_protocol_address: "192.168.83.3",
65
- target_protocol_address: "192.168.83.254"
102
+ source_mac: '00:26:82:eb:ea:d1',
103
+ destination_mac: '00:26:82:eb:ea:d1',
104
+ sender_protocol_address: '192.168.83.3',
105
+ target_protocol_address: '192.168.83.254'
66
106
  )
67
107
  reply.to_binary #=> Arp Reply frame in binary format.
68
108
  ```
@@ -73,18 +113,18 @@ To parse an LLDP frame, use the API `Pio::Lldp.read` and you can
73
113
  access each field of the parsed LLDP frame.
74
114
 
75
115
  ```ruby
76
- require "pio"
116
+ require 'pio'
77
117
 
78
- lldp = Pio::Lldp.read( binary_data )
118
+ lldp = Pio::Lldp.read(binary_data)
79
119
  lldp.ttl #=> 120
80
120
  ```
81
121
 
82
122
  Also you can use `Pio::Lldp#new` to generate an LLDP frame like below:
83
123
 
84
124
  ```ruby
85
- require "pio"
125
+ require 'pio'
86
126
 
87
- lldp = Pio::Lldp.new( dpid: 0x123, port_number: 12 )
127
+ lldp = Pio::Lldp.new(dpid: 0x123, port_number: 12)
88
128
  lldp.to_binary #=> LLDP frame in binary format.
89
129
  ```
90
130
 
@@ -113,9 +153,11 @@ Documents
113
153
  * [API document generated with YARD](http://rubydoc.info/github/trema/pio/frames/file/README.md)
114
154
 
115
155
 
116
- ### Author
156
+ Team
157
+ ----
117
158
 
118
- [Yasuhito Takamiya](https://github.com/yasuhito) ([@yasuhito](http://twitter.com/yasuhito))
159
+ * [Yasuhito Takamiya](https://github.com/yasuhito) ([@yasuhito](https://twitter.com/yasuhito))
160
+ * [Eishun Kondoh](https://github.com/shun159) ([@Eishun_Kondoh](https://twitter.com/Eishun_Kondoh))
119
161
 
120
162
  ### Contributors
121
163
 
data/Rakefile CHANGED
@@ -1,101 +1,99 @@
1
- require "bundler/gem_tasks"
2
- require "coveralls/rake/task"
3
- require "flay"
4
- require "flay_task"
5
- require "flog"
6
- require "rake/tasklib"
7
- require "reek/rake/task"
8
- require "rspec/core"
9
- require "rspec/core/rake_task"
10
- require "yaml"
11
- require "yard"
12
-
13
-
14
- $ruby_source = FileList[ "lib/**/*.rb" ]
15
-
1
+ require 'bundler/gem_tasks'
2
+ require 'coveralls/rake/task'
3
+ require 'flay'
4
+ require 'flay_task'
5
+ require 'flog'
6
+ require 'rake/tasklib'
7
+ require 'reek/rake/task'
8
+ require 'rspec/core'
9
+ require 'rspec/core/rake_task'
10
+ require 'yaml'
11
+ require 'yard'
12
+
13
+ ruby_source = FileList['lib/**/*.rb']
16
14
 
17
15
  task :default => :travis
18
- task :travis => [ :spec, :quality, "coveralls:push" ]
19
-
20
- desc "Check for code quality"
21
- task :quality => [ :reek, :flog, :flay ]
16
+ task :travis => [:spec, :quality, 'coveralls:push']
22
17
 
18
+ desc 'Check for code quality'
19
+ task :quality => [:reek, :flog, :flay]
23
20
 
24
21
  Coveralls::RakeTask.new
25
22
 
26
-
27
23
  RSpec::Core::RakeTask.new
28
24
 
29
-
30
- Reek::Rake::Task.new do | t |
25
+ Reek::Rake::Task.new do |t|
31
26
  t.fail_on_error = false
32
27
  t.verbose = false
33
- t.ruby_opts = [ "-rubygems" ]
34
- t.reek_opts = "--quiet"
35
- t.source_files = $ruby_source
28
+ t.ruby_opts = ['-rubygems']
29
+ t.reek_opts = '--quiet'
30
+ t.source_files = ruby_source
36
31
  end
37
32
 
38
-
39
- desc "Analyze for code complexity"
33
+ desc 'Analyze for code complexity'
40
34
  task :flog do
41
- flog = Flog.new( :continue => true )
42
- flog.flog( *$ruby_source )
43
- threshold = 20
35
+ flog = Flog.new(:continue => true)
36
+ flog.flog(*ruby_source)
37
+ threshold = 28
44
38
 
45
- bad_methods = flog.totals.select do | name, score |
46
- ( not ( /##{flog.no_method}$/=~ name ) ) and score > threshold
39
+ bad_methods = flog.totals.select do |name, score|
40
+ !(/##{flog.no_method}$/ =~ name) && score > threshold
47
41
  end
48
- bad_methods.sort do | a, b |
49
- a[ 1 ] <=> b[ 1 ]
50
- end.reverse.each do | name, score |
51
- puts "%8.1f: %s" % [ score, name ]
42
+ bad_methods.sort { |a, b| a[1] <=> b[1] }.reverse.each do |name, score|
43
+ printf "%8.1f: %s\n", score, name
52
44
  end
53
45
  unless bad_methods.empty?
54
- $stderr.puts "#{ bad_methods.size } methods have a flog complexity > #{ threshold }"
46
+ $stderr.puts "#{bad_methods.size} methods have a complexity > #{threshold}"
55
47
  end
56
48
  end
57
49
 
58
-
59
- FlayTask.new do | t |
60
- t.dirs = $ruby_source.collect do | each |
61
- each[ /[^\/]+/ ]
50
+ FlayTask.new do |t|
51
+ t.dirs = ruby_source.map do |each|
52
+ each[/[^\/]+/]
62
53
  end.uniq
63
54
  t.threshold = 0
64
- t.verbose = $trace
55
+ t.verbose = true
65
56
  end
66
57
 
67
-
68
- YARD::Rake::YardocTask.new do | t |
69
- t.options = [ "--no-private" ]
70
- t.options << "--debug" << "--verbose" if $trace
58
+ if RUBY_VERSION >= '1.9.0'
59
+ task :quality => :rubocop
60
+ require 'rubocop/rake_task'
61
+ Rubocop::RakeTask.new
71
62
  end
72
63
 
64
+ YARD::Rake::YardocTask.new do |t|
65
+ t.options = ['--no-private']
66
+ t.options << '--debug' << '--verbose' if Rake.verbose
67
+ end
73
68
 
74
69
  def travis_yml
75
- File.join File.dirname( __FILE__ ), ".travis.yml"
70
+ File.join File.dirname(__FILE__), '.travis.yml'
76
71
  end
77
72
 
78
-
79
73
  def rubies
80
- ( [ "1.8.7" ] + YAML.load_file( travis_yml )[ "rvm" ] ).uniq.sort
74
+ YAML.load_file(travis_yml)['rvm'].uniq.sort
81
75
  end
82
76
 
77
+ def gemfile_lock
78
+ File.join File.dirname(__FILE__), 'Gemfile.lock'
79
+ end
83
80
 
84
- desc "Run tests against multiple rubies"
81
+ desc 'Run tests against multiple rubies'
85
82
  task :portability
86
83
 
87
- rubies.each do | each |
88
- portability_task_name = "portability:#{ each }"
84
+ rubies.each do |each|
85
+ portability_task_name = "portability:#{each}"
89
86
  task :portability => portability_task_name
90
87
 
91
- desc "Run tests against Ruby#{ each }"
88
+ desc "Run tests against Ruby#{each}"
92
89
  task portability_task_name do
93
- sh "rvm #{ each } exec bundle"
94
- sh "rvm #{ each } exec bundle exec rake"
90
+ rm_f gemfile_lock
91
+ sh "rvm #{each} exec bundle update"
92
+ sh "rvm #{each} exec bundle install"
93
+ sh "rvm #{each} exec bundle exec rake"
95
94
  end
96
95
  end
97
96
 
98
-
99
97
  ### Local variables:
100
98
  ### mode: Ruby
101
99
  ### coding: utf-8-unix
data/lib/pio/arp/frame.rb CHANGED
@@ -1,7 +1,7 @@
1
- require "pio/type/ethernet_header"
2
- require "pio/type/ip_address"
3
- require "pio/type/mac_address"
4
-
1
+ # -*- coding: utf-8 -*-
2
+ require 'pio/type/ethernet_header'
3
+ require 'pio/type/ip_address'
4
+ require 'pio/type/mac_address'
5
5
 
6
6
  module Pio
7
7
  class Arp
@@ -22,15 +22,17 @@ module Pio
22
22
  mac_address :target_hardware_address
23
23
  ip_address :target_protocol_address
24
24
 
25
+ def message_type
26
+ operation
27
+ end
25
28
 
26
29
  def to_binary
27
- to_binary_s + "\000" * ( 64 - num_bytes )
30
+ to_binary_s + "\000" * (64 - num_bytes)
28
31
  end
29
32
  end
30
33
  end
31
34
  end
32
35
 
33
-
34
36
  ### Local variables:
35
37
  ### mode: Ruby
36
38
  ### coding: utf-8-unix
@@ -1,28 +1,27 @@
1
- require "forwardable"
2
- require "pio/arp/frame"
3
- require "pio/ipv4_address"
4
-
1
+ # -*- coding: utf-8 -*-
2
+ require 'forwardable'
3
+ require 'pio/arp/frame'
4
+ require 'pio/ipv4_address'
5
+ require 'pio/message_util'
5
6
 
6
7
  module Pio
7
8
  class Arp
8
9
  # Base class of ARP Request and Reply
9
10
  class Message
10
11
  extend Forwardable
12
+ include MessageUtil
11
13
 
12
-
13
- def self.create_from frame
14
+ def self.create_from(frame)
14
15
  message = allocate
15
16
  message.instance_variable_set :@frame, frame
16
17
  message
17
18
  end
18
19
 
19
-
20
- def initialize options
20
+ def initialize(options)
21
21
  @options = options
22
- @frame = Arp::Frame.new( option_hash )
22
+ @frame = Arp::Frame.new(option_hash)
23
23
  end
24
24
 
25
-
26
25
  def_delegators :@frame, :destination_mac
27
26
  def_delegators :@frame, :source_mac
28
27
  def_delegators :@frame, :ether_type
@@ -37,20 +36,7 @@ module Pio
37
36
  def_delegators :@frame, :target_protocol_address
38
37
  def_delegators :@frame, :to_binary
39
38
 
40
-
41
- ##########################################################################
42
39
  private
43
- ##########################################################################
44
-
45
-
46
- def option_hash
47
- mandatory_options.inject( {} ) do | opt, each |
48
- klass = option_to_klass[ each ]
49
- opt_pair = { each => klass.new( user_options[ each ] ).to_a }
50
- opt.merge opt_pair
51
- end.merge default_options
52
- end
53
-
54
40
 
55
41
  def option_to_klass
56
42
  {
data/lib/pio/arp/reply.rb CHANGED
@@ -1,7 +1,7 @@
1
- require "forwardable"
2
- require "pio/arp/message"
3
- require "pio/mac"
4
-
1
+ # -*- coding: utf-8 -*-
2
+ require 'forwardable'
3
+ require 'pio/arp/message'
4
+ require 'pio/mac'
5
5
 
6
6
  module Pio
7
7
  class Arp
@@ -9,11 +9,7 @@ module Pio
9
9
  class Reply < Message
10
10
  OPERATION = 2
11
11
 
12
-
13
- ##########################################################################
14
12
  private
15
- ##########################################################################
16
-
17
13
 
18
14
  def default_options
19
15
  {
@@ -21,17 +17,13 @@ module Pio
21
17
  }
22
18
  end
23
19
 
24
-
25
20
  def user_options
26
21
  @options.merge(
27
- {
28
- :sender_hardware_address => @options[ :source_mac ],
29
- :target_hardware_address => @options[ :destination_mac ]
30
- }
22
+ :sender_hardware_address => @options[:source_mac],
23
+ :target_hardware_address => @options[:destination_mac]
31
24
  )
32
25
  end
33
26
 
34
-
35
27
  def mandatory_options
36
28
  [
37
29
  :source_mac,
@@ -46,7 +38,6 @@ module Pio
46
38
  end
47
39
  end
48
40
 
49
-
50
41
  ### Local variables:
51
42
  ### mode: Ruby
52
43
  ### coding: utf-8-unix
@@ -1,7 +1,7 @@
1
- require "pio/arp/frame"
2
- require "pio/arp/message"
3
- require "pio/mac"
4
-
1
+ # -*- coding: utf-8 -*-
2
+ require 'pio/arp/frame'
3
+ require 'pio/arp/message'
4
+ require 'pio/mac'
5
5
 
6
6
  module Pio
7
7
  class Arp
@@ -9,14 +9,10 @@ module Pio
9
9
  class Request < Message
10
10
  OPERATION = 1
11
11
 
12
- BROADCAST_MAC_ADDRESS = Mac.new( 0xffffffffffff ).to_a
13
- ALL_ZERO_MAC_ADDRESS = Mac.new( 0 ).to_a
14
-
12
+ BROADCAST_MAC_ADDRESS = Mac.new(0xffffffffffff).to_a
13
+ ALL_ZERO_MAC_ADDRESS = Mac.new(0).to_a
15
14
 
16
- ########################################################################
17
15
  private
18
- ########################################################################
19
-
20
16
 
21
17
  def default_options
22
18
  {
@@ -26,14 +22,10 @@ module Pio
26
22
  }
27
23
  end
28
24
 
29
-
30
25
  def user_options
31
- @options.merge(
32
- { :sender_hardware_address => @options[ :source_mac ] }
33
- )
26
+ @options.merge :sender_hardware_address => @options[:source_mac]
34
27
  end
35
28
 
36
-
37
29
  def mandatory_options
38
30
  [
39
31
  :source_mac,
@@ -46,7 +38,6 @@ module Pio
46
38
  end
47
39
  end
48
40
 
49
-
50
41
  ### Local variables:
51
42
  ### mode: Ruby
52
43
  ### coding: utf-8-unix
data/lib/pio/arp.rb CHANGED
@@ -1,29 +1,26 @@
1
- require "rubygems"
2
- require "bindata"
3
-
4
- require "pio/arp/request"
5
- require "pio/arp/reply"
1
+ # -*- coding: utf-8 -*-
2
+ require 'English'
3
+ require 'rubygems'
4
+ require 'bindata'
6
5
 
6
+ require 'pio/arp/request'
7
+ require 'pio/arp/reply'
8
+ require 'pio/util'
7
9
 
8
10
  module Pio
9
11
  # ARP parser and generator.
10
- class Arp
11
- ARP_MESSAGE_TYPE = { Request::OPERATION => Request, Reply::OPERATION => Reply }
12
-
13
12
 
14
- def self.read( raw_data )
15
- begin
16
- frame = Arp::Frame.read( raw_data )
17
- rescue
18
- raise Pio::ParseError, $!.message
19
- end
20
-
21
- ARP_MESSAGE_TYPE[ frame.operation ].create_from frame
13
+ class Arp
14
+ MESSAGE_TYPE = {
15
+ Request::OPERATION => Request,
16
+ Reply::OPERATION => Reply
17
+ }
18
+ class << self
19
+ include Util
22
20
  end
23
21
  end
24
22
  end
25
23
 
26
-
27
24
  ### Local variables:
28
25
  ### mode: Ruby
29
26
  ### coding: utf-8-unix