コード例 #1
0
        private static void QueryPtrCallback(IntPtr h, DnsServiceFlags flags, int ifIndex, DnsServiceErrorType errorCode, string fullName, DnsServiceType rrType, DnsServiceClass rrClass, ushort dataLen, byte[] data, uint ttl, IntPtr context)
        {
            Dictionary <string, BonjourDevice> deviceList;

            lock (lookups)
                if (!lookups.TryGetValue(context, out deviceList))
                {
                    return;
                }

            BonjourDevice device;

            lock (deviceList)
                if (!deviceList.TryGetValue(fullName, out device))
                {
                    return;
                }

            if (errorCode != DnsServiceErrorType.NoError)
            {
                device.Error = errorCode;
                return;
            }

            device.Host.Address = new IPAddress(data);
            device.IsComplete   = true;
        }
コード例 #2
0
        private void RegisterCallback(IntPtr handle, DnsServiceFlags flags, DnsServiceErrorType errorCode, string name, string regType, string domain, IntPtr context)
        {
            Console.WriteLine("Register result: " + errorCode);

            if (errorCode == DnsServiceErrorType.NoError)
            {
                string key = name.Trim('.') + "." + regType.Trim('.') + "." + domain.Trim('.');

                lock (m_handles)
                    m_handles[key] = handle;
            }
        }
コード例 #3
0
        private void BrowseCallback(IntPtr h, DnsServiceFlags flags, int ifIndex, DnsServiceErrorType errorCode, string serviceName, string regType, string domain, IntPtr context)
        {
            errorCode.ThrowException("BrowseCallback");

            Dictionary <string, BonjourDevice> deviceList;

            lock (lookups)
                if (!lookups.TryGetValue(h, out deviceList))
                {
                    return;
                }

            var device = new BonjourDevice {
                DeviceId = serviceName, IsComplete = false, Error = DnsServiceErrorType.NoError
            };

            lock (deviceList)
                deviceList[serviceName] = device;

            IntPtr handle;
            var    r = Interop.DNSServiceResolve(out handle, DnsServiceFlags.Default | DnsServiceFlags.ForceMulticast, ifIndex, serviceName, regType, domain, resolveCallback, h);

            if (r != DnsServiceErrorType.NoError)
            {
                device.Error = r;
                return;
            }

            lock (deviceList)
                deviceList["0x" + handle.ToString("X")] = device;

            try
            {
                if (!Interop.DNSServiceHasData(handle, TimeSpan.FromSeconds(5)))
                {
                    return;
                }

                r = Interop.DNSServiceProcessResult(handle);

                if (r != DnsServiceErrorType.NoError)
                {
                    device.Error = r;
                    return;
                }
            }
            finally
            {
                lock (deviceList)
                    deviceList.Remove("0x" + handle.ToString("X"));
                Interop.DNSServiceRefDeallocate(handle);
            }
        }
コード例 #4
0
ファイル: BonjourService.cs プロジェクト: liurnd/TouchRemote
        private void RegisterCallback(IntPtr handle, DnsServiceFlags flags, DnsServiceErrorType errorCode, string name, string regType, string domain, IntPtr context)
        {
            Console.WriteLine("Register result: " + errorCode);

            if (errorCode == DnsServiceErrorType.NoError)
            {
                string key = name.Trim('.') + "." + regType.Trim('.') + "." + domain.Trim('.');

                lock (m_handles)
                    m_handles[key] = handle;
            }
        }
