diff options
author | Federico Lucifredi <flucifredi@acm.org> | 2007-05-06 20:12:18 +0000 |
---|---|---|
committer | Federico Lucifredi <flucifredi@acm.org> | 2007-05-06 20:12:18 +0000 |
commit | 8a49fc26776c8b95ce299e69903198df7bbebe11 (patch) | |
tree | f16ed29141aff95792cf73e3c636efcd534bf2bd /trunk/avahi-sharp/Utility.cs | |
parent | 1fef746edf313d8fb1d8417a17d536a915ca69cd (diff) | |
parent | a6a4c936ad8c9071b891bb19c4edf5779e027a19 (diff) |
refreshing branch to latest release.
git-svn-id: file:///home/lennart/svn/public/avahi/branches/federico@1455 941a03a8-eaeb-0310-b9a0-b1bbd8fe43fe
Diffstat (limited to 'trunk/avahi-sharp/Utility.cs')
-rw-r--r-- | trunk/avahi-sharp/Utility.cs | 114 |
1 files changed, 0 insertions, 114 deletions
diff --git a/trunk/avahi-sharp/Utility.cs b/trunk/avahi-sharp/Utility.cs deleted file mode 100644 index 9081b01..0000000 --- a/trunk/avahi-sharp/Utility.cs +++ /dev/null @@ -1,114 +0,0 @@ -/* $Id$ */ - -/*** - This file is part of avahi. - - avahi is free software; you can redistribute it and/or modify it - under the terms of the GNU Lesser General Public License as - published by the Free Software Foundation; either version 2.1 of the - License, or (at your option) any later version. - - avahi is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY - or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General - Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with avahi; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - USA. -***/ - -using System; -using System.Net; -using System.Text; -using System.Runtime.InteropServices; -using Mono.Unix; -using Mono.Unix.Native; - -using Stdlib = Mono.Unix.Native.Stdlib; - -namespace Avahi -{ - internal class Utility - { - [DllImport ("libc")] - private static extern int strlen (IntPtr ptr); - - [DllImport ("avahi-common")] - private static extern IntPtr avahi_address_snprint (IntPtr buf, int size, IntPtr address); - - [DllImport ("avahi-common")] - private static extern IntPtr avahi_address_parse (IntPtr str, Protocol proto, IntPtr ret); - - public static string PtrToString (IntPtr ptr) - { - if (ptr == IntPtr.Zero) - return null; - - int len = strlen (ptr); - byte[] bytes = new byte[len]; - Marshal.Copy (ptr, bytes, 0, len); - return Encoding.UTF8.GetString (bytes); - } - - public static string PtrToStringFree (IntPtr ptr) - { - if (ptr == IntPtr.Zero) - return null; - - string ret = PtrToString (ptr); - Free (ptr); - return ret; - } - - public static byte[] StringToBytes (string str) - { - if (str == null) - return null; - - return Encoding.UTF8.GetBytes (str + "\0"); // lame. - } - - private static IntPtr StringToPtr (string str) - { - if (str == null) - return IntPtr.Zero; - - byte[] bytes = Utility.StringToBytes (str); - IntPtr buf = Stdlib.malloc ((uint) bytes.Length + 1); - Marshal.Copy (bytes, 0, buf, bytes.Length); - Marshal.WriteByte (buf, bytes.Length, 0); - return buf; - } - - public static void Free (IntPtr ptr) - { - Stdlib.free (ptr); - } - - public static IntPtr AddressToPtr (IPAddress address) - { - IntPtr straddr = Utility.StringToPtr (address.ToString ()); - IntPtr addrPtr = Stdlib.malloc (32); - avahi_address_parse (straddr, Protocol.Unspecified, addrPtr); - Utility.Free (straddr); - - return addrPtr; - } - - public static IPAddress PtrToAddress (IntPtr ptr) - { - IPAddress address = null; - - if (ptr != IntPtr.Zero) { - IntPtr buf = Stdlib.malloc (256); - IntPtr addrPtr = avahi_address_snprint (buf, 256, ptr); - address = IPAddress.Parse (Utility.PtrToString (addrPtr)); - Utility.Free (addrPtr); - } - - return address; - } - } -} |