net-ping 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,13 @@
1
+ == 1.2.3 - 13-Jan-2008
2
+ * Fixed a bug in the checksum private method where it would die on odd data
3
+ sizes. Thanks go to Jake Douglas for the spot.
4
+ * A Socket.get_sockaddr_in call in the Ping::ICMP class is no longer included
5
+ as part of the overall ping time. Thanks go again to Jake Douglas for
6
+ the spot.
7
+ * Added data_size tests to the Ping::ICMP test suite.
8
+ * Renamed and updated the test files. The test-unit 2.x gem is now a
9
+ prerequisite as a result.
10
+
1
11
  == 1.2.2 - 22-Jan-2008
2
12
  * Bug fix for Ping::External where it was not honoring the timeout value.
3
13
  Thanks go to Chris Morris for the spot and the patch.
data/MANIFEST CHANGED
@@ -13,9 +13,9 @@
13
13
  * lib/net/ping/udp.rb
14
14
  * lib/net/ping/http.rb
15
15
  * lib/net/ping/external.rb
16
- * test/tc_pingexternal.rb
17
- * test/tc_pinghttp.rb
18
- * test/tc_pingicmp.rb
19
- * test/tc_pingtcp.rb
20
- * test/tc_pingudp.rb
21
- * test/ts_ping.rb
16
+ * test/test_net_ping_external.rb
17
+ * test/test_net_ping_http.rb
18
+ * test/test_net_ping_icmp.rb
19
+ * test/test_net_ping_tcp.rb
20
+ * test/test_net_ping_udp.rb
21
+ * test/test_net_ping.rb
data/README CHANGED
@@ -29,3 +29,8 @@
29
29
  The former has the advantage of being easier to remember and all inclusive,
30
30
  not to mention backwards compatible. The latter has the advantage of
31
31
  reducing your memory footprint.
32
+
33
+ == More documentation
34
+ If you installed this library via Rubygems, you can view the inline
35
+ documentation via ri or fire up 'gem server', and point your browser at
36
+ http://localhost:8808.
data/Rakefile CHANGED
@@ -26,30 +26,36 @@ end
26
26
 
27
27
  Rake::TestTask.new("test") do |t|
28
28
  t.warning = true
29
- t.test_files = FileList['test/ts_ping.rb']
29
+ t.verbose = true
30
+ t.test_files = FileList['test/test_net_ping.rb']
30
31
  end
31
32
 
32
33
  Rake::TestTask.new("test_external") do |t|
33
34
  t.warning = true
34
- t.test_files = FileList['test/tc_pingexternal.rb']
35
+ t.verbose = true
36
+ t.test_files = FileList['test/test_net_ping_external.rb']
35
37
  end
36
38
 
37
39
  Rake::TestTask.new("test_http") do |t|
38
40
  t.warning = true
39
- t.test_files = FileList['test/tc_pinghttp.rb']
41
+ t.verbose = true
42
+ t.test_files = FileList['test/test_net_ping_http.rb']
40
43
  end
41
44
 
42
45
  Rake::TestTask.new("test_icmp") do |t|
43
46
  t.warning = true
44
- t.test_files = FileList['test/tc_pingicmp.rb']
47
+ t.verbose = true
48
+ t.test_files = FileList['test/test_net_ping_icmp.rb']
45
49
  end
46
50
 
47
51
  Rake::TestTask.new("test_tcp") do |t|
48
52
  t.warning = true
49
- t.test_files = FileList['test/tc_pingtcp.rb']
53
+ t.verbose = true
54
+ t.test_files = FileList['test/test_net_ping_tcp.rb']
50
55
  end
51
56
 
52
57
  Rake::TestTask.new("test_udp") do |t|
53
58
  t.warning = true