コード例 #5
0
        private void BrowseCallback(IntPtr h, DnsServiceFlags flags, int ifIndex, DnsServiceErrorType errorCode, string serviceName, string regType, string domain, IntPtr context)
        {
            errorCode.ThrowException("BrowseCallback");

            Dictionary<string, BonjourDevice> deviceList;
            lock (lookups)
                if (!lookups.TryGetValue(h, out deviceList)) return;

            var device = new BonjourDevice { DeviceId = serviceName, IsComplete = false, Error = DnsServiceErrorType.NoError };

            lock (deviceList)
                deviceList[serviceName] = device;

            IntPtr handle;
            var r = Interop.DNSServiceResolve(out handle, DnsServiceFlags.Default | DnsServiceFlags.ForceMulticast, ifIndex, serviceName, regType, domain, resolveCallback, h);

            if (r != DnsServiceErrorType.NoError)
            {
                device.Error = r;
                return;
            }

            lock (deviceList)
                deviceList["0x" + handle.ToString("X")] = device;

            try
            {
                if (!Interop.DNSServiceHasData(handle, TimeSpan.FromSeconds(5))) return;

                r = Interop.DNSServiceProcessResult(handle);

                if (r != DnsServiceErrorType.NoError)
                {
                    device.Error = r;
                    return;
                }
            }
            finally
            {
                lock (deviceList)
                    deviceList.Remove("0x" + handle.ToString("X"));
                Interop.DNSServiceRefDeallocate(handle);
            }
        }
コード例 #6
0
        private static void QueryPtrCallback(IntPtr h, DnsServiceFlags flags, int ifIndex, DnsServiceErrorType errorCode, string fullName, DnsServiceType rrType, DnsServiceClass rrClass, ushort dataLen, byte[] data, uint ttl, IntPtr context)
        {
            Dictionary<string, BonjourDevice> deviceList;
            lock (lookups)
                if (!lookups.TryGetValue(context, out deviceList)) return;

            BonjourDevice device;
            lock (deviceList)
                if (!deviceList.TryGetValue(fullName, out device)) return;

            if (errorCode != DnsServiceErrorType.NoError)
            {
                device.Error = errorCode;
                return;
            }

            device.Host.Address = new IPAddress(data);
            device.IsComplete = true;
        }
コード例 #7
0
ファイル: Interop.cs プロジェクト: liurnd/TouchRemote
 public static extern DnsServiceErrorType DNSServiceRegister(
     out IntPtr handle, DnsServiceFlags flags,
     int ifIndex, string name, string regType, string domain,
     string host, ushort port,
     ushort txtLen, [MarshalAs(UnmanagedType.LPArray)] byte[] txtRecord,
     DnsServiceRegisterReply callback, IntPtr context);
コード例 #8
0
ファイル: Interop.cs プロジェクト: liurnd/TouchRemote
 public static extern DnsServiceErrorType DNSServiceQueryRecord(
     out IntPtr handle, DnsServiceFlags flags, int ifIndex, string fullName,
     [MarshalAs(UnmanagedType.U2)] DnsServiceType rrType, [MarshalAs(UnmanagedType.U2)] DnsServiceClass rrClass,
     DnsServiceQueryRecordReply callback, IntPtr context);
コード例 #9
0
ファイル: Interop.cs プロジェクト: liurnd/TouchRemote
 public static extern DnsServiceErrorType DNSServiceBrowse(
     out IntPtr handle, DnsServiceFlags flags,
     int ifIndex, string regType, string domain,
     DNSServiceBrowseReply callback, IntPtr context);
コード例 #10
0
        private void ResolveCallback(IntPtr h, DnsServiceFlags flags, int ifIndex, DnsServiceErrorType errorCode, string fullName, string hostTarget, ushort port, ushort txtLen, byte[] txtRecord, IntPtr context)
        {
            Dictionary<string, BonjourDevice> deviceList;
            lock (lookups)
                if (!lookups.TryGetValue(context, out deviceList)) return;

            BonjourDevice device;
            lock (deviceList)
                if (!deviceList.TryGetValue("0x" + h.ToString("X"), out device)) return;

            if (errorCode != DnsServiceErrorType.NoError)
            {
                device.Error = errorCode;
                return;
            }

            var hostPort = (ushort)IPAddress.NetworkToHostOrder((short)port);

            device.Host = new System.Net.IPEndPoint(0, hostPort);

            var txt = txtRecord.FromArray();

            device.Name = txt["DvNm"];
            device.PairCode = txt["Pair"];

            IntPtr handle;
            var r = Interop.DNSServiceQueryRecord(out handle, DnsServiceFlags.Default | DnsServiceFlags.ForceMulticast, ifIndex, hostTarget, DnsServiceType.A, DnsServiceClass.IN, queryPtrCallback, context);

            if (r != DnsServiceErrorType.NoError)
            {
                device.Error = errorCode;
                return;
            }

            lock (deviceList)
                deviceList[hostTarget] = device;

            try
            {
                if (!Interop.DNSServiceHasData(handle, TimeSpan.FromSeconds(5))) return;

                r = Interop.DNSServiceProcessResult(handle);

                if (r != DnsServiceErrorType.NoError)
                {
                    device.Error = r;
                }
            }
            finally
            {
                Interop.DNSServiceRefDeallocate(handle);
                lock (deviceList)
                    deviceList.Remove(hostTarget);
            }
        }
