sys-host 0.6.1 → 0.6.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +11 -0
- data/MANIFEST +10 -8
- data/Rakefile +139 -48
- data/doc/host.txt +46 -46
- data/examples/example_sys_host.rb +21 -0
- data/ext/bsd/extconf.rb +11 -0
- data/ext/bsd/sys/host.c +268 -0
- data/sys-host.gemspec +40 -0
- data/test/test_sys_host.rb +112 -78
- metadata +33 -25
- data/ext/bsd/bsd.c +0 -247
- data/ext/constants.h +0 -14
- data/ext/extconf.rb +0 -35
- data/ext/generic/generic.c +0 -189
- data/ext/linux/linux.c +0 -228
- data/ext/sunos/sunos.c +0 -242
data/sys-host.gemspec
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rbconfig'
|
3
|
+
include Config
|
4
|
+
|
5
|
+
# Some additional specification options are handled by the gem:create task.
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'sys-host'
|
9
|
+
spec.version = '0.6.2'
|
10
|
+
spec.author = 'Daniel J. Berger'
|
11
|
+
spec.license = 'Artistic 2.0'
|
12
|
+
spec.email = 'djberg96@gmail.com'
|
13
|
+
spec.homepage = 'http://www.rubyforge.org/projects/sysutils'
|
14
|
+
spec.platform = Gem::Platform::RUBY
|
15
|
+
spec.summary = 'Provides hostname and ip address info for a given host'
|
16
|
+
spec.test_file = 'test/test_sys_host.rb'
|
17
|
+
spec.has_rdoc = true
|
18
|
+
|
19
|
+
spec.files = %w[
|
20
|
+
CHANGES
|
21
|
+
MANIFEST
|
22
|
+
README
|
23
|
+
Rakefile
|
24
|
+
sys-host.gemspec
|
25
|
+
doc/host.txt
|
26
|
+
examples/example_sys_host.rb
|
27
|
+
test/test_sys_host.rb
|
28
|
+
]
|
29
|
+
|
30
|
+
spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
|
31
|
+
spec.rubyforge_project = 'sysutils'
|
32
|
+
|
33
|
+
spec.add_development_dependency('test-unit', '>= 2.0.7')
|
34
|
+
|
35
|
+
spec.description = <<-EOF
|
36
|
+
The sys-host library provides information about the current machine that
|
37
|
+
your program is running on. Specifically, it returns hostname, IP
|
38
|
+
address information, aliases and so on.
|
39
|
+
EOF
|
40
|
+
end
|
data/test/test_sys_host.rb
CHANGED
@@ -14,82 +14,116 @@ include Config
|
|
14
14
|
include Sys
|
15
15
|
|
16
16
|
class TC_Sys_Host < Test::Unit::TestCase
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
17
|
+
def self.startup
|
18
|
+
if CONFIG['host_os'] =~ /mswin|solaris|linux|bsd|mach|darwin|osx/i
|
19
|
+
@@info_supported = true
|
20
|
+
else
|
21
|
+
@@info_supported = false
|
22
|
+
end
|
23
|
+
|
24
|
+
@@windows = CONFIG['host_os'].match('mswin')
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_version
|
28
|
+
assert_equal('0.6.2', Host::VERSION)
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_hostname_basic
|
32
|
+
assert_respond_to(Host, :hostname)
|
33
|
+
assert_nothing_raised{ Host.hostname }
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_hostname
|
37
|
+
assert_kind_of(String, Host.hostname)
|
38
|
+
assert_equal(`hostname`.chomp, Host.hostname) # sanity check
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_hostname_expected_errors
|
42
|
+
assert_raise(ArgumentError){ Host.hostname(true) }
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_ip_addr_basic
|
46
|
+
assert_respond_to(Host, :ip_addr)
|
47
|
+
assert_nothing_raised{ Host.ip_addr }
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_ip_addr
|
51
|
+
assert_kind_of(Array, Host.ip_addr)
|
52
|
+
assert_kind_of(String, Host.ip_addr.first)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_ip_addr_expected_errors
|
56
|
+
assert_raise(ArgumentError){ Host.ip_addr(true) }
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_host_id_basic
|
60
|
+
assert_respond_to(Host, :host_id)
|
61
|
+
assert_nothing_raised{ Host.host_id }
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_host_id
|
65
|
+
type = @@windows ? String : Integer
|
66
|
+
assert_kind_of(type, Host.host_id)
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_host_id_expected_errors
|
70
|
+
assert_raise(ArgumentError){ Host.host_id(true) }
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_info_basic
|
74
|
+
omit_unless(@@info_supported, 'info test skipped on this platform')
|
75
|
+
assert_respond_to(Host, :info)
|
76
|
+
assert_nothing_raised{ Host.info }
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_info
|
80
|
+
omit_unless(@@info_supported, 'info test skipped on this platform')
|
81
|
+
assert_kind_of(Array, Host.info)
|
82
|
+
assert_kind_of(Struct::HostInfo, Host.info.first)
|
83
|
+
assert_nil(Host.info{ })
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_info_name_member
|
87
|
+
omit_unless(@@info_supported, 'info test skipped on this platform')
|
88
|
+
assert_true(Host.info.first.members.map{ |e| e.to_s }.include?('name'))
|
89
|
+
assert_kind_of(String, Host.info.first.name)
|
90
|
+
assert_true(Host.info.first.name.size > 0)
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_info_addr_type_member
|
94
|
+
omit_unless(@@info_supported, 'info test skipped on this platform')
|
95
|
+
assert_true(Host.info.first.members.map{ |e| e.to_s }.include?('addr_type'))
|
96
|
+
assert_kind_of(Fixnum, Host.info.first.addr_type)
|
97
|
+
assert_true(Host.info.first.addr_type >= 0)
|
98
|
+
end
|
99
|
+
|
100
|
+
def test_info_aliases_member
|
101
|
+
omit_unless(@@info_supported, 'info test skipped on this platform')
|
102
|
+
assert_true(Host.info.first.members.map{ |e| e.to_s }.include?('aliases'))
|
103
|
+
assert_kind_of(Array, Host.info.first.aliases)
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_info_length_member
|
107
|
+
omit_unless(@@info_supported, 'info test skipped on this platform')
|
108
|
+
assert_true(Host.info.first.members.map{ |e| e.to_s }.include?('length'))
|
109
|
+
assert_kind_of(Fixnum, Host.info.first.length)
|
110
|
+
assert_true(Host.info.first.length >= 4)
|
111
|
+
end
|
112
|
+
|
113
|
+
def test_info_addr_list_member
|
114
|
+
omit_unless(@@info_supported, 'info test skipped on this platform')
|
115
|
+
assert_true(Host.info.first.members.map{ |e| e.to_s }.include?('addr_list'))
|
116
|
+
assert_kind_of(Array, Host.info.first.addr_list)
|
117
|
+
assert_true(Host.info.first.addr_list.first.length > 0)
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_info_high_iteration
|
121
|
+
omit_unless(@@info_supported, 'info test skipped on this platform')
|
122
|
+
assert_nothing_raised{ 100.times{ Host.info } }
|
123
|
+
end
|
124
|
+
|
125
|
+
def self.shutdown
|
126
|
+
@@info_supported = nil
|
127
|
+
@@windows = nil
|
128
|
+
end
|
95
129
|
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sys-host
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 6
|
8
|
+
- 2
|
9
|
+
version: 0.6.2
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Daniel J. Berger
|
@@ -9,47 +14,48 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-03-20 00:00:00 -06:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: test-unit
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
25
|
-
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 0
|
30
|
+
- 7
|
31
|
+
version: 2.0.7
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
34
|
+
description: " The sys-host library provides information about the current machine that\n your program is running on. Specifically, it returns hostname, IP\n address information, aliases and so on.\n"
|
26
35
|
email: djberg96@gmail.com
|
27
36
|
executables: []
|
28
37
|
|
29
38
|
extensions:
|
30
|
-
- ext/extconf.rb
|
39
|
+
- ext/bsd/extconf.rb
|
31
40
|
extra_rdoc_files:
|
32
41
|
- CHANGES
|
33
42
|
- README
|
34
43
|
- MANIFEST
|
35
|
-
- ext/bsd/
|
36
|
-
- ext/generic/generic.c
|
37
|
-
- ext/linux/linux.c
|
38
|
-
- ext/sunos/sunos.c
|
44
|
+
- ext/bsd/sys/host.c
|
39
45
|
files:
|
40
|
-
- doc/host.txt
|
41
|
-
- test/test_sys_host.rb
|
42
46
|
- CHANGES
|
43
47
|
- MANIFEST
|
44
48
|
- README
|
45
49
|
- Rakefile
|
46
|
-
-
|
47
|
-
-
|
48
|
-
-
|
49
|
-
-
|
50
|
-
- ext/
|
50
|
+
- sys-host.gemspec
|
51
|
+
- doc/host.txt
|
52
|
+
- examples/example_sys_host.rb
|
53
|
+
- test/test_sys_host.rb
|
54
|
+
- ext/bsd/sys/host.c
|
51
55
|
has_rdoc: true
|
52
56
|
homepage: http://www.rubyforge.org/projects/sysutils
|
57
|
+
licenses:
|
58
|
+
- Artistic 2.0
|
53
59
|
post_install_message:
|
54
60
|
rdoc_options: []
|
55
61
|
|
@@ -59,20 +65,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
59
65
|
requirements:
|
60
66
|
- - ">="
|
61
67
|
- !ruby/object:Gem::Version
|
62
|
-
|
63
|
-
|
68
|
+
segments:
|
69
|
+
- 0
|
70
|
+
version: "0"
|
64
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
72
|
requirements:
|
66
73
|
- - ">="
|
67
74
|
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 0
|
68
77
|
version: "0"
|
69
|
-
version:
|
70
78
|
requirements: []
|
71
79
|
|
72
80
|
rubyforge_project: sysutils
|
73
|
-
rubygems_version: 1.
|
81
|
+
rubygems_version: 1.3.6
|
74
82
|
signing_key:
|
75
|
-
specification_version:
|
83
|
+
specification_version: 3
|
76
84
|
summary: Provides hostname and ip address info for a given host
|
77
85
|
test_files:
|
78
86
|
- test/test_sys_host.rb
|
data/ext/bsd/bsd.c
DELETED
@@ -1,247 +0,0 @@
|
|
1
|
-
/******************************************************************************
|
2
|
-
* bsd.c (host.c) - Ruby extension for the sys-host package for BSD flavors,
|
3
|
-
* including OS X.
|
4
|
-
*
|
5
|
-
* Author: Daniel Berger
|
6
|
-
*****************************************************************************/
|
7
|
-
#include <ruby.h>
|
8
|
-
#include <constants.h>
|
9
|
-
#include <unistd.h>
|
10
|
-
#include <netdb.h>
|
11
|
-
#include <arpa/inet.h>
|
12
|
-
#include <sys/socket.h>
|
13
|
-
#include <sys/types.h>
|
14
|
-
#include <errno.h>
|
15
|
-
|
16
|
-
#ifdef __cplusplus
|
17
|
-
extern "C"
|
18
|
-
{
|
19
|
-
#endif
|
20
|
-
|
21
|
-
VALUE cHostError, sHostInfo;
|
22
|
-
|
23
|
-
/*
|
24
|
-
* call-seq:
|
25
|
-
* Host.hostname
|
26
|
-
*
|
27
|
-
* Returns the hostname of the current host. This may or not return the FQDN,
|
28
|
-
* depending on your system.
|
29
|
-
*/
|
30
|
-
static VALUE host_hostname(){
|
31
|
-
char host_name[MAXHOSTNAMELEN];
|
32
|
-
int rv;
|
33
|
-
rv = gethostname(host_name, MAXHOSTNAMELEN);
|
34
|
-
|
35
|
-
/* If you get this exception, you've got big problems */
|
36
|
-
if(rv != 0)
|
37
|
-
rb_raise(cHostError, "gethostname() call failed: %s", strerror(errno));
|
38
|
-
|
39
|
-
return rb_str_new2(host_name);
|
40
|
-
}
|
41
|
-
|
42
|
-
/*
|
43
|
-
* call-seq:
|
44
|
-
* Host.ip_addr
|
45
|
-
*
|
46
|
-
* Returns a list of IP addresses for the current host (yes, it is possible
|
47
|
-
* to have more than one).
|
48
|
-
*/
|
49
|
-
static VALUE host_ip_addr(){
|
50
|
-
char host_name[MAXHOSTNAMELEN];
|
51
|
-
char str[INET_ADDRSTRLEN];
|
52
|
-
char **pptr;
|
53
|
-
struct hostent* hp;
|
54
|
-
int err;
|
55
|
-
VALUE v_results = rb_ary_new();
|
56
|
-
#ifndef HAVE_INET_NTOP
|
57
|
-
struct in_addr ipa;
|
58
|
-
int n;
|
59
|
-
#endif
|
60
|
-
|
61
|
-
if(gethostname(host_name, MAXHOSTNAMELEN) != 0)
|
62
|
-
rb_raise(cHostError, "gethostname() call failed");
|
63
|
-
|
64
|
-
#ifdef HAVE_GETIPNODEBYNAME
|
65
|
-
hp = getipnodebyname(host_name, AF_INET, AI_DEFAULT, &err);
|
66
|
-
#else
|
67
|
-
hp = gethostbyname(host_name);
|
68
|
-
#endif
|
69
|
-
|
70
|
-
if(hp == NULL)
|
71
|
-
rb_raise(cHostError, "getipnodebyname() call failed");
|
72
|
-
|
73
|
-
pptr = hp->h_addr_list;
|
74
|
-
|
75
|
-
#ifdef HAVE_INET_NTOP
|
76
|
-
for( ; *pptr != NULL; pptr++){
|
77
|
-
rb_ary_push(v_results,
|
78
|
-
rb_str_new2(inet_ntop(hp->h_addrtype, *pptr, str, INET_ADDRSTRLEN)));
|
79
|
-
}
|
80
|
-
#else
|
81
|
-
for(n = 0; hp->h_addr_list[n] != NULL; n++){
|
82
|
-
memcpy(&ipa.s_addr, hp->h_addr_list[n], hp->h_length);
|
83
|
-
rb_ary_push(v_results, rb_str_new2(inet_ntoa(ipa)));
|
84
|
-
}
|
85
|
-
#endif
|
86
|
-
return v_results;
|
87
|
-
}
|
88
|
-
|
89
|
-
/* :call-seq:
|
90
|
-
* Sys::Host.info
|
91
|
-
* Sys::Host.info{ |i| ... }
|
92
|
-
*
|
93
|
-
* Yields a HostInfo struct containing various bits of information about
|
94
|
-
* the local machine for each entry in the hosts table. In non-block form,
|
95
|
-
* returns an array of HostInfo structs.
|
96
|
-
*
|
97
|
-
* The Struct::HostInfo struct contains 5 fields:
|
98
|
-
*
|
99
|
-
* * name (String)
|
100
|
-
* * aliases (Array)
|
101
|
-
* * addr_type (Integer)
|
102
|
-
* * length (Integer)
|
103
|
-
* * addr_list (Array)
|
104
|
-
*/
|
105
|
-
static VALUE host_info(VALUE klass){
|
106
|
-
VALUE v_hostinfo = Qnil;
|
107
|
-
VALUE v_addr = rb_ary_new();
|
108
|
-
VALUE v_array = rb_ary_new();
|
109
|
-
VALUE v_aliases = rb_ary_new();
|
110
|
-
|
111
|
-
sethostent(0);
|
112
|
-
|
113
|
-
#ifdef HAVE_GETHOSTENT_R
|
114
|
-
struct hostent host;
|
115
|
-
struct hostent* result;
|
116
|
-
char buf[HOSTENT_BUF];
|
117
|
-
int err;
|
118
|
-
|
119
|
-
while(!gethostent_r(&host, buf, HOSTENT_BUF, &result, &err)){
|
120
|
-
while(*result->h_aliases){
|
121
|
-
rb_ary_push(v_aliases, rb_str_new2(*result->h_aliases));
|
122
|
-
*result->h_aliases++;
|
123
|
-
}
|
124
|
-
|
125
|
-
#ifdef __MACH__ or #ifdef __APPLE__
|
126
|
-
char **addrs = host->h_addr_list;
|
127
|
-
while(*addrs){
|
128
|
-
inet_ntop(result->h_addrtype, addrs, buf, HOSTENT_BUF);
|
129
|
-
rb_ary_push(v_addr, rb_str_new2(buf));
|
130
|
-
addrs++;
|
131
|
-
}
|
132
|
-
#else
|
133
|
-
while(*result->h_addr_list){
|
134
|
-
inet_ntop(result->h_addrtype, *result->h_addr_list, buf, HOSTENT_BUF);
|
135
|
-
rb_ary_push(v_addr, rb_str_new2(buf));
|
136
|
-
*result->h_addr_list++;
|
137
|
-
}
|
138
|
-
#endif
|
139
|
-
|
140
|
-
/* We need to dup the arrays because Ruby is holding onto the same
|
141
|
-
* reference.
|
142
|
-
*/
|
143
|
-
v_hostinfo = rb_struct_new(sHostInfo,
|
144
|
-
rb_str_new2(result->h_name),
|
145
|
-
rb_ary_dup(v_aliases),
|
146
|
-
INT2FIX(result->h_addrtype),
|
147
|
-
INT2FIX(result->h_length),
|
148
|
-
rb_ary_dup(v_addr)
|
149
|
-
);
|
150
|
-
#else
|
151
|
-
struct hostent* host;
|
152
|
-
char buf[INET_ADDRSTRLEN];
|
153
|
-
|
154
|
-
while((host = gethostent())){
|
155
|
-
while(*host->h_aliases){
|
156
|
-
rb_ary_push(v_aliases, rb_str_new2(*host->h_aliases));
|
157
|
-
*host->h_aliases++;
|
158
|
-
}
|
159
|
-
|
160
|
-
#ifdef __MACH__ or #ifdef __APPLE__
|
161
|
-
char **addrs = host->h_addr_list;
|
162
|
-
while(*addrs){
|
163
|
-
inet_ntop(host->h_addrtype, addrs, buf, HOSTENT_BUF);
|
164
|
-
rb_ary_push(v_addr, rb_str_new2(buf));
|
165
|
-
addrs++;
|
166
|
-
}
|
167
|
-
#else
|
168
|
-
while(*host->h_addr_list){
|
169
|
-
inet_ntop(host->h_addrtype, *host->h_addr_list, buf, HOSTENT_BUF);
|
170
|
-
rb_ary_push(v_addr, rb_str_new2(buf));
|
171
|
-
*host->h_addr_list++;
|
172
|
-
}
|
173
|
-
#endif
|
174
|
-
|
175
|
-
v_hostinfo = rb_struct_new(sHostInfo,
|
176
|
-
rb_str_new2(host->h_name),
|
177
|
-
rb_ary_dup(v_aliases),
|
178
|
-
INT2FIX(host->h_addrtype),
|
179
|
-
INT2FIX(host->h_length),
|
180
|
-
rb_ary_dup(v_addr)
|
181
|
-
);
|
182
|
-
#endif
|
183
|
-
|
184
|
-
if(rb_block_given_p())
|
185
|
-
rb_yield(v_hostinfo);
|
186
|
-
else
|
187
|
-
rb_ary_push(v_array, v_hostinfo);
|
188
|
-
|
189
|
-
rb_ary_clear(v_aliases);
|
190
|
-
rb_ary_clear(v_addr);
|
191
|
-
}
|
192
|
-
|
193
|
-
endhostent();
|
194
|
-
|
195
|
-
if(rb_block_given_p())
|
196
|
-
return Qnil;
|
197
|
-
|
198
|
-
return v_array;
|
199
|
-
}
|
200
|
-
|
201
|
-
#ifdef HAVE_GETHOSTID
|
202
|
-
/*
|
203
|
-
* Sys::Host.host_id
|
204
|
-
*
|
205
|
-
* Returns the host id of the current machine.
|
206
|
-
*/
|
207
|
-
static VALUE host_host_id(){
|
208
|
-
return ULL2NUM(gethostid());
|
209
|
-
}
|
210
|
-
#endif
|
211
|
-
|
212
|
-
void Init_host()
|
213
|
-
{
|
214
|
-
VALUE sys_mSys, cHost;
|
215
|
-
|
216
|
-
/* The Sys module serves as a toplevel namespace, nothing more. */
|
217
|
-
sys_mSys = rb_define_module("Sys");
|
218
|
-
|
219
|
-
/* The Host class encapsulates information about your machine, such as
|
220
|
-
* the host name and IP address.
|
221
|
-
*/
|
222
|
-
cHost = rb_define_class_under(sys_mSys, "Host", rb_cObject);
|
223
|
-
|
224
|
-
/* This error is raised if any of the Host methods fail. */
|
225
|
-
cHostError = rb_define_class_under(cHost, "Error", rb_eStandardError);
|
226
|
-
|
227
|
-
/* 0.6.1: The version of this library. This is a string, not a number. */
|
228
|
-
rb_define_const(cHost, "VERSION", rb_str_new2(SYS_HOST_VERSION));
|
229
|
-
|
230
|
-
/* Structs */
|
231
|
-
sHostInfo = rb_struct_define("HostInfo", "name", "aliases", "addr_type",
|
232
|
-
"length", "addr_list", NULL
|
233
|
-
);
|
234
|
-
|
235
|
-
/* Class Methods */
|
236
|
-
rb_define_singleton_method(cHost, "hostname", host_hostname, 0);
|
237
|
-
rb_define_singleton_method(cHost, "ip_addr", host_ip_addr, 0);
|
238
|
-
rb_define_singleton_method(cHost, "info", host_info, 0);
|
239
|
-
|
240
|
-
#ifdef HAVE_GETHOSTID
|
241
|
-
rb_define_singleton_method(cHost, "host_id", host_host_id, 0);
|
242
|
-
#endif
|
243
|
-
}
|
244
|
-
|
245
|
-
#ifdef __cplusplus
|
246
|
-
}
|
247
|
-
#endif
|