net-proto 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +9 -0
- data/MANIFEST +1 -1
- data/ext/extconf.rb +9 -6
- data/ext/generic/generic.c +36 -12
- data/ext/linux/linux.c +36 -14
- data/ext/sunos/sunos.c +24 -1
- data/ext/version.h +1 -1
- data/ext/windows/windows.c +14 -1
- data/test/test_net_proto.rb +126 -0
- metadata +55 -39
- data/test/tc_netproto.rb +0 -71
data/CHANGES
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
== 1.0.4 - 6-Jan-2008
|
2
|
+
* The struct returned by Net::Proto.getprotoent is now frozen. This is
|
3
|
+
strictly read-only data.
|
4
|
+
* It is now explicitly illegal to call Net::Proto.new.
|
5
|
+
* Some minor modifications to extconf.rb in terms of how and where the
|
6
|
+
the source is built in order to be potentially more friendly to Rubygems.
|
7
|
+
* Renamed and refactored the test suite. This library now requires test-unit
|
8
|
+
version 2.0.2 or later.
|
9
|
+
|
1
10
|
== 1.0.3 - 13-Aug-2007
|
2
11
|
* Fix for OS X (whining about malloced pointer).
|
3
12
|
* Added a Rakefile along with tasks for installation and testing.
|
data/MANIFEST
CHANGED
data/ext/extconf.rb
CHANGED
@@ -1,16 +1,19 @@
|
|
1
1
|
require 'mkmf'
|
2
2
|
require 'fileutils'
|
3
|
+
require 'rbconfig'
|
3
4
|
|
4
|
-
|
5
|
+
Dir.mkdir('net') unless File.exists?('net')
|
6
|
+
|
7
|
+
case Config::CONFIG['host_os']
|
5
8
|
when /sunos|solaris/i
|
6
9
|
have_library('socket')
|
7
|
-
FileUtils.cp('sunos/sunos.c', 'proto.c')
|
10
|
+
FileUtils.cp('sunos/sunos.c', 'net/proto.c')
|
8
11
|
when /linux/i
|
9
|
-
FileUtils.cp('linux/linux.c', 'proto.c')
|
12
|
+
FileUtils.cp('linux/linux.c', 'net/proto.c')
|
10
13
|
when /win32|windows|dos|mingw|cygwin/i
|
11
|
-
FileUtils.cp('windows/windows.c', 'proto.c')
|
14
|
+
FileUtils.cp('windows/windows.c', 'net/proto.c')
|
12
15
|
else
|
13
|
-
FileUtils.cp('generic/generic.c', 'proto.c')
|
16
|
+
FileUtils.cp('generic/generic.c', 'net/proto.c')
|
14
17
|
end
|
15
18
|
|
16
|
-
create_makefile('net/proto')
|
19
|
+
create_makefile('net/proto', 'net')
|
data/ext/generic/generic.c
CHANGED
@@ -15,15 +15,20 @@ VALUE sProto;
|
|
15
15
|
|
16
16
|
/*
|
17
17
|
* call-seq:
|
18
|
-
* Proto.getprotobyname(name)
|
18
|
+
* Net::Proto.getprotobyname(name)
|
19
19
|
*
|
20
20
|
* Given a protocol string, returns the corresponding number, or nil if not
|
21
21
|
* found.
|
22
|
+
*
|
23
|
+
* Examples:
|
24
|
+
*
|
25
|
+
* Net::Proto.getprotobyname("tcp") # => 6
|
26
|
+
* Net::Proto.getprotobyname("bogus") # => nil
|
22
27
|
*/
|
23
28
|
static VALUE np_getprotobyname(VALUE klass, VALUE v_proto_name){
|
24
29
|
struct protoent* p;
|
25
30
|
VALUE v_proto_num = Qnil;
|
26
|
-
|
31
|
+
|
27
32
|
SafeStringValue(v_proto_name);
|
28
33
|
|
29
34
|
setprotoent(0);
|
@@ -31,7 +36,7 @@ static VALUE np_getprotobyname(VALUE klass, VALUE v_proto_name){
|
|
31
36
|
|
32
37
|
if(p)
|
33
38
|
v_proto_num = INT2FIX(p->p_proto);
|
34
|
-
|
39
|
+
|
35
40
|
endprotoent();
|
36
41
|
|
37
42
|
return v_proto_num;
|
@@ -43,6 +48,11 @@ static VALUE np_getprotobyname(VALUE klass, VALUE v_proto_name){
|
|
43
48
|
*
|
44
49
|
* Given a protocol number, returns the corresponding string, or nil if not
|
45
50
|
* found.
|
51
|
+
*
|
52
|
+
* Examples:
|
53
|
+
*
|
54
|
+
* Net::Proto.getprotobynumber(6) # => "tcp"
|
55
|
+
* Net::Proto.getprotobynumber(999) # => nil
|
46
56
|
*/
|
47
57
|
static VALUE np_getprotobynumber(VALUE klass, VALUE v_proto_num){
|
48
58
|
struct protoent* p;
|
@@ -50,10 +60,10 @@ static VALUE np_getprotobynumber(VALUE klass, VALUE v_proto_num){
|
|
50
60
|
|
51
61
|
setprotoent(0);
|
52
62
|
p = getprotobynumber(NUM2INT(v_proto_num));
|
53
|
-
|
63
|
+
|
54
64
|
if(p)
|
55
65
|
v_proto_name = rb_str_new2(p->p_name);
|
56
|
-
|
66
|
+
|
57
67
|
endprotoent();
|
58
68
|
|
59
69
|
return v_proto_name;
|
@@ -67,9 +77,18 @@ static VALUE np_getprotobynumber(VALUE klass, VALUE v_proto_num){
|
|
67
77
|
* In block form, yields each entry from /etc/protocols as a struct of type
|
68
78
|
* Proto::ProtoStruct. In non-block form, returns an array of
|
69
79
|
* Proto::ProtoStruct objects.
|
70
|
-
|
80
|
+
*
|
71
81
|
* The fields are 'name' (a String), 'aliases' (an Array of String's,
|
72
82
|
* though often only one element), and 'proto' (a Fixnum).
|
83
|
+
*
|
84
|
+
* Example:
|
85
|
+
*
|
86
|
+
* Net::Proto.getprotoent.each{ |prot|
|
87
|
+
* p prot.name
|
88
|
+
* p prot.aliases
|
89
|
+
* p prot.proto
|
90
|
+
* }
|
91
|
+
*
|
73
92
|
*/
|
74
93
|
static VALUE np_getprotoent(VALUE klass){
|
75
94
|
struct protoent* p;
|
@@ -78,15 +97,15 @@ static VALUE np_getprotoent(VALUE klass){
|
|
78
97
|
VALUE v_struct = Qnil;
|
79
98
|
|
80
99
|
p = malloc(sizeof(struct protoent));
|
81
|
-
|
100
|
+
|
82
101
|
if(!rb_block_given_p())
|
83
102
|
v_array = rb_ary_new();
|
84
|
-
|
103
|
+
|
85
104
|
setprotoent(0);
|
86
105
|
|
87
106
|
while((p = getprotoent())){
|
88
107
|
v_aliases = rb_ary_new();
|
89
|
-
|
108
|
+
|
90
109
|
#ifdef __MACH__ or #ifdef __APPLE__
|
91
110
|
char **aliases = p->p_aliases;
|
92
111
|
while(*aliases){
|
@@ -99,13 +118,15 @@ static VALUE np_getprotoent(VALUE klass){
|
|
99
118
|
(void)p->p_aliases++;
|
100
119
|
}
|
101
120
|
#endif
|
102
|
-
|
121
|
+
|
103
122
|
v_struct = rb_struct_new(sProto,
|
104
123
|
rb_str_new2(p->p_name),
|
105
124
|
v_aliases,
|
106
125
|
INT2FIX(p->p_proto)
|
107
126
|
);
|
108
127
|
|
128
|
+
OBJ_FREEZE(v_struct); /* This is read-only data */
|
129
|
+
|
109
130
|
if(rb_block_given_p())
|
110
131
|
rb_yield(v_struct);
|
111
132
|
else
|
@@ -114,7 +135,7 @@ static VALUE np_getprotoent(VALUE klass){
|
|
114
135
|
|
115
136
|
free(p);
|
116
137
|
endprotoent();
|
117
|
-
|
138
|
+
|
118
139
|
return v_array; /* nil if a block is given */
|
119
140
|
}
|
120
141
|
|
@@ -135,7 +156,10 @@ void Init_proto(){
|
|
135
156
|
rb_define_singleton_method(cProto, "getprotobynumber", np_getprotobynumber, 1);
|
136
157
|
rb_define_singleton_method(cProto, "getprotoent", np_getprotoent, 0);
|
137
158
|
|
138
|
-
/*
|
159
|
+
/* There is no constructor */
|
160
|
+
rb_funcall(cProto, rb_intern("private_class_method"), 1, ID2SYM(rb_intern("new")));
|
161
|
+
|
162
|
+
/* 1.0.4: The version of this library. This is a string, not a number */
|
139
163
|
rb_define_const(cProto, "VERSION", rb_str_new2(NET_PROTO_VERSION));
|
140
164
|
}
|
141
165
|
|
data/ext/linux/linux.c
CHANGED
@@ -21,24 +21,29 @@ VALUE sProto;
|
|
21
21
|
*
|
22
22
|
* Given a protocol string, returns the corresponding number, or nil if not
|
23
23
|
* found.
|
24
|
+
*
|
25
|
+
* Examples:
|
26
|
+
*
|
27
|
+
* Net::Proto.getprotobyname("tcp") # => 6
|
28
|
+
* Net::Proto.getprotobyname("bogus") # => nil
|
24
29
|
*/
|
25
30
|
static VALUE np_getprotobyname(VALUE klass, VALUE v_proto_name){
|
26
31
|
struct protoent* p;
|
27
32
|
char buffer[BUF_SIZE];
|
28
33
|
VALUE v_proto_num = Qnil;
|
29
|
-
|
34
|
+
|
30
35
|
SafeStringValue(v_proto_name);
|
31
36
|
|
32
37
|
p = malloc(sizeof(struct protoent));
|
33
38
|
|
34
39
|
setprotoent(0);
|
35
40
|
getprotobyname_r(StringValuePtr(v_proto_name), p, buffer, BUF_SIZE, &p);
|
36
|
-
|
41
|
+
|
37
42
|
if(p){
|
38
43
|
v_proto_num = INT2FIX(p->p_proto);
|
39
44
|
free(p);
|
40
|
-
}
|
41
|
-
|
45
|
+
}
|
46
|
+
|
42
47
|
endprotoent();
|
43
48
|
return v_proto_num;
|
44
49
|
}
|
@@ -49,8 +54,12 @@ static VALUE np_getprotobyname(VALUE klass, VALUE v_proto_name){
|
|
49
54
|
*
|
50
55
|
* Given a protocol number, returns the corresponding string, or nil if not
|
51
56
|
* found.
|
57
|
+
*
|
58
|
+
* Examples:
|
59
|
+
*
|
60
|
+
* Net::Proto.getprotobynumber(6) # => "tcp"
|
61
|
+
* Net::Proto.getprotobynumber(999) # => nil
|
52
62
|
*/
|
53
|
-
|
54
63
|
static VALUE np_getprotobynumber(VALUE klass, VALUE v_proto_num){
|
55
64
|
struct protoent* p;
|
56
65
|
char buffer[BUF_SIZE];
|
@@ -66,7 +75,7 @@ static VALUE np_getprotobynumber(VALUE klass, VALUE v_proto_num){
|
|
66
75
|
v_proto_name = rb_str_new2(proto_name = p->p_name);
|
67
76
|
free(p);
|
68
77
|
}
|
69
|
-
|
78
|
+
|
70
79
|
endprotoent();
|
71
80
|
return v_proto_name;
|
72
81
|
}
|
@@ -79,9 +88,17 @@ static VALUE np_getprotobynumber(VALUE klass, VALUE v_proto_num){
|
|
79
88
|
* In block form, yields each entry from /etc/protocols as a struct of type
|
80
89
|
* Proto::ProtoStruct. In non-block form, returns an array of
|
81
90
|
* Proto::ProtoStruct objects.
|
82
|
-
|
91
|
+
|
83
92
|
* The fields are 'name' (a String), 'aliases' (an Array of String's,
|
84
93
|
* though often only one element), and 'proto' (a Fixnum).
|
94
|
+
*
|
95
|
+
* Example:
|
96
|
+
*
|
97
|
+
* Net::Proto.getprotoent.each{ |prot|
|
98
|
+
* p prot.name
|
99
|
+
* p prot.aliases
|
100
|
+
* p prot.proto
|
101
|
+
* }
|
85
102
|
*/
|
86
103
|
static VALUE np_getprotoent(VALUE klass){
|
87
104
|
struct protoent* p;
|
@@ -93,10 +110,10 @@ static VALUE np_getprotoent(VALUE klass){
|
|
93
110
|
|
94
111
|
p = malloc(sizeof(struct protoent));
|
95
112
|
q = malloc(sizeof(struct protoent));
|
96
|
-
|
113
|
+
|
97
114
|
if(!rb_block_given_p())
|
98
115
|
v_array = rb_ary_new();
|
99
|
-
|
116
|
+
|
100
117
|
setprotoent(0);
|
101
118
|
|
102
119
|
while(!getprotoent_r(p, buffer, BUF_SIZE, &q)){
|
@@ -106,13 +123,15 @@ static VALUE np_getprotoent(VALUE klass){
|
|
106
123
|
rb_ary_push(v_alias_array, rb_str_new2(*p->p_aliases));
|
107
124
|
(void)*p->p_aliases++;
|
108
125
|
}
|
109
|
-
|
126
|
+
|
110
127
|
v_struct = rb_struct_new(sProto,
|
111
128
|
rb_str_new2(p->p_name),
|
112
129
|
v_alias_array,
|
113
130
|
INT2FIX(p->p_proto)
|
114
131
|
);
|
115
|
-
|
132
|
+
|
133
|
+
OBJ_FREEZE(v_struct); /* This is read-only data */
|
134
|
+
|
116
135
|
if(rb_block_given_p())
|
117
136
|
rb_yield(v_struct);
|
118
137
|
else
|
@@ -121,9 +140,9 @@ static VALUE np_getprotoent(VALUE klass){
|
|
121
140
|
|
122
141
|
free(p);
|
123
142
|
free(q);
|
124
|
-
|
143
|
+
|
125
144
|
endprotoent();
|
126
|
-
|
145
|
+
|
127
146
|
return v_array; /* nil if a block was given */
|
128
147
|
}
|
129
148
|
|
@@ -139,12 +158,15 @@ void Init_proto(){
|
|
139
158
|
/* Structure definitions */
|
140
159
|
sProto = rb_struct_define("ProtoStruct", "name", "aliases", "proto", 0);
|
141
160
|
|
161
|
+
/* There is no constructor */
|
162
|
+
rb_funcall(cProto, rb_intern("private_class_method"), 1, ID2SYM(rb_intern("new")));
|
163
|
+
|
142
164
|
/* Class methods */
|
143
165
|
rb_define_singleton_method(cProto, "getprotobyname", np_getprotobyname, 1);
|
144
166
|
rb_define_singleton_method(cProto, "getprotobynumber", np_getprotobynumber, 1);
|
145
167
|
rb_define_singleton_method(cProto, "getprotoent", np_getprotoent, 0);
|
146
168
|
|
147
|
-
/* 1.0.
|
169
|
+
/* 1.0.4: The version of this library. This is a string, not a number */
|
148
170
|
rb_define_const(cProto, "VERSION", rb_str_new2(NET_PROTO_VERSION));
|
149
171
|
}
|
150
172
|
|
data/ext/sunos/sunos.c
CHANGED
@@ -21,6 +21,11 @@ VALUE sProto;
|
|
21
21
|
*
|
22
22
|
* Given a protocol string, returns the corresponding number, or nil if not
|
23
23
|
* found.
|
24
|
+
*
|
25
|
+
* Examples:
|
26
|
+
*
|
27
|
+
* Net::Proto.getprotobyname("tcp") # => 6
|
28
|
+
* Net::Proto.getprotobyname("bogus") # => nil
|
24
29
|
*/
|
25
30
|
static VALUE np_getprotobyname(VALUE klass, VALUE v_proto_name){
|
26
31
|
struct protoent p;
|
@@ -45,6 +50,11 @@ static VALUE np_getprotobyname(VALUE klass, VALUE v_proto_name){
|
|
45
50
|
*
|
46
51
|
* Given a protocol number, returns the corresponding string, or nil if not
|
47
52
|
* found.
|
53
|
+
*
|
54
|
+
* Examples:
|
55
|
+
*
|
56
|
+
* Net::Proto.getprotobynumber(6) # => "tcp"
|
57
|
+
* Net::Proto.getprotobynumber(999) # => nil
|
48
58
|
*/
|
49
59
|
static VALUE np_getprotobynumber(VALUE klass, VALUE v_proto_num){
|
50
60
|
struct protoent p;
|
@@ -72,6 +82,14 @@ static VALUE np_getprotobynumber(VALUE klass, VALUE v_proto_num){
|
|
72
82
|
|
73
83
|
* The fields are 'name' (a String), 'aliases' (an Array of String's,
|
74
84
|
* though often only one element), and 'proto' (a Fixnum).
|
85
|
+
*
|
86
|
+
* Example:
|
87
|
+
*
|
88
|
+
* Net::Proto.getprotoent.each{ |prot|
|
89
|
+
* p prot.name
|
90
|
+
* p prot.aliases
|
91
|
+
* p prot.proto
|
92
|
+
* }
|
75
93
|
*/
|
76
94
|
static VALUE np_getprotoent(){
|
77
95
|
struct protoent p;
|
@@ -99,6 +117,8 @@ static VALUE np_getprotoent(){
|
|
99
117
|
INT2FIX(p.p_proto)
|
100
118
|
);
|
101
119
|
|
120
|
+
OBJ_FREEZE(v_struct); /* This is read-only data */
|
121
|
+
|
102
122
|
if(rb_block_given_p())
|
103
123
|
rb_yield(v_struct);
|
104
124
|
else
|
@@ -123,12 +143,15 @@ void Init_proto()
|
|
123
143
|
/* Structure definitions */
|
124
144
|
sProto = rb_struct_define("ProtoStruct", "name", "aliases", "proto", 0);
|
125
145
|
|
146
|
+
/* There is no constructor */
|
147
|
+
rb_funcall(cProto, rb_intern("private_class_method"), 1, ID2SYM(rb_intern("new")));
|
148
|
+
|
126
149
|
/* Class methods */
|
127
150
|
rb_define_singleton_method(cProto, "getprotobyname", np_getprotobyname,1);
|
128
151
|
rb_define_singleton_method(cProto, "getprotobynumber", np_getprotobynumber,1);
|
129
152
|
rb_define_singleton_method(cProto, "getprotoent", np_getprotoent,0);
|
130
153
|
|
131
|
-
/* 1.0.
|
154
|
+
/* 1.0.4: The version of this library. This a string, not a number */
|
132
155
|
rb_define_const(cProto, "VERSION", rb_str_new2(NET_PROTO_VERSION));
|
133
156
|
}
|
134
157
|
|
data/ext/version.h
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
/* version.h - there can be only one */
|
2
|
-
#define NET_PROTO_VERSION "1.0.
|
2
|
+
#define NET_PROTO_VERSION "1.0.4"
|
data/ext/windows/windows.c
CHANGED
@@ -16,6 +16,11 @@ extern "C"
|
|
16
16
|
*
|
17
17
|
* Given a protocol string, returns the corresponding number, or nil if not
|
18
18
|
* found.
|
19
|
+
*
|
20
|
+
* Examples:
|
21
|
+
*
|
22
|
+
* Net::Proto.getprotobyname("tcp") # => 6
|
23
|
+
* Net::Proto.getprotobyname("bogus") # => nil
|
19
24
|
*/
|
20
25
|
static VALUE np_getprotobyname(VALUE klass, VALUE rbProtoName){
|
21
26
|
struct protoent* p;
|
@@ -36,6 +41,11 @@ static VALUE np_getprotobyname(VALUE klass, VALUE rbProtoName){
|
|
36
41
|
*
|
37
42
|
* Given a protocol number, returns the corresponding string, or nil if not
|
38
43
|
* found.
|
44
|
+
*
|
45
|
+
* Examples:
|
46
|
+
*
|
47
|
+
* Net::Proto.getprotobynumber(6) # => "tcp"
|
48
|
+
* Net::Proto.getprotobynumber(999) # => nil
|
39
49
|
*/
|
40
50
|
static VALUE np_getprotobynumber(VALUE klass, VALUE v_proto_num)
|
41
51
|
{
|
@@ -64,7 +74,10 @@ void Init_proto()
|
|
64
74
|
rb_define_singleton_method(cProto,"getprotobyname",np_getprotobyname,1);
|
65
75
|
rb_define_singleton_method(cProto,"getprotobynumber",np_getprotobynumber,1);
|
66
76
|
|
67
|
-
/*
|
77
|
+
/* There is no constructor */
|
78
|
+
rb_funcall(cProto, rb_intern("private_class_method"), 1, ID2SYM(rb_intern("new")));
|
79
|
+
|
80
|
+
/* 1.0.4: The version of this library. This is a string, not a number */
|
68
81
|
rb_define_const(cProto, "VERSION", rb_str_new2(NET_PROTO_VERSION));
|
69
82
|
}
|
70
83
|
|
@@ -0,0 +1,126 @@
|
|
1
|
+
###########################################################################
|
2
|
+
# test_net_netproto.rb
|
3
|
+
#
|
4
|
+
# Test suite for net-proto - all platforms. This test suite should be run
|
5
|
+
# via the 'rake test' task.
|
6
|
+
###########################################################################
|
7
|
+
require 'rubygems'
|
8
|
+
gem 'test-unit'
|
9
|
+
|
10
|
+
require 'net/proto'
|
11
|
+
require 'test/unit'
|
12
|
+
|
13
|
+
class TC_Net_Proto < Test::Unit::TestCase
|
14
|
+
|
15
|
+
# These were the protocols listed in my own /etc/protocols file on Solaris 9
|
16
|
+
def self.startup
|
17
|
+
@@protocols = %w/
|
18
|
+
ip icmp igmp ggp ipip tcp cbt egp igp pup udp mux hmp
|
19
|
+
xns-idp rdp idpr idpr-cmtp sdrp idrp rsvp gre
|
20
|
+
mobile ospf pim ipcomp vrrp sctp hopopt ipv6
|
21
|
+
ipv6-route ipv6-frag esp ah ipv6-icmp ipv6-nonxt ipv6-opts
|
22
|
+
/
|
23
|
+
end
|
24
|
+
|
25
|
+
def setup
|
26
|
+
@protoent = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_version
|
30
|
+
assert_equal('1.0.4', Net::Proto::VERSION)
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_getprotobynumber_basic
|
34
|
+
assert_respond_to(Net::Proto, :getprotobynumber)
|
35
|
+
assert_nothing_raised{ 0.upto(132){ |n| Net::Proto.getprotobynumber(n) } }
|
36
|
+
assert_kind_of(String, Net::Proto.getprotobynumber(1))
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_getprotobynumber_result_expected
|
40
|
+
assert_equal('icmp', Net::Proto.getprotobynumber(1))
|
41
|
+
assert_equal('tcp', Net::Proto.getprotobynumber(6))
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_getprotbynumber_result_not_expected
|
45
|
+
assert_equal(nil, Net::Proto.getprotobynumber(9999999))
|
46
|
+
assert_equal(nil, Net::Proto.getprotobynumber(-1))
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_getprotobynumber_expected_errors
|
50
|
+
assert_raise(TypeError){ Net::Proto.getprotobynumber('foo') }
|
51
|
+
assert_raise(TypeError){ Net::Proto.getprotobynumber(nil) }
|
52
|
+
assert_raise(RangeError){ Net::Proto.getprotobynumber(999999999999) }
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_getprotobyname_basic
|
56
|
+
assert_respond_to(Net::Proto, :getprotobyname)
|
57
|
+
@@protocols.each{ |n| assert_nothing_raised{ Net::Proto.getprotobyname(n) } }
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_getprotobyname_result_expected
|
61
|
+
assert_equal(1, Net::Proto.getprotobyname('icmp'))
|
62
|
+
assert_equal(6, Net::Proto.getprotobyname('tcp'))
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_getprotobyname_result_not_expected
|
66
|
+
assert_equal(nil, Net::Proto.getprotobyname('foo'))
|
67
|
+
assert_equal(nil, Net::Proto.getprotobyname('tcpx'))
|
68
|
+
assert_equal(nil, Net::Proto.getprotobyname(''))
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_getprotobyname_expected_errors
|
72
|
+
assert_raises(TypeError){ Net::Proto.getprotobyname(1) }
|
73
|
+
assert_raises(TypeError){ Net::Proto.getprotobyname(nil) }
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_getprotoent_basic
|
77
|
+
omit_if(Config::CONFIG['host_os'].match('mswin'), 'Skipped on MS Windows')
|
78
|
+
|
79
|
+
assert_respond_to(Net::Proto, :getprotoent)
|
80
|
+
assert_nothing_raised{ Net::Proto.getprotoent }
|
81
|
+
assert_kind_of(Array, Net::Proto.getprotoent)
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_getprotoent
|
85
|
+
omit_if(Config::CONFIG['host_os'].match('mswin'), 'Skipped on MS Windows')
|
86
|
+
|
87
|
+
assert_kind_of(Struct::ProtoStruct, Net::Proto.getprotoent.first)
|
88
|
+
assert_nil(Net::Proto.getprotoent{})
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_getprotoent_struct
|
92
|
+
omit_if(Config::CONFIG['host_os'].match('mswin'), 'Skipped on MS Windows')
|
93
|
+
|
94
|
+
@protoent = Net::Proto.getprotoent.first
|
95
|
+
assert_equal(['name', 'aliases', 'proto'], @protoent.members)
|
96
|
+
assert_kind_of(String, @protoent.name)
|
97
|
+
assert_kind_of(Array, @protoent.aliases)
|
98
|
+
assert_kind_of(Integer, @protoent.proto)
|
99
|
+
end
|
100
|
+
|
101
|
+
def test_getprotoent_struct_aliases_member
|
102
|
+
omit_if(Config::CONFIG['host_os'].match('mswin'), 'Skipped on MS Windows')
|
103
|
+
|
104
|
+
@protoent = Net::Proto.getprotoent.first
|
105
|
+
assert_true(@protoent.aliases.all?{ |e| e.is_a?(String) })
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_getprotoent_struct_frozen
|
109
|
+
omit_if(Config::CONFIG['host_os'].match('mswin'), 'Skipped on MS Windows')
|
110
|
+
|
111
|
+
@protoent = Net::Proto.getprotoent.first
|
112
|
+
assert_true(@protoent.frozen?)
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_constructor_illegal
|
116
|
+
assert_raise(NoMethodError){ Net::Proto.new }
|
117
|
+
end
|
118
|
+
|
119
|
+
def teardown
|
120
|
+
@protoent = nil
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.shutdown
|
124
|
+
@@protocols = nil
|
125
|
+
end
|
126
|
+
end
|
metadata
CHANGED
@@ -1,63 +1,79 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: net-proto
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.0.
|
7
|
-
date: 2007-08-13 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:
|
4
|
+
version: 1.0.4
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Daniel J. Berger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-01-06 00:00:00 -07:00
|
13
|
+
default_executable:
|
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:
|
25
|
+
description: The net-proto package provides the getprotobyname(), getprotobynumber() and the getprotoent() methods for Ruby.
|
26
|
+
email: djberg96@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions:
|
30
|
+
- ext/extconf.rb
|
31
|
+
extra_rdoc_files:
|
32
|
+
- CHANGES
|
33
|
+
- README
|
34
|
+
- MANIFEST
|
35
|
+
- doc/netproto.txt
|
31
36
|
files:
|
32
37
|
- doc/netproto.txt
|
33
|
-
- test/
|
38
|
+
- test/test_net_proto.rb
|
34
39
|
- ext/extconf.rb
|
35
|
-
- ext/version.h
|
36
40
|
- ext/generic
|
37
41
|
- ext/generic/generic.c
|
38
42
|
- ext/linux
|
39
43
|
- ext/linux/linux.c
|
40
44
|
- ext/sunos
|
41
45
|
- ext/sunos/sunos.c
|
46
|
+
- ext/version.h
|
42
47
|
- ext/windows
|
43
48
|
- ext/windows/windows.c
|
44
49
|
- CHANGES
|
45
50
|
- README
|
46
51
|
- MANIFEST
|
47
|
-
|
48
|
-
|
52
|
+
has_rdoc: true
|
53
|
+
homepage: http://www.rubyforge.org/projects/sysutils
|
54
|
+
post_install_message:
|
49
55
|
rdoc_options: []
|
50
56
|
|
51
|
-
|
52
|
-
-
|
53
|
-
|
54
|
-
|
55
|
-
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 1.8.0
|
64
|
+
version:
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: "0"
|
70
|
+
version:
|
60
71
|
requirements: []
|
61
72
|
|
62
|
-
|
63
|
-
|
73
|
+
rubyforge_project: sysutils
|
74
|
+
rubygems_version: 1.2.0
|
75
|
+
signing_key:
|
76
|
+
specification_version: 2
|
77
|
+
summary: The net-proto package provides the getprotobyname(), getprotobynumber() and the getprotoent() methods for Ruby.
|
78
|
+
test_files:
|
79
|
+
- test/test_net_proto.rb
|
data/test/tc_netproto.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
###########################################################################
|
2
|
-
# tc_netproto.rb
|
3
|
-
#
|
4
|
-
# Test suite for net-proto - all platforms. This test suite should be run
|
5
|
-
# via the 'rake test' task.
|
6
|
-
###########################################################################
|
7
|
-
require "net/proto"
|
8
|
-
require "test/unit"
|
9
|
-
include Net
|
10
|
-
|
11
|
-
class TC_Net_Proto < Test::Unit::TestCase
|
12
|
-
# These were the protocols listed in my
|
13
|
-
# own /etc/protocols file on Solaris 9.
|
14
|
-
def setup
|
15
|
-
@protocols = %w/
|
16
|
-
ip icmp igmp ggp ipip tcp cbt egp igp pup udp mux hmp
|
17
|
-
xns-idp rdp idpr idpr-cmtp sdrp idrp rsvp gre
|
18
|
-
mobile ospf pim ipcomp vrrp sctp hopopt ipv6
|
19
|
-
ipv6-route ipv6-frag esp ah ipv6-icmp ipv6-nonxt ipv6-opts
|
20
|
-
/
|
21
|
-
end
|
22
|
-
|
23
|
-
def test_version
|
24
|
-
assert_equal("1.0.3", Proto::VERSION)
|
25
|
-
end
|
26
|
-
|
27
|
-
def test_getprotobynumber
|
28
|
-
assert_respond_to(Proto, :getprotobynumber)
|
29
|
-
assert_raises(TypeError){ Proto.getprotobynumber("foo") }
|
30
|
-
assert_raises(TypeError){ Proto.getprotobynumber(nil) }
|
31
|
-
assert_equal(nil, Proto.getprotobynumber(9999999))
|
32
|
-
assert_equal("tcp", Proto.getprotobynumber(6))
|
33
|
-
assert_nothing_raised{
|
34
|
-
0.upto(132){ |n| Proto.getprotobynumber(n) }
|
35
|
-
}
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_getprotobyname
|
39
|
-
assert_respond_to(Proto, :getprotobyname)
|
40
|
-
assert_raises(TypeError){ Proto.getprotobyname(1) }
|
41
|
-
assert_raises(TypeError){ Proto.getprotobyname(nil) }
|
42
|
-
assert_equal(nil, Proto.getprotobyname("foo"))
|
43
|
-
assert_equal(6, Proto.getprotobyname("tcp"))
|
44
|
-
@protocols.each{ |prot|
|
45
|
-
assert_nothing_raised{ Proto.getprotobyname(prot) }
|
46
|
-
}
|
47
|
-
end
|
48
|
-
|
49
|
-
def test_getprotoent
|
50
|
-
if File::ALT_SEPARATOR
|
51
|
-
msg = "The getprotoent() function is not supported on this "
|
52
|
-
msg += "platform - test skipped"
|
53
|
-
STDERR.puts msg
|
54
|
-
else
|
55
|
-
assert_respond_to(Proto, :getprotoent)
|
56
|
-
p = Proto.getprotoent.first
|
57
|
-
assert_kind_of(Struct::ProtoStruct, p)
|
58
|
-
assert_equal(%w/name aliases proto/,p.members)
|
59
|
-
assert_kind_of(String, p.name, "Bad type for name")
|
60
|
-
assert_kind_of(Array, p.aliases, "Bad type for aliases")
|
61
|
-
assert_kind_of(Integer, p.proto, "Bad type for proto")
|
62
|
-
p.aliases.each{ |a|
|
63
|
-
assert_kind_of(String, a, "Bad type for aliases member")
|
64
|
-
}
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def teardown
|
69
|
-
@protocols = nil
|
70
|
-
end
|
71
|
-
end
|