+/* $Id$ */
+
/***
This file is part of avahi.
using System.Text;
using System.Runtime.InteropServices;
using Mono.Unix;
+using Mono.Unix.Native;
+using Stdlib = Mono.Unix.Native.Stdlib;
namespace Avahi
{
[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 ret;
}
- public static IntPtr StringToPtr (string str)
+ 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 = Encoding.UTF8.GetBytes (str);
+ 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);
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;