コード例 #11
0
        private void ResolveCallback(IntPtr h, DnsServiceFlags flags, int ifIndex, DnsServiceErrorType errorCode, string fullName, string hostTarget, ushort port, ushort txtLen, byte[] txtRecord, IntPtr context)
        {
            Dictionary <string, BonjourDevice> deviceList;

            lock (lookups)
                if (!lookups.TryGetValue(context, out deviceList))
                {
                    return;
                }

            BonjourDevice device;

            lock (deviceList)
                if (!deviceList.TryGetValue("0x" + h.ToString("X"), out device))
                {
                    return;
                }

            if (errorCode != DnsServiceErrorType.NoError)
            {
                device.Error = errorCode;
                return;
            }

            var hostPort = (ushort)IPAddress.NetworkToHostOrder((short)port);

            device.Host = new System.Net.IPEndPoint(0, hostPort);

            var txt = txtRecord.FromArray();

            device.Name     = txt["DvNm"];
            device.PairCode = txt["Pair"];

            IntPtr handle;
            var    r = Interop.DNSServiceQueryRecord(out handle, DnsServiceFlags.Default | DnsServiceFlags.ForceMulticast, ifIndex, hostTarget, DnsServiceType.A, DnsServiceClass.IN, queryPtrCallback, context);

            if (r != DnsServiceErrorType.NoError)
            {
                device.Error = errorCode;
                return;
            }

            lock (deviceList)
                deviceList[hostTarget] = device;

            try
            {
                if (!Interop.DNSServiceHasData(handle, TimeSpan.FromSeconds(5)))
                {
                    return;
                }

                r = Interop.DNSServiceProcessResult(handle);

                if (r != DnsServiceErrorType.NoError)
                {
                    device.Error = r;
                }
            }
            finally
            {
                Interop.DNSServiceRefDeallocate(handle);
                lock (deviceList)
                    deviceList.Remove(hostTarget);
            }
        }
コード例 #12
0
ファイル: Interop.cs プロジェクト: pieceofsummer/TouchRemote
 public static extern DnsServiceErrorType DNSServiceResolve(
     out IntPtr handle, DnsServiceFlags flags,
     int ifIndex, string name, string regType, string domain,
     DNSServiceResolveReply callback, IntPtr context);
コード例 #13
0
ファイル: Interop.cs プロジェクト: pieceofsummer/TouchRemote
 public static extern DnsServiceErrorType DNSServiceRegister(
     out IntPtr handle, DnsServiceFlags flags,
     int ifIndex, string name, string regType, string domain,
     string host, ushort port,
     ushort txtLen, [MarshalAs(UnmanagedType.LPArray)] byte[] txtRecord,
     DnsServiceRegisterReply callback, IntPtr context);
コード例 #14
0
ファイル: Interop.cs プロジェクト: pieceofsummer/TouchRemote
 public static extern DnsServiceErrorType DNSServiceQueryRecord(
     out IntPtr handle, DnsServiceFlags flags, int ifIndex, string fullName,
     [MarshalAs(UnmanagedType.U2)] DnsServiceType rrType, [MarshalAs(UnmanagedType.U2)] DnsServiceClass rrClass,
     DnsServiceQueryRecordReply callback, IntPtr context);