ethernet 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -1
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/ethernet.gemspec +4 -7
- data/lib/ethernet.rb +0 -4
- metadata +6 -8
- data/bin/ethernet_ping +0 -30
- data/lib/ethernet/ping.rb +0 -89
data/Gemfile
CHANGED
@@ -9,7 +9,7 @@ gem 'system-getifaddrs', '~> 0.1.1', :platform => :ruby,
|
|
9
9
|
# Add dependencies to develop your gem here.
|
10
10
|
# Include everything needed to run rake, tests, features, etc.
|
11
11
|
group :development do
|
12
|
-
gem 'rdoc', '
|
12
|
+
gem 'rdoc', '>= 3.6.1'
|
13
13
|
gem 'rspec', '~> 2.6.0'
|
14
14
|
gem 'bundler', '~> 1.0.0'
|
15
15
|
gem 'jeweler', '~> 1.6.0'
|
data/Gemfile.lock
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/ethernet.gemspec
CHANGED
@@ -5,14 +5,13 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{ethernet}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
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}, %q{HaoQi Li}]
|
12
12
|
s.date = %q{2011-05-27}
|
13
13
|
s.description = %q{Provides a Socket-like API that bypasses TCP/IP. Useful for exotic devices and FPGA development.}
|
14
14
|
s.email = %q{victor@costan.us}
|
15
|
-
s.executables = [%q{ethernet_ping}]
|
16
15
|
s.extra_rdoc_files = [
|
17
16
|
"LICENSE.txt",
|
18
17
|
"README.rdoc"
|
@@ -27,12 +26,10 @@ Gem::Specification.new do |s|
|
|
27
26
|
"README.rdoc",
|
28
27
|
"Rakefile",
|
29
28
|
"VERSION",
|
30
|
-
"bin/ethernet_ping",
|
31
29
|
"ethernet.gemspec",
|
32
30
|
"lib/ethernet.rb",
|
33
31
|
"lib/ethernet/devices.rb",
|
34
32
|
"lib/ethernet/frame_socket.rb",
|
35
|
-
"lib/ethernet/ping.rb",
|
36
33
|
"lib/ethernet/provisioning.rb",
|
37
34
|
"lib/ethernet/raw_socket_factory.rb",
|
38
35
|
"spec/ethernet/devices_spec.rb",
|
@@ -54,14 +51,14 @@ Gem::Specification.new do |s|
|
|
54
51
|
|
55
52
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
56
53
|
s.add_runtime_dependency(%q<system-getifaddrs>, ["~> 0.1.1"])
|
57
|
-
s.add_development_dependency(%q<rdoc>, ["
|
54
|
+
s.add_development_dependency(%q<rdoc>, [">= 3.6.1"])
|
58
55
|
s.add_development_dependency(%q<rspec>, ["~> 2.6.0"])
|
59
56
|
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
60
57
|
s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
|
61
58
|
s.add_development_dependency(%q<rcov>, [">= 0"])
|
62
59
|
else
|
63
60
|
s.add_dependency(%q<system-getifaddrs>, ["~> 0.1.1"])
|
64
|
-
s.add_dependency(%q<rdoc>, ["
|
61
|
+
s.add_dependency(%q<rdoc>, [">= 3.6.1"])
|
65
62
|
s.add_dependency(%q<rspec>, ["~> 2.6.0"])
|
66
63
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
67
64
|
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
@@ -69,7 +66,7 @@ Gem::Specification.new do |s|
|
|
69
66
|
end
|
70
67
|
else
|
71
68
|
s.add_dependency(%q<system-getifaddrs>, ["~> 0.1.1"])
|
72
|
-
s.add_dependency(%q<rdoc>, ["
|
69
|
+
s.add_dependency(%q<rdoc>, [">= 3.6.1"])
|
73
70
|
s.add_dependency(%q<rspec>, ["~> 2.6.0"])
|
74
71
|
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
75
72
|
s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
|
data/lib/ethernet.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ethernet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Victor Costan
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
|
-
- -
|
42
|
+
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
hash: 29
|
45
45
|
segments:
|
@@ -114,8 +114,8 @@ dependencies:
|
|
114
114
|
name: rcov
|
115
115
|
description: Provides a Socket-like API that bypasses TCP/IP. Useful for exotic devices and FPGA development.
|
116
116
|
email: victor@costan.us
|
117
|
-
executables:
|
118
|
-
|
117
|
+
executables: []
|
118
|
+
|
119
119
|
extensions: []
|
120
120
|
|
121
121
|
extra_rdoc_files:
|
@@ -131,12 +131,10 @@ files:
|
|
131
131
|
- README.rdoc
|
132
132
|
- Rakefile
|
133
133
|
- VERSION
|
134
|
-
- bin/ethernet_ping
|
135
134
|
- ethernet.gemspec
|
136
135
|
- lib/ethernet.rb
|
137
136
|
- lib/ethernet/devices.rb
|
138
137
|
- lib/ethernet/frame_socket.rb
|
139
|
-
- lib/ethernet/ping.rb
|
140
138
|
- lib/ethernet/provisioning.rb
|
141
139
|
- lib/ethernet/raw_socket_factory.rb
|
142
140
|
- spec/ethernet/devices_spec.rb
|
data/bin/ethernet_ping
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require 'rubygems'
|
3
|
-
require 'ethernet' #'scratchpad'
|
4
|
-
|
5
|
-
if ARGV.length < 4
|
6
|
-
print <<END_USAGE
|
7
|
-
Usage: #{$0} net_interface ether_type dest_mac data
|
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
|
-
dest_mac: destination MAC for the ping packets, in hex (6 bytes)
|
11
|
-
data: ping packet data, in hex (0-padded to 64 bytes)
|
12
|
-
END_USAGE
|
13
|
-
exit 1
|
14
|
-
end
|
15
|
-
|
16
|
-
interface = ARGV[0]
|
17
|
-
ether_type = [ARGV[1]].pack('H*').unpack('n').first
|
18
|
-
dest_mac = ARGV[2]
|
19
|
-
data = [ARGV[3]].pack('H*')
|
20
|
-
|
21
|
-
#client = Scratchpad::Ethernet::PingClient.new interface, ether_type, dest_mac
|
22
|
-
client = Ethernet::PingClient.new interface, ether_type, dest_mac
|
23
|
-
|
24
|
-
loop do
|
25
|
-
print "Pinging #{dest_mac}... "
|
26
|
-
STDOUT.flush
|
27
|
-
puts client.ping(data) ? "OK" : "Failed"
|
28
|
-
STDOUT.flush
|
29
|
-
sleep 1
|
30
|
-
end
|
data/lib/ethernet/ping.rb
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
# TODO(pwnall): move to separate gem
|
2
|
-
|
3
|
-
|
4
|
-
# copied from victor's scratchpad/lib/scratchpad/ethernet/ping.rb
|
5
|
-
# changes see raw_socket.rb
|
6
|
-
# :%s/if_name/eth_device/g
|
7
|
-
# .get_interface_mac() --> .mac()
|
8
|
-
# Ethernet.socket --> Ethernet::RawSocket.socket
|
9
|
-
# Ethernet.mac --> Ethernet::RawSocket.mac
|
10
|
-
|
11
|
-
# :nodoc: namespace # module Scratchpad
|
12
|
-
|
13
|
-
# :nodoc: namespace
|
14
|
-
module Ethernet
|
15
|
-
|
16
|
-
# Responder for ping utility using raw Ethernet sockets.
|
17
|
-
class PingServer
|
18
|
-
module Connection
|
19
|
-
def receive_data(packet)
|
20
|
-
source_mac = packet[0, 6].unpack('H*')
|
21
|
-
dest_mac = packet[6, 6].unpack('H*')
|
22
|
-
ether_type = packet[12, 2].unpack('H*')
|
23
|
-
|
24
|
-
puts "Src: #{source_mac} Dst: #{dest_mac} Eth: #{ether_type}\n"
|
25
|
-
puts packet[14..-1].unpack('H*')
|
26
|
-
|
27
|
-
# Exchange the source and destination ARP addresses.
|
28
|
-
packet[0, 6], packet[6, 6] = packet[6, 6], packet[0, 6]
|
29
|
-
send_data packet
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
class ConnectionWrapper
|
34
|
-
include Connection
|
35
|
-
|
36
|
-
def initialize(socket)
|
37
|
-
@socket = socket
|
38
|
-
end
|
39
|
-
|
40
|
-
def send_data(data)
|
41
|
-
@socket.send data, 0
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def run
|
46
|
-
connection = ConnectionWrapper.new @socket
|
47
|
-
loop do
|
48
|
-
packet = @socket.recv 65536
|
49
|
-
connection.receive_data packet
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def initialize(eth_device, ether_type)
|
54
|
-
@socket = Ethernet::RawSocket.socket eth_device, ether_type
|
55
|
-
end
|
56
|
-
end # module Ethernet::PingServer
|
57
|
-
|
58
|
-
# Ping utility
|
59
|
-
class PingClient
|
60
|
-
def initialize(eth_device, ether_type, destination_mac)
|
61
|
-
@socket = Ethernet::RawSocket.socket eth_device, ether_type
|
62
|
-
@source_mac = [Ethernet::RawSocket.mac(eth_device).unpack('H*').first].pack('H*')[0, 6]
|
63
|
-
@dest_mac = [destination_mac].pack('H*')[0, 6]
|
64
|
-
@ether_type = [ether_type].pack('n')
|
65
|
-
end
|
66
|
-
|
67
|
-
attr_reader :socket
|
68
|
-
attr_reader :source_mac
|
69
|
-
attr_reader :dest_mac
|
70
|
-
|
71
|
-
# Pings over raw Ethernet sockets.
|
72
|
-
#
|
73
|
-
# Returns true if the ping receives a response, false otherwise.
|
74
|
-
def ping(data, timeout = 1)
|
75
|
-
data = data.clone
|
76
|
-
# Pad data to have at least 64 bytes.
|
77
|
-
data += "\0" * (64 - data.length) if data.length < 64
|
78
|
-
|
79
|
-
ping_packet = @dest_mac + @source_mac + @ether_type + data
|
80
|
-
@socket.send ping_packet, 0
|
81
|
-
|
82
|
-
response_packet = @source_mac + @dest_mac + @ether_type + data
|
83
|
-
response = @socket.recv response_packet.length * 2
|
84
|
-
|
85
|
-
response == response_packet
|
86
|
-
end
|
87
|
-
end # module Ethernet::PingClient
|
88
|
-
|
89
|
-
end # namespace Ethernet
|