net-proto 1.0.1 → 1.0.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.0.3 - 13-Aug-2007
2
+ * Fix for OS X (whining about malloced pointer).
3
+ * Added a Rakefile along with tasks for installation and testing.
4
+ * Major internal reorganization.
5
+ * Fixed Proto::VERSION test.
6
+
7
+ == 1.0.2 - 18-Nov-2006
8
+ * Updated the README, gemspec and netproto.txt files.
9
+ * No code changes.
10
+
1
11
  == 1.0.1 - 30-Jun-2006
2
12
  * Added rdoc to the source files.
3
13
  * Added a gemspec.
data/MANIFEST CHANGED
@@ -1,17 +1,13 @@
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
1
+ * CHANGES
2
+ * MANIFEST
3
+ * README
4
+ * Rakefile
5
+ * net-proto.gemspec
6
+ * doc/netproto.txt
7
+ * examples/test_proto.rb
8
+ * ext/version.h
9
+ * ext/generic/generic.c
10
+ * ext/linux/linux.c
11
+ * ext/sunos/sunos.c
12
+ * ext/windows/windows.c
13
+ * test/tc_netproto.rb
data/README CHANGED
@@ -1,25 +1,30 @@
1
1
  == Description
2
- The net-proto package provides the getprotobyname(), getprotobynumber() and
3
- the getprotoent() methods for Ruby.
2
+ The net-proto package provides a way to get protocol information.
3
+
4
+ This is really just a wrapper for the getprotobyname(), getprotobynumber() and
5
+ the getprotoent() functions.
4
6
 
5
7
  == Prerequisites
6
8
  Ruby 1.8.0 or later.
7
9
 
8
10
  == Installation
9
- ruby extconf.rb
10
- make
11
- ruby test\tc_netproto.rb (optional)
12
- make site-install
11
+ rake test (optional)
12
+ rake install (non-gem) OR rake install_gem (gem)
13
13
 
14
14
  == Notes
15
- The net-proto package uses reentrant code for sunos and linux. Otherwise, the
15
+ The net-proto package uses reentrant code for sunos and linux. Otherwise, the
16
16
  generic form of the functions are used (which may be reentrant by default
17
17
  anway - check the man pages on your platform).
18
18
 
19
- The Proto.getprotoent method is not supported on Win32 platforms.
19
+ The Proto.getprotoent method is not supported on MS Windows because the
20
+ underlying function isn't supported by the MS Windows API.
20
21
 
21
22
  == 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
23
+ Ruby has a predefined set of constants in socket.c in the general form of
24
+ IPPROTO_XXX, Y. However, using constants in this fashion can be unreliable
24
25
  because it's easy to define your own protocols (I set 'echo' to 7, for
25
26
  example), or to modify/delete entries in /etc/protocols.
27
+
28
+ == Further Documentation
29
+ See the 'netproto.txt' file under the 'doc' directory for more details. There
30
+ is also an example under the 'examples' directory.
data/doc/netproto.txt CHANGED
@@ -20,7 +20,7 @@
20
20
 
21
21
  == Constants
22
22
  VERSION
23
- The current version number of this package, returned as a String.
23
+ The current version number of this package, returned as a String.
24
24
 
25
25
  == Class Methods
26
26
  Proto.getprotobyname(name)
@@ -37,8 +37,8 @@ Proto.getprotoent{ |struct| ... }
37
37
  Proto::ProtoStruct. In non-block form, returns an array of
38
38
  Proto::ProtoStruct objects.
39
39
 
40
- The fields are 'name' (a String), 'aliases' (an Array of String's,
41
- though often only one element), and 'proto' (a Fixnum).
40
+ The fields are 'name' (a String), 'aliases' (an Array of String's,
41
+ though often only one element), and 'proto' (a Fixnum).
42
42
 
43
43
  This method is NOT supported on MS Windows.
44
44
 
@@ -53,8 +53,8 @@ Proto.getprotoent{ |struct| ... }
53
53
  separate method calls. Rather, these are called internally by the various
54
54
  methods, except on Windows, which does not support them.
55
55
 
