public static void SplitServiceName(string service, out string name, out string type, out string domain) { int len = 1024; IntPtr namePtr = Stdlib.malloc((ulong)len); IntPtr typePtr = Stdlib.malloc((ulong)len); IntPtr domainPtr = Stdlib.malloc((ulong)len); int ret = avahi_service_name_split(Utility.StringToBytes(service), namePtr, len, typePtr, len, domainPtr, len); if (ret < 0) { Utility.Free(namePtr); Utility.Free(typePtr); Utility.Free(domainPtr); name = null; type = null; domain = null; return; } name = Utility.PtrToString(namePtr); type = Utility.PtrToString(typePtr); domain = Utility.PtrToString(domainPtr); Utility.Free(namePtr); Utility.Free(typePtr); Utility.Free(domainPtr); }
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); }
public void AddAddress(int iface, Protocol proto, PublishFlags flags, string name, IPAddress address) { IntPtr addressPtr = Utility.AddressToPtr(address); lock (client) { int ret = avahi_entry_group_add_address(handle, iface, proto, flags, Utility.StringToBytes(name), addressPtr); Utility.Free(addressPtr); if (ret < 0) { client.ThrowError(); } } }
public static string JoinServiceName(string name, string type, string domain) { int len = 4 * (name.Length + type.Length + domain.Length) + 4; IntPtr buf = Stdlib.malloc((ulong)len); int ret = avahi_service_name_join(buf, len, Utility.StringToBytes(name), Utility.StringToBytes(type), Utility.StringToBytes(domain)); if (ret < 0) { Utility.Free(buf); return(null); // FIXME, should throw exception } string service = Utility.PtrToString(buf); Utility.Free(buf); return(service); }
private void Start() { if (client.Handle == IntPtr.Zero || handle != IntPtr.Zero || (foundListeners.Count == 0 && timeoutListeners.Count == 0)) { return; } IntPtr addrPtr = Utility.AddressToPtr(address); lock (client) { handle = avahi_address_resolver_new(client.Handle, iface, proto, addrPtr, flags, cb, IntPtr.Zero); if (handle == IntPtr.Zero) { client.ThrowError(); } } Utility.Free(addrPtr); }