From 49bc336919092e279b7f29e33f850004262a834b Mon Sep 17 00:00:00 2001 From: Matthew Kent Date: Sun, 23 Aug 2009 23:24:50 -0700 Subject: [PATCH 1/2] (SIGAR-180) Expose sigar_fqdn_get in the ruby binding. --- bindings/ruby/rbsigar.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bindings/ruby/rbsigar.c b/bindings/ruby/rbsigar.c index 526125a9..0d8968cd 100644 --- a/bindings/ruby/rbsigar.c +++ b/bindings/ruby/rbsigar.c @@ -657,6 +657,19 @@ static VALUE rb_sigar_set_log_level(VALUE obj, VALUE level) return obj; } +static VALUE rb_sigar_fqdn(VALUE obj) +{ + SIGAR_GET; + + char fqdn[SIGAR_FQDN_LEN]; + int status; + + if ((status = sigar_fqdn_get(sigar, fqdn, sizeof(fqdn))) != SIGAR_OK) { + RB_SIGAR_CROAK; + } + + return rb_str_new2(fqdn); +} #include "./rbsigar_generated.rx" @@ -752,6 +765,7 @@ void Init_rbsigar(void) rb_define_method(rclass, "proc_list", rb_sigar_proc_list, -1); rb_define_method(rclass, "proc_args", rb_sigar_proc_args, 1); rb_define_method(rclass, "proc_env", rb_sigar_proc_env, 1); + rb_define_method(rclass, "fqdn", rb_sigar_fqdn, 0); rb_define_singleton_method(rclass, "new", rb_sigar_new, 0); rb_define_singleton_method(rclass, "format_size", rb_sigar_format_size, 1); From abda75748b87a2557d8e43e68306605a9022b9bf Mon Sep 17 00:00:00 2001 From: Matthew Kent Date: Sun, 23 Aug 2009 23:26:55 -0700 Subject: [PATCH 2/2] Add an example of net_info usage. --- bindings/ruby/examples/net_info.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 bindings/ruby/examples/net_info.rb diff --git a/bindings/ruby/examples/net_info.rb b/bindings/ruby/examples/net_info.rb new file mode 100644 index 00000000..22ca59c5 --- /dev/null +++ b/bindings/ruby/examples/net_info.rb @@ -0,0 +1,15 @@ +# Example illustrating the collecting of network information. + +require 'rbsigar' + +sigar = Sigar.new + +ninfo = sigar.net_info + +puts "Hostname: " + ninfo.host_name +puts "Domain Name: " + ninfo.domain_name +puts "FQDN: " + sigar.fqdn +puts "Default gateway: " + ninfo.default_gateway +puts "Default gateway interface: " + ninfo.default_gateway_interface +puts "Primary DNS: " + ninfo.primary_dns +puts "Secondary DNS: " + ninfo.secondary_dns