54
- t.test_files = FileList['test/tc_pingudp.rb']
55
- end
59
+ t.verbose = true
60
+ t.test_files = FileList['test/test_net_ping_udp.rb']
61
+ end
data/lib/net/ping/http.rb CHANGED
@@ -2,10 +2,11 @@ $LOAD_PATH.unshift File.dirname(__FILE__)
2
2
  require 'ping'
3
3
  require 'net/http'
4
4
  require 'uri'
5
+ require 'rbconfig'
5
6
 
6
7
  # Force non-blocking Socket.getaddrinfo on Unix systems. Do not use on
7
8
  # Windows because it causes problems.
8
- unless RUBY_PLATFORM.match('mswin')
9
+ unless Config::CONFIG['host_os'].match('mswin')
9
10
  require 'resolv-replace'
10
11
  end
11
12
 
data/lib/net/ping/icmp.rb CHANGED
@@ -82,13 +82,13 @@ module Net
82
82
  checksum = checksum(msg)
83
83
  msg = [ICMP_ECHO, ICMP_SUBCODE, checksum, @pid, @seq, @data].pack(pstring)
84
84
 
85
- start_time = Time.now
86
-
87
85
  begin
88
86
  saddr = Socket.pack_sockaddr_in(0, host)
89
87
  rescue Exception
90
88
  return bool
91
89
  end
90
+
91
+ start_time = Time.now
92
92
 
93
93
  socket.send(msg, 0, saddr) # Send the message
94
94
 
@@ -152,7 +152,7 @@ module Net
152
152
  end
153
153
 
154
154
  if length % 2 > 0
155
- check += msg[length-1, 1].unpack('C') << 8
155
+ check += msg[length-1, 1].unpack('C').first << 8
156
156
  end
157
157
 
158
158
  check = (check >> 16) + (check & 0xffff)
data/lib/net/ping/ping.rb CHANGED
@@ -3,7 +3,7 @@ require 'timeout'
3
3
 
4
4
  module Net
5
5
  class Ping
6
- VERSION = '1.2.2'
6
+ VERSION = '1.2.3'
7
7
 
8
8
  # The host to ping. In the case of Ping::HTTP, this is the URI.
9
9
  attr_accessor :host
@@ -1,18 +1,18 @@
1
1
  ######################################################################
2
- # ts_ping.rb
2
+ # test_net_ping.rb
3
3
  #
4
4
  # Test suite for all the Ping subclasses. Note that the PingICMP
5
5
  # class test won't be run unless this is run as a privileged process.
6
6
  ######################################################################
7
7
  $LOAD_PATH.unshift(Dir.pwd)
8
- $LOAD_PATH.unshift(Dir.pwd + "/lib")
9
- $LOAD_PATH.unshift(Dir.pwd + "/test")
8
+ $LOAD_PATH.unshift(File.join(Dir.pwd, 'lib'))
9
+ $LOAD_PATH.unshift(File.join(Dir.pwd, 'test'))
10
10
 
11
- require "tc_pingexternal"
12
- require "tc_pinghttp"
13
- require "tc_pingtcp"
14
- require "tc_pingudp"
11
+ require "test_net_ping_external"
12
+ require "test_net_ping_http"
13
+ require "test_net_ping_tcp"
14
+ require "test_net_ping_udp"
15
15
 
16
16
  if Process.euid == 0
17
- require "tc_pingicmp"
17
+ require "test_net_ping_icmp"
18
18
  end
@@ -1,9 +1,12 @@
1
1
  #########################################################################
2
- # tc_pingexternal.rb
2
+ # test_net_ping_external.rb
3
3
  #
4
4
  # Test case for the Net::PingExternal class. Run this via the 'test' or
5
5
  # 'test_external' rake task.
6
6
  #########################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
7
10
  require 'test/unit'
8
11
  require 'net/ping/external'
9
12
  include Net
@@ -17,7 +20,7 @@ class TC_PingExternal < Test::Unit::TestCase
17
20
  end
18
21
 
19
22
  def test_version
