net-proto 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES ADDED
@@ -0,0 +1,74 @@
1
+ == 1.0.1 - 30-Jun-2006
2
+ * Added rdoc to the source files.
3
+ * Added a gemspec.
4
+
5
+ == 1.0.0 - 14-Jul-2005
6
+ * Moved project to RubyForge.
7
+ * Minor directory layout change.
8
+ * Minor changes to the extconf.rb file.
9
+ * Officially bumped VERSION to 1.0.0.
10
+
11
+ == 0.2.5 - 18-Apr-2005
12
+ * The Unix versions now call setprotoent(0) and endprotoent() internally
13
+ before each call.
14
+
15
+ == 0.2.4 - 12-Apr-2005
16
+ * Added internal taint checking for the Proto.getprotobyname method.
17
+ * Removed the INSTALL file. Installation instructions are now in the README.
18
+ * Moved the sample script into the 'examples' directory.
19
+ * General code cleanup.
20
+ * Minor test suite changes and additions.
21
+ * Removed the netproto.rd and netproto.html files. The netproto.txt file is
22
+ now rdoc friendly.
23
+
24
+ == 0.2.3 - 13-Sep-2004
25
+ * Replaced all instances of the deprecated STR2CSTR() function with the
26
+ StringValuePtr() function. That means that, as of this release, this
27
+ package requires Ruby 1.8.0 or later.
28
+ * Minor documentation corrections.
29
+
30
+ == 0.2.2 - 10-Apr-2004
31
+ * No longer returns an Array in block form. Only the non-block form returns
32
+ an array. The block form returns nil.
33
+ * Updated the documentation, warranty information included, license changed
34
+ back to "Ruby's".
35
+ * Modified extconf.rb. It is now assumed that you have TestUnit installed.
36
+ * Changed "tc_all.rb" to "tc_netproto.rb".
37
+ * Changed "netproto.rd2" to "netproto.rd".
38
+
39
+ == 0.2.1 - 29-Jul-2003
40
+ * Code cleanup (-Wall warnings on Linux)
41
+ * Removed VERSION() class method. Use the constant instead
42
+ * The getprotoent() method now returns an array of structs in non-block form
43
+ * Added README file
44
+ * Added generic test script under test/
45
+ * Modified extconf.rb to use generic test script for those who don't have
46
+ TestUnit installed, instead of dynamically generating one
47
+ * Fixed up TestUnit test suite
48
+
49
+ == 0.2.0 - 26-Feb-2003
50
+ * Added MS Windows support (except 'getprotoent()' - see docs)
51
+ * For protocols that aren't defined, nil is now returned instead
52
+ of crashing (always a good thing)
53
+ * Removed sys-uname requirement
54
+ * Added a test suite (for those with testunit installed)
55
+ * Some internal layout changes (doc, lib, test dirs)
56
+ * Added a VERSION constant and class method
57
+ * RD2 documentation now separated from source
58
+ * Installation instructions modified
59
+ * Lots of changes to extconf.rb
60
+ * Changelog now CHANGES
61
+ * Manifest now MANIFEST
62
+ * Package name changed to lower case
63
+
64
+ == 0.1.0 - 13-Aug-2002
65
+ * Fixed bug with getprotoent_r function for Linux
66
+ * Added a 'generic' source file that uses the non-reentrant functions for
67
+ those platforms that are not specifically supported.
68
+ * Added FreeBSD support
69
+ * Modified test script slightly
70
+ * Added a changelog :)
71
+ * Added a manifest
72
+
73
+ == 0.0.1 - 12-Aug-2002
74
+ * Initial release (though written earlier)
data/MANIFEST ADDED
@@ -0,0 +1,17 @@
1
+ CHANGES
2
+ MANIFEST
3
+ README
4
+ extconf.rb
5
+ net-proto.gemspec
6
+
7
+ doc/netproto.txt
8
+
9
+ examples/test_proto.rb
10
+
11
+ lib/version.h
12
+ lib/net/generic.c
13
+ lib/net/linux.c
14
+ lib/net/sunos.c
15
+ lib/net/windows.c
16
+
17
+ test/tc_netproto.rb
data/README ADDED
@@ -0,0 +1,25 @@
1
+ == Description
2
+ The net-proto package provides the getprotobyname(), getprotobynumber() and
3
+ the getprotoent() methods for Ruby.
4
+
5
+ == Prerequisites
6
+ Ruby 1.8.0 or later.
7
+
8
+ == Installation
9
+ ruby extconf.rb
10
+ make
11
+ ruby test\tc_netproto.rb (optional)
12
+ make site-install
13
+
14
+ == Notes
15
+ The net-proto package uses reentrant code for sunos and linux. Otherwise, the
16
+ generic form of the functions are used (which may be reentrant by default
17
+ anway - check the man pages on your platform).
18
+
19
+ The Proto.getprotoent method is not supported on Win32 platforms.
20
+
21
+ == Why should I use this?
22
+ Ruby does define a predefined set of constants in socket.c in the general form
23
+ of IPPROTO_XXX, Y. However, using constants in this fashion can be unreliable
24
+ because it's easy to define your own protocols (I set 'echo' to 7, for
25
+ example), or to modify/delete entries in /etc/protocols.
data/doc/netproto.txt ADDED
@@ -0,0 +1,82 @@
1
+ == Description
2
+ Net::Proto - An interface for the 'getproto' family of functions.
3
+
4
+ == Synopsis
5
+ require "net/proto"
6
+ include Net
7
+
8
+ Proto.getprotobyname("tcp") # -> 6
9
+ Proto.getprotobynumber(1) # -> "icmp"
10
+
11
+ # Block form
12
+ Proto.getprotoent{ |p|
13
+ puts p.name
14
+ puts p.aliases
15
+ puts p.proto
16
+ }
17
+
18
+ # Non-block form
19
+ a = Proto.getprotoent
20
+
21
+ == Constants
22
+ VERSION
23
+ The current version number of this package, returned as a String.
24
+
25
+ == Class Methods
26
+ Proto.getprotobyname(name)
27
+ Given a protocol string, returns the corresponding number, or nil if not
28
+ found.
29
+
30
+ Proto.getprotobynumber(num)
31
+ Given a protocol number, returns the corresponding string, or nil if not
32
+ found.
33
+
34
+ Proto.getprotoent
35
+ Proto.getprotoent{ |struct| ... }
36
+ In block form, yields each entry from /etc/protocols as a struct of type
37
+ Proto::ProtoStruct. In non-block form, returns an array of
38
+ Proto::ProtoStruct objects.
39
+
40
+ The fields are 'name' (a String), 'aliases' (an Array of String's,
41
+ though often only one element), and 'proto' (a Fixnum).
42
+
43
+ This method is NOT supported on MS Windows.
44
+
45
+ == Notes
46
+ This module uses the reentrant (i.e. thread safe) functions on those
47
+ platforms that support them. In some cases, e.g. FreeBSD and HP-UX, the
48
+ standard function names are reentrant by default (i.e. there is no '_r'
49
+ version, or it's not needed), so you will not see specific .c files for
50
+ all platforms.
51
+
52
+ The 'setprotoent()' and 'endprotoent()' functions are not implemented as
53
+ separate method calls. Rather, these are called internally by the various
54
+ methods, except on Windows, which does not support them.
55
+
56
+ The 'getprotoent()' method is not supported on the Win32 platform. It's
57
+ not part of the API as of Windows XP.
58
+
59
+ == Known Bugs
60
+ None that I'm aware of. Please log any bug reports on the project page
61
+ at http://ruby-netutils.sf.net.
62
+
63
+ == Future Plans
64
+ Use the asynchronous calls (WSAAsyncGetProtoByName and
65
+ WSAAsyncGetProtoByNumber) on Win32 systems.
66
+
67
+ == Copyright
68
+ (C) 2003-2005 Daniel J. Berger
69
+ All rights reserved.
70
+
71
+ == Warranty
72
+ This package is provided "as is" and without any express or
73
+ implied warranties, including, without limitation, the implied
74
+ warranties of merchantability and fitness for a particular purpose.
75
+
76
+ == License
77
+ Ruby's
78
+
79
+ == Author
80
+ Daniel J. Berger
81
+ djberg96 at yahoo dot com
82
+ rubyhacker1/imperator on IRC (Freenode)
data/extconf.rb ADDED
@@ -0,0 +1,30 @@
1
+ ################################
2
+ # extconf.rb file for net-proto
3
+ ################################
4
+ require "mkmf"
5
+ require "ftools"
6
+
7
+ ##################################################
8
+ # Use the appropriate .c file, based on platform
9
+ ##################################################
10
+ c_file = nil
11
+
12
+ case RUBY_PLATFORM
13
+ when /win32|windows|mingw|cygwin/i
14
+ c_file = "lib/net/windows.c"
15
+ when /sunos|solaris/i
16
+ c_file = "lib/net/sunos.c"
17
+ have_library("socket")
18
+ when /linux/i
19
+ c_file = "lib/net/linux.c"
20
+ else
21
+ c_file = "lib/net/generic.c"
22
+ end
23
+
24
+ File.delete("proto.c") if File.exists?("proto.c")
25
+ File.delete("version.h") if File.exists?("version.h")
26
+
27
+ File.copy(c_file, "proto.c")
28
+ File.copy("lib/version.h",".")
29
+
30
+ create_makefile("net/proto")
data/lib/net/sunos.c ADDED
@@ -0,0 +1,136 @@
1
+ /*******************************************************
2
+ * proto.c (sunos.c)
3
+ *******************************************************/
4
+ #include "ruby.h"
5
+ #include "version.h"
6
+ #include <netdb.h>
7
+ #include <string.h>
8
+
9
+ #ifdef __cplusplus
10
+ extern "C"
11
+ {
12
+ #endif
13
+
14
+ #define BUF_SIZE 8192
15
+
16
+ VALUE sProto;
17
+
18
+ /*
19
+ * call-seq:
20
+ * Proto.getprotobyname(name)
21
+ *
22
+ * Given a protocol string, returns the corresponding number, or nil if not
23
+ * found.
24
+ */
25
+ static VALUE np_getprotobyname(VALUE klass, VALUE rbProtoName){
26
+ struct protoent p;
27
+ char buffer[BUF_SIZE];
28
+ VALUE rbProtoNum = Qnil;
29
+
30
+ SafeStringValue(rbProtoName);
31
+
32
+ setprotoent(0);
33
+
34
+ if(getprotobyname_r(StringValuePtr(rbProtoName),&p,buffer,BUF_SIZE) != NULL)
35
+ rbProtoNum = INT2FIX(p.p_proto);
36
+
37
+ endprotoent();
38
+
39
+ return rbProtoNum;
40
+ }
41
+
42
+ /*
43
+ * call-seq:
44
+ * Proto.getprotobynumber(num)
45
+ *
46
+ * Given a protocol number, returns the corresponding string, or nil if not
47
+ * found.
48
+ */
49
+ static VALUE np_getprotobynumber(VALUE klass, VALUE rbProtoNum){
50
+ struct protoent p;
51
+ char buffer[BUF_SIZE];
52
+ VALUE rbProtoName = Qnil;
53
+
54
+ setprotoent(0);
55
+
56
+ if(getprotobynumber_r(NUM2INT(rbProtoNum),&p,buffer,BUF_SIZE) != NULL)
57
+ rbProtoName = rb_str_new2(p.p_name);
58
+
59
+ endprotoent();
60
+
61
+ return rbProtoName;
62
+ }
63
+
64
+ /*
65
+ * call-seq:
66
+ * Proto.getprotoent
67
+ * Proto.getprotoent{ |struct| ... }
68
+ *
69
+ * In block form, yields each entry from /etc/protocols as a struct of type
70
+ * Proto::ProtoStruct. In non-block form, returns an array of
71
+ * Proto::ProtoStruct objects.
72
+
73
+ * The fields are 'name' (a String), 'aliases' (an Array of String's,
74
+ * though often only one element), and 'proto' (a Fixnum).
75
+ */
76
+ static VALUE np_getprotoent(){
77
+ struct protoent p;
78
+ char buffer[BUF_SIZE];
79
+ VALUE rbAliasArray = Qnil;
80
+ VALUE rbArray = Qnil;
81
+ VALUE rbStruct = Qnil;
82
+
83
+ if(!rb_block_given_p())
84
+ rbArray = rb_ary_new();
85
+
86
+ setprotoent(0);
87
+
88
+ while(getprotoent_r(&p, buffer, BUF_SIZE)){
89
+ rbAliasArray = rb_ary_new();
90
+
91
+ while(*p.p_aliases){
92
+ rb_ary_push(rbAliasArray ,rb_str_new2(*p.p_aliases));
93
+ (void)p.p_aliases++;
94
+ }
95
+
96
+ rbStruct = rb_struct_new(sProto,
97
+ rb_str_new2(p.p_name),
98
+ rbAliasArray,
99
+ INT2FIX(p.p_proto)
100
+ );
101
+
102
+ if(rb_block_given_p()){
103
+ rb_yield(rbStruct);
104
+ }
105
+ else{
106
+ rb_ary_push(rbArray, rbStruct);
107
+ }
108
+ }
109
+
110
+ endprotoent();
111
+
112
+ return rbArray; /* nil unless a block is given */
113
+ }
114
+
115
+ void Init_proto()
116
+ {
117
+ /* Module and class definitions */
118
+ VALUE mNet, cProto;
119
+ mNet = rb_define_module("Net");
120
+ cProto = rb_define_class_under(mNet,"Proto",rb_cObject);
121
+
122
+ /* Structure definitions */
123
+ sProto = rb_struct_define("ProtoStruct","name","aliases","proto",0);
124
+
125
+ /* Class methods */
126
+ rb_define_singleton_method(cProto,"getprotobyname",np_getprotobyname,1);
127
+ rb_define_singleton_method(cProto,"getprotobynumber",np_getprotobynumber,1);
128
+ rb_define_singleton_method(cProto,"getprotoent",np_getprotoent,0);
129
+
130
+ /* Constants */
131
+ rb_define_const(cProto,"VERSION",rb_str_new2(NET_PROTO_VERSION));
132
+ }
133
+
134
+ #ifdef __cplusplus
135
+ }
136
+ #endif
data/lib/version.h ADDED
@@ -0,0 +1,2 @@
1
+ /* version.h - there can be only one */
2
+ #define NET_PROTO_VERSION "1.0.1"
@@ -0,0 +1,94 @@
1
+ ############################################
2
+ # tc_netproto.rb
3
+ #
4
+ # Test suite for net-proto - all platforms.
5
+ ############################################
6
+ base = File.basename(Dir.pwd)
7
+
8
+ if base == "test" || base =~ /net-proto.*/
9
+ require "ftools"
10
+ Dir.chdir("..") if base == "test"
11
+ Dir.mkdir("net") unless File.exists?("net")
12
+
13
+ extension = ".so"
14
+ extension = ".sl" if RUBY_PLATFORM =~ /hpux/i
15
+ extension = ".bundle" if RUBY_PLATFORM =~ /darwin|powerpc/i
16
+
17
+ proto_file = "proto" + extension
18
+
19
+ if File.exist?(proto_file)
20
+ File.copy(proto_file,"net")
21
+ else
22
+ puts "No proto#{extenstion} file found."
23
+ puts "Please run extconf.rb and make first."
24
+ exit!
25
+ end
26
+ $LOAD_PATH.unshift(Dir.pwd)
27
+ Dir.chdir("test") rescue nil
28
+ end
29
+
30
+ require "net/proto"
31
+ require "test/unit"
32
+ include Net
33
+
34
+ class TC_Net_Proto < Test::Unit::TestCase
35
+ # These were the protocols listed in my
36
+ # own /etc/protocols file on Solaris 9.
37
+ def setup
38
+ @protocols = %w/
39
+ ip icmp igmp ggp ipip tcp cbt egp igp pup udp mux hmp
40
+ xns-idp rdp idpr idpr-cmtp sdrp idrp rsvp gre
41
+ mobile ospf pim ipcomp vrrp sctp hopopt ipv6
42
+ ipv6-route ipv6-frag esp ah ipv6-icmp ipv6-nonxt ipv6-opts
43
+ /
44
+ end
45
+
46
+ def test_version
47
+ assert_equal("1.0.1", Proto::VERSION)
48
+ end
49
+
50
+ def test_getprotobynumber
51
+ assert_respond_to(Proto, :getprotobynumber)
52
+ assert_raises(TypeError){ Proto.getprotobynumber("foo") }
53
+ assert_raises(TypeError){ Proto.getprotobynumber(nil) }
54
+ assert_equal(nil, Proto.getprotobynumber(9999999))
55
+ assert_equal("tcp", Proto.getprotobynumber(6))
56
+ assert_nothing_raised{
57
+ 0.upto(132){ |n| Proto.getprotobynumber(n) }
58
+ }
59
+ end
60
+
61
+ def test_getprotobyname
62
+ assert_respond_to(Proto, :getprotobyname)
63
+ assert_raises(TypeError){ Proto.getprotobyname(1) }
64
+ assert_raises(TypeError){ Proto.getprotobyname(nil) }
65
+ assert_equal(nil, Proto.getprotobyname("foo"))
66
+ assert_equal(6, Proto.getprotobyname("tcp"))
67
+ @protocols.each{ |prot|
68
+ assert_nothing_raised{ Proto.getprotobyname(prot) }
69
+ }
70
+ end
71
+
72
+ def test_getprotoent
73
+ if File::ALT_SEPARATOR
74
+ msg = "The getprotoent() function is not supported on this "
75
+ msg += "platform - test skipped"
76
+ STDERR.puts msg
77
+ else
78
+ assert_respond_to(Proto, :getprotoent)
79
+ p = Proto.getprotoent.first
80
+ assert_kind_of(Struct::ProtoStruct, p)
81
+ assert_equal(%w/name aliases proto/,p.members)
82
+ assert_kind_of(String, p.name, "Bad type for name")
83
+ assert_kind_of(Array, p.aliases, "Bad type for aliases")
84
+ assert_kind_of(Integer, p.proto, "Bad type for proto")
85
+ p.aliases.each{ |a|
86
+ assert_kind_of(String, a, "Bad type for aliases member")
87
+ }
88
+ end
89
+ end
90
+
91
+ def teardown
92
+ @protocols = nil
93
+ end
94
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: net-proto
5
+ version: !ruby/object:Gem::Version
6
+ version: 1.0.1
7
+ date: 2006-06-30 00:00:00 -06:00
8
+ summary: The net-proto package provides the getprotobyname(), getprotobynumber() and the getprotoent() methods for Ruby.
9
+ require_paths:
10
+ - lib
11
+ email: djberg96@gmail.com
12
+ homepage: http://www.rubyforge.org/projects/sysutils
13
+ rubyforge_project: sysutils
14
+ description: The net-proto package provides the getprotobyname(), getprotobynumber() and the getprotoent() methods for Ruby.
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 1.8.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Daniel J. Berger
31
+ files:
32
+ - doc/netproto.txt
33
+ - test/tc_netproto.rb
34
+ - CHANGES
35
+ - MANIFEST
36
+ - README
37
+ - extconf.rb
38
+ - lib/version.h
39
+ - lib/net/sunos.c
40
+ test_files:
41
+ - test/tc_netproto.rb
42
+ rdoc_options: []
43
+
44
+ extra_rdoc_files:
45
+ - CHANGES
46
+ - README
47
+ executables: []
48
+
49
+ extensions:
50
+ - extconf.rb
51
+ requirements: []
52
+
53
+ dependencies: []
54
+