56
- The 'getprotoent()' method is not supported on the Win32 platform. It's
57
- not part of the API as of Windows XP.
56
+ The 'getprotoent()' method is not supported on the MS Windows platform.
57
+ It's not part of the API as of Windows XP.
58
58
 
59
59
  == Known Bugs
60
60
  None that I'm aware of. Please log any bug reports on the project page
@@ -62,21 +62,21 @@ Proto.getprotoent{ |struct| ... }
62
62
 
63
63
  == Future Plans
64
64
  Use the asynchronous calls (WSAAsyncGetProtoByName and
65
- WSAAsyncGetProtoByNumber) on Win32 systems.
65
+ WSAAsyncGetProtoByNumber) on MS Windows systems.
66
66
 
67
67
  == Copyright
68
- (C) 2003-2005 Daniel J. Berger
69
- All rights reserved.
68
+ (C) 2003-2007 Daniel J. Berger
69
+ All rights reserved.
70
70
 
71
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.
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
75
 
76
76
  == License
77
- Ruby's
77
+ Ruby's
78
78
 
79
79
  == Author
80
- Daniel J. Berger
81
- djberg96 at yahoo dot com
82
- rubyhacker1/imperator on IRC (Freenode)
80
+ Daniel J. Berger
81
+ djberg96 at gmail dot com
82
+ imperator on IRC (Freenode)
data/ext/extconf.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'mkmf'
2
+ require 'fileutils'
3
+
4
+ case RUBY_PLATFORM
5
+ when /sunos|solaris/i
6
+ have_library('socket')
7
+ FileUtils.cp('sunos/sunos.c', 'proto.c')
8
+ when /linux/i
9
+ FileUtils.cp('linux/linux.c', 'proto.c')
10
+ when /win32|windows|dos|mingw|cygwin/i
11
+ FileUtils.cp('windows/windows.c', 'proto.c')
12
+ else
13
+ FileUtils.cp('generic/generic.c', 'proto.c')
14
+ end
15
+
16
+ create_makefile('net/proto')
@@ -0,0 +1,144 @@
1
+ /*******************************************************
2
+ * proto.c (generic.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
+ VALUE sProto;
15
+
16
+ /*
17
+ * call-seq:
18
+ * Proto.getprotobyname(name)
19
+ *
20
+ * Given a protocol string, returns the corresponding number, or nil if not
21
+ * found.
22
+ */
23
+ static VALUE np_getprotobyname(VALUE klass, VALUE v_proto_name){
24
+ struct protoent* p;
25
+ VALUE v_proto_num = Qnil;
26
+
27
+ SafeStringValue(v_proto_name);
28
+
29
+ setprotoent(0);
30
+ p = getprotobyname(StringValuePtr(v_proto_name));
31
+
32
+ if(p)
33
+ v_proto_num = INT2FIX(p->p_proto);
34
+
35
+ endprotoent();
36
+
37
+ return v_proto_num;
38
+ }
39
+
40
+ /*
41
+ * call-seq:
42
+ * Proto.getprotobynumber(num)
43
+ *
44
+ * Given a protocol number, returns the corresponding string, or nil if not
45
+ * found.
46
+ */
47
+ static VALUE np_getprotobynumber(VALUE klass, VALUE v_proto_num){
48
+ struct protoent* p;
49
+ VALUE v_proto_name = Qnil;
50
+
51
+ setprotoent(0);
52
+ p = getprotobynumber(NUM2INT(v_proto_num));
53
+
54
+ if(p)
55
+ v_proto_name = rb_str_new2(p->p_name);
56
+
57
+ endprotoent();
58
+
59
+ return v_proto_name;
60
+ }
61
+
62
+ /*
63
+ * call-seq:
64
+ * Proto.getprotoent
65
+ * Proto.getprotoent{ |struct| ... }
66
+ *
67
+ * In block form, yields each entry from /etc/protocols as a struct of type
68
+ * Proto::ProtoStruct. In non-block form, returns an array of
69
+ * Proto::ProtoStruct objects.
70
+
71
+ * The fields are 'name' (a String), 'aliases' (an Array of String's,
72
+ * though often only one element), and 'proto' (a Fixnum).
73
+ */
74
+ static VALUE np_getprotoent(VALUE klass){
75
+ struct protoent* p;
76
+ VALUE v_aliases = Qnil;
77
+ VALUE v_array = Qnil;
78
+ VALUE v_struct = Qnil;
79
+
80
+ p = malloc(sizeof(struct protoent));
81
+
82
+ if(!rb_block_given_p())
83
+ v_array = rb_ary_new();
84
+
85
+ setprotoent(0);
86
+
87
+ while((p = getprotoent())){
88
+ v_aliases = rb_ary_new();
89
+
90
+ #ifdef __MACH__ or #ifdef __APPLE__
91
+ char **aliases = p->p_aliases;
92
+ while(*aliases){
93
+ rb_ary_push(v_aliases, rb_str_new2(*aliases));
94
+ aliases++;
95
+ }
96
+ #else
97
+ while(*p->p_aliases){
98
+ rb_ary_push(v_aliases, rb_str_new2(*p->p_aliases));
99
+ (void)p->p_aliases++;
100
+ }
101
+ #endif
102
+
103
+ v_struct = rb_struct_new(sProto,
104
+ rb_str_new2(p->p_name),
105
+ v_aliases,
106
+ INT2FIX(p->p_proto)
107
+ );
108
+
109
+ if(rb_block_given_p())
110
+ rb_yield(v_struct);
111
+ else
112
+ rb_ary_push(v_array, v_struct);
113
+ }
114
+
115
+ free(p);
116
+ endprotoent();
117
+
118
+ return v_array; /* nil if a block is given */
119
+ }
120
+
121
+ void Init_proto(){
122
+ VALUE mNet, cProto;
123
+
124
+ /* The Net module serves only as a namespace */
125
+ mNet = rb_define_module("Net");
126
+
127
+ /* The Proto class encapsulates network protocol information */
128
+ cProto = rb_define_class_under(mNet, "Proto", rb_cObject);
129
+
130
+ /* Structure definitions */
131
+ sProto = rb_struct_define("ProtoStruct", "name", "aliases", "proto", 0);
132
+
133
+ /* Class methods */
134
+ rb_define_singleton_method(cProto, "getprotobyname", np_getprotobyname, 1);
135
+ rb_define_singleton_method(cProto, "getprotobynumber", np_getprotobynumber, 1);
136
+ rb_define_singleton_method(cProto, "getprotoent", np_getprotoent, 0);
137
+
138
+ /* 1.0.3: The version of this package. This is a string, not a number */
139
+ rb_define_const(cProto, "VERSION", rb_str_new2(NET_PROTO_VERSION));
140
+ }
141
+
142
+ #ifdef __cplusplus
143
+ }
144
+ #endif
data/ext/linux/linux.c ADDED
@@ -0,0 +1,153 @@
1
+ /*******************************************************
2
+ * proto.c (linux.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 v_proto_name){
26
+ struct protoent* p;
27
+ char buffer[BUF_SIZE];
28
+ VALUE v_proto_num = Qnil;
29
+
30
+ SafeStringValue(v_proto_name);
31
+
32
+ p = malloc(sizeof(struct protoent));
33
+
34
+ setprotoent(0);
35
+ getprotobyname_r(StringValuePtr(v_proto_name), p, buffer, BUF_SIZE, &p);
36
+
37
+ if(p){
38
+ v_proto_num = INT2FIX(p->p_proto);
39
+ free(p);
40
+ }
41
+
42
+ endprotoent();
43
+ return v_proto_num;
44
+ }
45
+
46
+ /*
47
+ * call-seq:
48
+ * Proto.getprotobynumber(num)
49
+ *
50
+ * Given a protocol number, returns the corresponding string, or nil if not
51
+ * found.
52
+ */
53
+
54
+ static VALUE np_getprotobynumber(VALUE klass, VALUE v_proto_num){
55
+ struct protoent* p;
56
+ char buffer[BUF_SIZE];
57
+ char* proto_name;
58
+ VALUE v_proto_name = Qnil;
59
+
60
+ p = malloc(sizeof(struct protoent));
61
+
62
+ setprotoent(0);
63
+ getprotobynumber_r(NUM2INT(v_proto_num), p, buffer, BUF_SIZE, &p);
64
+
65
+ if(p){
66
+ v_proto_name = rb_str_new2(proto_name = p->p_name);
67
+ free(p);
68
+ }
69
+
70
+ endprotoent();
71
+ return v_proto_name;
72
+ }
73
+
74
+ /*
75
+ * call-seq:
76
+ * Proto.getprotoent
77
+ * Proto.getprotoent{ |struct| ... }
78
+ *
79
+ * In block form, yields each entry from /etc/protocols as a struct of type
80
+ * Proto::ProtoStruct. In non-block form, returns an array of
81
+ * Proto::ProtoStruct objects.
82
+
83
+ * The fields are 'name' (a String), 'aliases' (an Array of String's,
84
+ * though often only one element), and 'proto' (a Fixnum).
85
+ */
86
+ static VALUE np_getprotoent(VALUE klass){
87
+ struct protoent* p;
88
+ struct protoent* q;
89
+ char buffer[BUF_SIZE];
90
+ VALUE v_alias_array = Qnil;
91
+ VALUE v_array = Qnil;
92
+ VALUE v_struct = Qnil;
93
+
94
+ p = malloc(sizeof(struct protoent));
95
+ q = malloc(sizeof(struct protoent));
96
+
97
+ if(!rb_block_given_p())
98
+ v_array = rb_ary_new();
99
+
100
+ setprotoent(0);
101
+
102
+ while(!getprotoent_r(p, buffer, BUF_SIZE, &q)){
103
+ v_alias_array = rb_ary_new();
104
+
105
+ while((*p->p_aliases)){
106
+ rb_ary_push(v_alias_array, rb_str_new2(*p->p_aliases));
107
+ (void)*p->p_aliases++;
108
+ }
109
+
110
+ v_struct = rb_struct_new(sProto,
111
+ rb_str_new2(p->p_name),
112
+ v_alias_array,
113
+ INT2FIX(p->p_proto)
114
+ );
115
+
116
+ if(rb_block_given_p())
117
+ rb_yield(v_struct);
118
+ else
119
+ rb_ary_push(v_array, v_struct);
120
+ }
121
+
122
+ free(p);
123
+ free(q);
124
+
125
+ endprotoent();
126
+
127
+ return v_array; /* nil if a block was given */
128
+ }
129
+
130
+ void Init_proto(){
131
+ VALUE mNet, cProto;
132
+
133
+ /* The Net module serves as a namespace only */
134
+ mNet = rb_define_module("Net");
135
+
136
+ /* The Proto class encapsulates network protocol information */
137
+ cProto = rb_define_class_under(mNet, "Proto", rb_cObject);
138
+
139
+ /* Structure definitions */
140
+ sProto = rb_struct_define("ProtoStruct", "name", "aliases", "proto", 0);
141
+
142
+ /* Class methods */
143
+ rb_define_singleton_method(cProto, "getprotobyname", np_getprotobyname, 1);
144
+ rb_define_singleton_method(cProto, "getprotobynumber", np_getprotobynumber, 1);
145
+ rb_define_singleton_method(cProto, "getprotoent", np_getprotoent, 0);
146
+
147
+ /* 1.0.3: The version of this package. This is a string, not a number */
148
+ rb_define_const(cProto, "VERSION", rb_str_new2(NET_PROTO_VERSION));
149
+ }
150
+
151
+ #ifdef __cplusplus
152
+ }
153
+ #endif
data/ext/sunos/sunos.c ADDED
@@ -0,0 +1,137 @@
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 v_proto_name){
26
+ struct protoent p;
27
+ char buffer[BUF_SIZE];
28
+ VALUE v_proto_num = Qnil;
29
+
30
+ SafeStringValue(v_proto_name);
31
+
32
+ setprotoent(0);
33
+
34
+ if(getprotobyname_r(StringValuePtr(v_proto_name),&p,buffer,BUF_SIZE) != NULL)
35
+ v_proto_num = INT2FIX(p.p_proto);
36
+
37
+ endprotoent();
38
+
39
+ return v_proto_num;
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 v_proto_num){
50
+ struct protoent p;
51
+ char buffer[BUF_SIZE];
52
+ VALUE v_proto_name = Qnil;
53
+
54
+ setprotoent(0);
55
+
56
+ if(getprotobynumber_r(NUM2INT(v_proto_num),&p,buffer,BUF_SIZE) != NULL)
57
+ v_proto_name = rb_str_new2(p.p_name);
58
+
59
+ endprotoent();
60
+
61
+ return v_proto_name;
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 v_alias_array = Qnil;
80
+ VALUE v_array = Qnil;
81
+ VALUE v_struct = Qnil;
82
+
83
+ if(!rb_block_given_p())
84
+ v_array = rb_ary_new();
85
+
86
+ setprotoent(0);
87
+
88
+ while(getprotoent_r(&p, buffer, BUF_SIZE)){
89
+ v_alias_array = rb_ary_new();
90
+
91
+ while(*p.p_aliases){
92
+ rb_ary_push(v_alias_array ,rb_str_new2(*p.p_aliases));
93
+ (void)p.p_aliases++;
94
+ }
95
+
96
+ v_struct = rb_struct_new(sProto,
97
+ rb_str_new2(p.p_name),
98
+ v_alias_array,
99
+ INT2FIX(p.p_proto)
100
+ );
101
+
102
+ if(rb_block_given_p())
103
+ rb_yield(v_struct);
104
+ else
105
+ rb_ary_push(v_array, v_struct);
106
+ }
107
+
108
+ endprotoent();
109
+
110
+ return v_array; /* nil unless a block is given */
111
+ }
112
+
113
+ void Init_proto()
114
+ {
115
+ VALUE mNet, cProto;
116
+
117
+ /* The Net module serves only as a namespace */
118
+ mNet = rb_define_module("Net");
119
+
120
+ /* The Proto class encapsulates information associated for network protocol entries */
121
+ cProto = rb_define_class_under(mNet, "Proto", rb_cObject);
122
+
123
+ /* Structure definitions */
124
+ sProto = rb_struct_define("ProtoStruct", "name", "aliases", "proto", 0);
125
+
126
+ /* Class methods */
127
+ rb_define_singleton_method(cProto, "getprotobyname", np_getprotobyname,1);
128
+ rb_define_singleton_method(cProto, "getprotobynumber", np_getprotobynumber,1);
129
+ rb_define_singleton_method(cProto, "getprotoent", np_getprotoent,0);
130
+
131
+ /* 1.0.3: The version of this package. This a string, not a number */
132
+ rb_define_const(cProto, "VERSION", rb_str_new2(NET_PROTO_VERSION));
133
+ }
134
+
135
+ #ifdef __cplusplus
136
+ }
137
+ #endif
@@ -1,2 +1,2 @@
1
1
  /* version.h - there can be only one */
