net-proto 1.0.6 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +9 -0
- data/MANIFEST +6 -6
- data/README +22 -15
- data/Rakefile +7 -58
- data/doc/netproto.txt +14 -17
- data/examples/example_net_proto.rb +11 -11
- data/lib/generic/net/proto.rb +145 -0
- data/lib/linux/net/proto.rb +140 -0
- data/lib/net/proto.rb +10 -0
- data/lib/net/proto/common.rb +37 -0
- data/lib/sunos/net/proto.rb +134 -0
- data/net-proto.gemspec +3 -6
- data/test/test_net_proto.rb +52 -45
- metadata +40 -27
- data/ext/extconf.rb +0 -19
- data/ext/generic/generic.c +0 -168
- data/ext/linux/linux.c +0 -175
- data/ext/sunos/sunos.c +0 -160
- data/ext/version.h +0 -2
- data/ext/windows/windows.c +0 -86
data/ext/version.h
DELETED
data/ext/windows/windows.c
DELETED
@@ -1,86 +0,0 @@
|
|
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
|
-
* Examples:
|
21
|
-
*
|
22
|
-
* Net::Proto.getprotobyname("tcp") # => 6
|
23
|
-
* Net::Proto.getprotobyname("bogus") # => nil
|
24
|
-
*/
|
25
|
-
static VALUE np_getprotobyname(VALUE klass, VALUE rbProtoName){
|
26
|
-
struct protoent* p;
|
27
|
-
VALUE v_proto_num = Qnil;
|
28
|
-
|
29
|
-
SafeStringValue(rbProtoName);
|
30
|
-
p = getprotobyname(StringValuePtr(rbProtoName));
|
31
|
-
|
32
|
-
if(p)
|
33
|
-
v_proto_num = INT2FIX(p->p_proto);
|
34
|
-
|
35
|
-
return v_proto_num;
|
36
|
-
}
|
37
|
-
|
38
|
-
/*
|
39
|
-
* call-seq:
|
40
|
-
* Proto.getprotobynumber(num)
|
41
|
-
*
|
42
|
-
* Given a protocol number, returns the corresponding string, or nil if not
|
43
|
-
* found.
|
44
|
-
*
|
45
|
-
* Examples:
|
46
|
-
*
|
47
|
-
* Net::Proto.getprotobynumber(6) # => "tcp"
|
48
|
-
* Net::Proto.getprotobynumber(999) # => nil
|
49
|
-
*/
|
50
|
-
static VALUE np_getprotobynumber(VALUE klass, VALUE v_proto_num)
|
51
|
-
{
|
52
|
-
struct protoent* p;
|
53
|
-
VALUE v_proto_name = Qnil;
|
54
|
-
|
55
|
-
p = getprotobynumber(NUM2INT(v_proto_num));
|
56
|
-
|
57
|
-
if(p)
|
58
|
-
v_proto_name = rb_str_new2(p->p_name);
|
59
|
-
|
60
|
-
return v_proto_name;
|
61
|
-
}
|
62
|
-
|
63
|
-
void Init_proto()
|
64
|
-
{
|
65
|
-
VALUE mNet, cProto;
|
66
|
-
|
67
|
-
/* The Net module serves only as a namespace */
|
68
|
-
mNet = rb_define_module("Net");
|
69
|
-
|
70
|
-
/* The Proto class encapsulates network protocol information */
|
71
|
-
cProto = rb_define_class_under(mNet, "Proto", rb_cObject);
|
72
|
-
|
73
|
-
/* Class Methods */
|
74
|
-
rb_define_singleton_method(cProto,"getprotobyname",np_getprotobyname,1);
|
75
|
-
rb_define_singleton_method(cProto,"getprotobynumber",np_getprotobynumber,1);
|
76
|
-
|
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 */
|
81
|
-
rb_define_const(cProto, "VERSION", rb_str_new2(NET_PROTO_VERSION));
|
82
|
-
}
|
83
|
-
|
84
|
-
#ifdef __cplusplus
|
85
|
-
}
|
86
|
-
#endif
|