ether_ping 0.1.0 → 0.2.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/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
data/bin/ether_ping CHANGED
@@ -6,8 +6,8 @@ if ARGV.length < 3
6
6
  print <<END_USAGE
7
7
  Usage: #{$0} net_interface dest_mac [ether_type] data
8
8
  net_interface: name of the Ethernet interface, e.g. eth0
9
- ether_type: packet type for the Ethernet II frame, in hex (2 bytes)
10
9
  dest_mac: destination MAC for the ping packets, in hex (6 bytes)
10
+ ether_type: packet type for the Ethernet II frame, in hex (2 bytes)
11
11
  data: ping packet data, in hex (0-padded to 64 bytes)
12
12
 
13
13
  Available Ethernet interfaces:
@@ -32,7 +32,18 @@ client = EtherPing::Client.new interface, ether_type, dest_mac
32
32
  loop do
33
33
  print "Pinging #{dest_mac}... "
34
34
  STDOUT.flush
35
- puts client.ping(data) ? "OK" : "Failed"
35
+ result = client.ping data
36
+ if result
37
+ if result == true
38
+ puts "OK"
39
+ else
40
+ puts "Failed"
41
+ puts "Expected:\n#{result.first.unpack('H*').first}"
42
+ puts "Received:\n#{result.last.unpack('H*').last}"
43
+ end
44
+ else
45
+ puts "Timed out"
46
+ end
36
47
  STDOUT.flush
37
48
  sleep 1
38
49
  end
data/ether_ping.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ether_ping}
8
- s.version = "0.1.0"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{Victor Costan}]
12
- s.date = %q{2011-05-27}
12
+ s.date = %q{2011-05-29}
13
13
  s.description = %q{Contains an Ethernet-level ping server and client.}
14
14
  s.email = %q{victor@costan.us}
15
15
  s.executables = [%q{ether_ping_server}, %q{ether_ping}]
@@ -18,7 +18,8 @@ class Client
18
18
 
19
19
  # Pings over raw Ethernet sockets.
20
20
  #
21
- # Returns true if the ping receives a response, false otherwise.
21
+ # Returns true if the ping response matches, an array of [expected,
22
+ # received] strings if it doesn't match, and false if the ping times out.
22
23
  def ping(data, timeout = 1)
23
24
  data = data.clone
24
25
  # Pad data to have at least 64 bytes.
@@ -28,9 +29,17 @@ class Client
28
29
  @socket.send ping_packet, 0
29
30
 
30
31
  response_packet = @source_mac + @dest_mac + @ether_type + data
31
- response = @socket.recv response_packet.length * 2
32
32
 
33
- response == response_packet
33
+ response = nil
34
+ begin
35
+ Timeout.timeout timeout do
36
+ response = @socket.recv response_packet.length * 2
37
+ end
38
+ rescue Timeout::Error
39
+ response = nil
40
+ end
41
+ return false unless response
42
+ response == response_packet || [response, response_packet]
34
43
  end
35
44
  end # module EtherPing::Client
36
45
 
@@ -1,3 +1,5 @@
1
+ require 'timeout'
2
+
1
3
  require 'ethernet'
2
4
 
3
5
  # :nodoc: namespace
@@ -7,14 +9,14 @@ module EtherPing
7
9
  class Server
8
10
  module Connection
9
11
  def receive_data(packet)
10
- source_mac = packet[0, 6].unpack('H*')
11
- dest_mac = packet[6, 6].unpack('H*')
12
+ dest_mac = packet[0, 6].unpack('H*')
13
+ source_mac = packet[6, 6].unpack('H*')
12
14
  ether_type = packet[12, 2].unpack('H*')
13
15
 
14
16
  puts "Src: #{source_mac} Dst: #{dest_mac} Eth: #{ether_type}\n"
15
17
  puts packet[14..-1].unpack('H*')
16
18
 
17
- # Exchange the source and destination ARP addresses.
19
+ # Exchange the source and destination MAC addresses.
18
20
  packet[0, 6], packet[6, 6] = packet[6, 6], packet[0, 6]
19
21
  send_data packet
20
22
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ether_ping
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 0.1.0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Victor Costan
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-05-27 00:00:00 Z
18
+ date: 2011-05-29 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  type: :runtime