2
- #define NET_PROTO_VERSION "1.0.1"
2
+ #define NET_PROTO_VERSION "1.0.3"
@@ -0,0 +1,73 @@
1
+ /***********************
2
+ * proto.c (windows.c)
3
+ ***********************/
4
+ #include <ruby.h>
5
+ #include <version.h>
6
+ #include <windows.h>
7
+
8
+ #ifdef __cplusplus
9
+ extern "C"
10
+ {
11
+ #endif
12
+
13
+ /*
14
+ * call-seq:
15
+ * Proto.getprotobyname(name)
16
+ *
17
+ * Given a protocol string, returns the corresponding number, or nil if not
18
+ * found.
19
+ */
20
+ static VALUE np_getprotobyname(VALUE klass, VALUE rbProtoName){
21
+ struct protoent* p;
22
+ VALUE v_proto_num = Qnil;
23
+
24
+ SafeStringValue(rbProtoName);
25
+ p = getprotobyname(StringValuePtr(rbProtoName));
26
+
27
+ if(p)
28
+ v_proto_num = INT2FIX(p->p_proto);
29
+
30
+ return v_proto_num;
31
+ }
32
+
33
+ /*
34
+ * call-seq:
35
+ * Proto.getprotobynumber(num)
36
+ *
37
+ * Given a protocol number, returns the corresponding string, or nil if not
38
+ * found.
39
+ */
40
+ static VALUE np_getprotobynumber(VALUE klass, VALUE v_proto_num)
41
+ {
42
+ struct protoent* p;
43
+ VALUE v_proto_name = Qnil;
44
+
45
+ p = getprotobynumber(NUM2INT(v_proto_num));
46
+
47
+ if(p)
48
+ v_proto_name = rb_str_new2(p->p_name);
49
+
50
+ return v_proto_name;
51
+ }
52
+
53
+ void Init_proto()
54
+ {
55
+ VALUE mNet, cProto;
56
+
57
+ /* The Net module serves only as a namespace */
58
+ mNet = rb_define_module("Net");
59
+
60
+ /* The Proto class encapsulates network protocol information */
61
+ cProto = rb_define_class_under(mNet, "Proto", rb_cObject);
62
+
63
+ /* Class Methods */
64
+ rb_define_singleton_method(cProto,"getprotobyname",np_getprotobyname,1);
65
+ rb_define_singleton_method(cProto,"getprotobynumber",np_getprotobynumber,1);
66
+
67
+ /* 1.0.3: The version of this package. This is a string, not a number */
68
+ rb_define_const(cProto, "VERSION", rb_str_new2(NET_PROTO_VERSION));
69
+ }
70
+
71
+ #ifdef __cplusplus
72
+ }
73
+ #endif
data/test/tc_netproto.rb CHANGED
@@ -1,32 +1,9 @@
1
- ############################################
1
+ ###########################################################################
2
2
  # tc_netproto.rb
