From 47a544ec5a660c2aa6964713ead0312982814cbb Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 17 Sep 2004 21:05:59 +0000 Subject: [PATCH] convert netaddr to string --- bindings/dotnet/src/Sigar.cs | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/bindings/dotnet/src/Sigar.cs b/bindings/dotnet/src/Sigar.cs index 3005130d..c5fbaf79 100644 --- a/bindings/dotnet/src/Sigar.cs +++ b/bindings/dotnet/src/Sigar.cs @@ -2,6 +2,7 @@ using System; using System.IO; using System.Collections; using System.Runtime.InteropServices; +using System.Text; namespace Hyperic.Sigar { public class Sigar { @@ -395,5 +396,41 @@ namespace Hyperic.Sigar { return ifconfig; } + + [DllImport(Sigar.LIBSIGAR)] + private static extern int + sigar_inet_ntoa(IntPtr sigar, ulong address, + StringBuilder addr_str); + + private string inet_ntoa(ulong address) { + StringBuilder buffer = new StringBuilder(); + buffer.Capacity = (3 * 4 + 3 + 1); + sigar_inet_ntoa(IntPtr.Zero, address, buffer); + return buffer.ToString(); + } + + public string Address { + get { + return inet_ntoa(this.address); + } + } + + public string Destination { + get { + return inet_ntoa(this.destination); + } + } + + public string Broadcast { + get { + return inet_ntoa(this.broadcast); + } + } + + public string Netmask { + get { + return inet_ntoa(this.netmask); + } + } } }