20
- assert_equal('1.2.2', PingExternal::VERSION)
23
+ assert_equal('1.2.3', PingExternal::VERSION)
21
24
  end
22
25
 
23
26
  def test_ping
@@ -1,9 +1,12 @@
1
1
  #################################################################################
2
- # tc_pinghttp.rb
2
+ # test_net_ping_http.rb
3
3
  #
4
4
  # Test case for the Net::PingHTTP class. This should be run via the 'test' or
5
5
  # 'test_http' test task.
6
6
  #################################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
7
10
  require 'test/unit'
8
11
  require 'net/ping/http'
9
12
  include Net
@@ -16,7 +19,7 @@ class TC_PingHTTP < Test::Unit::TestCase
16
19
  end
17
20
 
18
21
  def test_version
19
- assert_equal('1.2.2', Ping::HTTP::VERSION)
22
+ assert_equal('1.2.3', Ping::HTTP::VERSION)
20
23
  end
21
24
 
22
25
  def test_ping
@@ -1,10 +1,13 @@
1
1
  #######################################################################
2
- # tc_pingicmp.rb
2
+ # test_net_ping_icmp.rb
3
3
  #
4
4
  # Test case for the Net::PingICMP class. You must run this test case
5
5
  # with root privileges on UNIX systems. This should be run via the
6
6
  # 'test' or 'test_icmp' Rake task.
7
7
  #######################################################################
8
+ require 'rubygems'
9
+ gem 'test-unit'
10
+
8
11
  require 'test/unit'
9
12
  require 'net/ping/icmp'
10
13
  include Net
@@ -20,7 +23,7 @@ class TC_PingICMP < Test::Unit::TestCase
20
23
  end
21
24
 
22
25
  def test_version
23
- assert_equal('1.2.2', PingICMP::VERSION)
26
+ assert_equal('1.2.3', PingICMP::VERSION)
24
27
  end
25
28
 
26
29
  def test_ping
@@ -29,13 +32,21 @@ class TC_PingICMP < Test::Unit::TestCase
29
32
  assert_nothing_raised{ @icmp.ping(@host) }
30
33
  end
31
34
 
32
- def test_ping_aliases
35
+ def test_ping_aliases_basic
33
36
  assert_respond_to(@icmp, :ping?)
34
37
  assert_respond_to(@icmp, :pingecho)
35
38
  assert_nothing_raised{ @icmp.ping? }
36
39
  assert_nothing_raised{ @icmp.ping?(@host) }
37
- assert_nothing_raised{ @icmp.pingecho }
38
- assert_nothing_raised{ @icmp.pingecho(@host) }
40
+ end
41
+
42
+ def test_ping_returns_boolean
43
+ assert_boolean(@icmp.pingecho)
44
+ assert_boolean(@icmp.pingecho(@host))
45
+ end
46
+
47
+ def test_ping_expected_failure
48
+ assert_false(Ping::ICMP.new('bogus').ping?)
49
+ assert_false(Ping::ICMP.new('http://www.asdfhjklasdfhlkj.com').ping?)
39
50
  end
40
51
 
41
52
  def test_bind
@@ -77,6 +88,21 @@ class TC_PingICMP < Test::Unit::TestCase
77
88
  assert_respond_to(@icmp, :warning)
78
89
  end
79
90
 
91
+ def test_data_size_get
92
+ assert_respond_to(@icmp, :data_size)
93
+ assert_equal(56, @icmp.data_size)
94
+ end
95
+
96
+ def test_data_size_set
97
+ assert_respond_to(@icmp, :data_size=)
98
+ assert_nothing_raised{ @icmp.data_size = 22 }
99
+ end
100
+
101
+ def test_odd_data_size_ok
102
+ assert_nothing_raised{ @icmp.data_size = 57 }
103
+ assert_boolean(@icmp.ping)
104
+ end
105
+
80
106
  def teardown
81
107
  @host = nil
82
108
  @icmp = nil
