]> git.meshlink.io Git - catta/blobdiff - avahi-sharp/ServiceResolver.cs
avahi-discover crashes if row is unselected
[catta] / avahi-sharp / ServiceResolver.cs
index 7527652d6ac485f20346dbeb710331354ca3151c..a32efca8b795186bf19dd429e7dcc97944823680 100644 (file)
@@ -23,6 +23,7 @@ using System;
 using System.Collections;
 using System.Net;
 using System.Runtime.InteropServices;
+using System.Text;
 using Mono.Unix;
 
 namespace Avahi
@@ -53,7 +54,7 @@ namespace Avahi
         
         [DllImport ("avahi-client")]
         private static extern IntPtr avahi_service_resolver_new (IntPtr client, int iface, Protocol proto,
-                                                                 IntPtr name, IntPtr type, IntPtr domain,
+                                                                 byte[] name, byte[] type, byte[] domain,
                                                                  Protocol aproto, LookupFlags flags,
                                                                  ServiceResolverCallback cb,
                                                                  IntPtr userdata);
@@ -145,18 +146,14 @@ namespace Avahi
                 (foundListeners.Count == 0 && timeoutListeners.Count == 0))
                 return;
 
-            IntPtr namePtr = Utility.StringToPtr (name);
-            IntPtr typePtr = Utility.StringToPtr (type);
-            IntPtr domainPtr = Utility.StringToPtr (domain);
-
             lock (client) {
-                handle = avahi_service_resolver_new (client.Handle, iface, proto, namePtr, typePtr, domainPtr,
-                                                     aproto, flags, cb, IntPtr.Zero);
+                handle = avahi_service_resolver_new (client.Handle, iface, proto,
+                                                     Utility.StringToBytes (name), Utility.StringToBytes (type),
+                                                     Utility.StringToBytes (domain), aproto, flags, cb, IntPtr.Zero);
+
+                if (handle == IntPtr.Zero)
+                    client.ThrowError ();
             }
-            
-            Utility.Free (namePtr);
-            Utility.Free (typePtr);
-            Utility.Free (domainPtr);
         }
 
         private void Stop (bool force)
@@ -187,6 +184,9 @@ namespace Avahi
             info.Address = Utility.PtrToAddress (address);
             info.Port = port;
 
+            if (proto == Protocol.IPv6)
+              info.Address.ScopeId = iface;
+
             ArrayList txtlist = new ArrayList ();
             for (IntPtr l = txt; l != IntPtr.Zero; l = avahi_string_list_get_next (l)) {
                 IntPtr buf = avahi_string_list_get_text (l);
@@ -205,16 +205,10 @@ namespace Avahi
                 currentInfo = info;
 
                 foreach (ServiceInfoHandler handler in foundListeners)
-                    handler (this, info);
-                break;
-            case ResolverEvent.Timeout:
-                currentInfo = ServiceInfo.Zero;
-                
-                foreach (EventHandler handler in timeoutListeners)
-                    handler (this, new EventArgs ());
+                    handler (this, new ServiceInfoArgs (info));
                 break;
-            default:
-                EmitResolverEvent (revent);
+            case ResolverEvent.Failure:
+                EmitFailure (client.LastError);
                 break;
             }
         }