3
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
-
4
+ # Test suite for net-proto - all platforms. This test suite should be run
5
+ # via the 'rake test' task.
6
+ ###########################################################################
30
7
  require "net/proto"
31
8
  require "test/unit"
32
9
  include Net
@@ -44,7 +21,7 @@ class TC_Net_Proto < Test::Unit::TestCase
44
21
  end
45
22
 
46
23
  def test_version
47
- assert_equal("1.0.1", Proto::VERSION)
24
+ assert_equal("1.0.3", Proto::VERSION)
48
25
  end
49
26
 
50
27
  def test_getprotobynumber
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.0
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: net-proto
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.0.1
7
- date: 2006-06-30 00:00:00 -06:00
6
+ version: 1.0.3
7
+ date: 2007-08-13 00:00:00 -06:00
8
8
  summary: The net-proto package provides the getprotobyname(), getprotobynumber() and the getprotoent() methods for Ruby.
9
9
  require_paths:
10
10
  - lib
@@ -31,12 +31,19 @@ authors:
31
31
  files:
32
32
  - doc/netproto.txt
33
33
  - test/tc_netproto.rb
34
+ - ext/extconf.rb
35
+ - ext/version.h
36
+ - ext/generic
37
+ - ext/generic/generic.c
38
+ - ext/linux
39
+ - ext/linux/linux.c
40
+ - ext/sunos
41
+ - ext/sunos/sunos.c
42
+ - ext/windows
43
+ - ext/windows/windows.c
34
44
  - CHANGES
35
- - MANIFEST
36
45
  - README
37
- - extconf.rb
38
- - lib/version.h
39
- - lib/net/sunos.c
46
+ - MANIFEST
40
47
  test_files:
41
48
  - test/tc_netproto.rb
42
49
  rdoc_options: []
@@ -44,10 +51,12 @@ rdoc_options: []
44
51
  extra_rdoc_files:
45
52
  - CHANGES
46
53
  - README
54
+ - MANIFEST
55
+ - doc/netproto.txt
47
56
  executables: []
48
57
 
49
58
  extensions:
50
- - extconf.rb
59
+ - ext/extconf.rb
51
60
  requirements: []
52
61
 
53
62
  dependencies: []
data/extconf.rb DELETED
@@ -1,30 +0,0 @@
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 DELETED
@@ -1,136 +0,0 @@
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