@@ -1,9 +1,12 @@
1
1
  #####################################################################
2
- # tc_pingtcp.rb
2
+ # test_net_ping_tcp.rb
3
3
  #
4
4
  # Test case for the Net::PingTCP class. This test should be run via
5
5
  # the 'test' or 'test_tcp' Rake task.
6
6
  #####################################################################
7
+ require 'rubygems'
8
+ gem 'test-unit'
9
+
7
10
  require 'test/unit'
8
11
  require 'net/ping/tcp'
9
12
  include Net
@@ -15,7 +18,7 @@ class TC_PingTCP < Test::Unit::TestCase
15
18
  end
16
19
 
17
20
  def test_version
18
- assert_equal('1.2.2', PingTCP::VERSION)
21
+ assert_equal('1.2.3', PingTCP::VERSION)
19
22
  end
20
23
 
21
24
  def test_ping
@@ -1,5 +1,5 @@
1
1
  ################################################################
2
- # tc_pingudp.rb
2
+ # test_net_ping_udp.rb
3
3
  #
4
4
  # Test case for the Net::Ping::UDP class. This should be run
5
5
  # via the 'test' or 'test_udp' Rake task.
@@ -7,6 +7,9 @@
7
7
  # If someone could provide me a host where a udp ping actually
8
8
  # works (with a service check), I would appreciate it. :)
9
9
  ################################################################
10
+ require 'rubygems'
11
+ gem 'test-unit'
12
+
10
13
  require 'test/unit'
11
14
  require 'net/ping/udp'
12
15
  include Net
@@ -19,7 +22,7 @@ class TC_PingUDP < Test::Unit::TestCase
19
22
  end
20
23
 
21
24
  def test_version
22
- assert_equal('1.2.2', Ping::UDP::VERSION)
25
+ assert_equal('1.2.3', Ping::UDP::VERSION)
23
26
  end
24
27
 
25
28
  def test_ping
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-ping
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
@@ -9,10 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-01-22 00:00:00 -07:00
12
+ date: 2009-01-13 00:00:00 -07:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: test-unit
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.0.2
24
+ version:
16
25
  description: A ping interface for Ruby. Includes TCP, HTTP, ICMP, UDP, and External ping interfaces.
17
26
  email: djberg96@gmail.com
18
27
  executables: []
@@ -24,22 +33,18 @@ extra_rdoc_files:
24
33
  - CHANGES
25
34
  - doc/ping.txt
26
35
  files:
27
- - lib/net/CVS
28
36
  - lib/net/ping
29
37
  - lib/net/ping.rb
30
38
  - CHANGES
31
- - CVS
32
39
  - MANIFEST
33
40
  - Rakefile
34
41
  - README
35
- - test/CVS
36
- - test/tc_pingexternal.rb
37
- - test/tc_pinghttp.rb
38
- - test/tc_pingicmp.rb
39
- - test/tc_pingtcp.rb
40
- - test/tc_pingudp.rb
41
- - test/ts_ping.rb
42
- - lib/net/ping/CVS
42
+ - test/test_net_ping.rb
43
+ - test/test_net_ping_external.rb
44
+ - test/test_net_ping_http.rb
45
+ - test/test_net_ping_icmp.rb
46
+ - test/test_net_ping_tcp.rb
47
+ - test/test_net_ping_udp.rb
43
48
  - lib/net/ping/external.rb
44
49
  - lib/net/ping/http.rb
45
50
  - lib/net/ping/icmp.rb
@@ -69,9 +74,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
74
  requirements: []
70
75
 
71
76
  rubyforge_project: shards
72
- rubygems_version: 1.0.0
77
+ rubygems_version: 1.2.0
73
78
  signing_key:
74
79
  specification_version: 2
75
80
  summary: A ping interface for Ruby.
76
81
  test_files:
77
- - test/ts_ping.rb
82
+ - test/test_net_ping.rb