protected virtual void OnResolved() { ServiceResolvedEventHandler handler = Resolved; if (handler != null) { handler(this, new ServiceResolvedEventArgs(this)); } }
private void OnResolveReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex, ServiceError errorCode, IntPtr fullname, string hosttarget, ushort port, ushort txtLen, IntPtr txtRecord, IntPtr contex) { is_resolved = true; resolve_pending = false; InterfaceIndex = interfaceIndex; FullName = Native.Utf8toString(fullname); this.port = (ushort)IPAddress.NetworkToHostOrder((short)port); TxtRecord = new TxtRecord(txtLen, txtRecord); this.hosttarget = hosttarget; sdRef.Deallocate(); // Run an A query to resolve the IP address ServiceRef sd_ref; if (AddressProtocol == AddressProtocol.Any || AddressProtocol == AddressProtocol.IPv4) { ServiceError error = Native.DNSServiceQueryRecord(out sd_ref, ServiceFlags.None, interfaceIndex, hosttarget, ServiceType.A, ServiceClass.IN, query_record_reply_handler, IntPtr.Zero); if (error != ServiceError.NoError) { throw new ServiceErrorException(error); } sd_ref.Process(); } if (AddressProtocol == AddressProtocol.Any || AddressProtocol == AddressProtocol.IPv6) { ServiceError error = Native.DNSServiceQueryRecord(out sd_ref, ServiceFlags.None, interfaceIndex, hosttarget, ServiceType.AAAA, ServiceClass.IN, query_record_reply_handler, IntPtr.Zero); if (error != ServiceError.NoError) { throw new ServiceErrorException(error); } sd_ref.Process(); } if (hostentry.AddressList != null) { ServiceResolvedEventHandler handler = Resolved; if (handler != null) { handler(this, new ServiceResolvedEventArgs(this)); } } }
private void OnServiceResolved(object o, AV.ServiceInfoArgs args) { service = args.Service; ((AV.ServiceResolver)o).Dispose(); ServiceResolvedEventHandler handler = Resolved; if (handler != null) { handler(this, new ServiceResolvedEventArgs(this)); } }
private void OnQueryRecordReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex, ServiceError errorCode, string fullname, ServiceType rrtype, ServiceClass rrclass, ushort rdlen, IntPtr rdata, uint ttl, IntPtr context) { switch (rrtype) { case ServiceType.A: IPAddress address; if (rdlen == 4) { // ~4.5 times faster than Marshal.Copy into byte[4] uint address_raw = (uint)(Marshal.ReadByte(rdata, 3) << 24); address_raw |= (uint)(Marshal.ReadByte(rdata, 2) << 16); address_raw |= (uint)(Marshal.ReadByte(rdata, 1) << 8); address_raw |= (uint)Marshal.ReadByte(rdata, 0); address = new IPAddress(address_raw); } else if (rdlen == 16) { byte [] address_raw = new byte[rdlen]; Marshal.Copy(rdata, address_raw, 0, rdlen); address = new IPAddress(address_raw, interfaceIndex); } else { break; } if (hostentry == null) { hostentry = new IPHostEntry(); hostentry.HostName = hosttarget; } if (hostentry.AddressList != null) { ArrayList list = new ArrayList(hostentry.AddressList); list.Add(address); hostentry.AddressList = list.ToArray(typeof(IPAddress)) as IPAddress []; } else { hostentry.AddressList = new IPAddress [] { address }; } ServiceResolvedEventHandler handler = Resolved; if (handler != null) { handler(this, new ServiceResolvedEventArgs(this)); } break; case ServiceType.TXT: if (TxtRecord != null) { TxtRecord.Dispose(); } TxtRecord = new TxtRecord(rdlen, rdata); break; default: break; } sdRef.Deallocate(); }
private static void OnQueryRecordReply(ServiceRef sdRef, ServiceFlags flags, uint interfaceIndex, ServiceError errorCode, string fullname, ServiceType rrtype, ServiceClass rrclass, ushort rdlen, IntPtr rdata, uint ttl, IntPtr context) { var handle = GCHandle.FromIntPtr(context); var browseService = handle.Target as BrowseService; switch (rrtype) { case ServiceType.A: IPAddress address; if (rdlen == 4) { // ~4.5 times faster than Marshal.Copy into byte[4] uint address_raw = (uint)(Marshal.ReadByte(rdata, 3) << 24); address_raw |= (uint)(Marshal.ReadByte(rdata, 2) << 16); address_raw |= (uint)(Marshal.ReadByte(rdata, 1) << 8); address_raw |= (uint)Marshal.ReadByte(rdata, 0); address = new IPAddress(address_raw); } else if (rdlen == 16) { byte [] address_raw = new byte[rdlen]; Marshal.Copy(rdata, address_raw, 0, rdlen); address = new IPAddress(address_raw, interfaceIndex); } else { break; } if (browseService.hostentry == null) { browseService.hostentry = new IPHostEntry(); browseService.hostentry.HostName = browseService.hosttarget; } if (browseService.hostentry.AddressList != null) { ArrayList list = new ArrayList(browseService.hostentry.AddressList); list.Add(address); browseService.hostentry.AddressList = list.ToArray(typeof(IPAddress)) as IPAddress []; } else { browseService.hostentry.AddressList = new IPAddress [] { address }; } Log.To.Discovery.V(Tag, "Query record reply received for {0} (0x{1})", browseService, sdRef.Raw.ToString("X")); ServiceResolvedEventHandler handler = browseService._resolved; if (handler != null) { handler(browseService, new ServiceResolvedEventArgs(browseService)); } break; case ServiceType.TXT: if (browseService.TxtRecord != null) { browseService.TxtRecord.Dispose(); } browseService.TxtRecord = new TxtRecord(rdlen, rdata); break; default: break; } sdRef.Deallocate(); }