Inheritance: NameServicePacket
コード例 #1
0
        /// <exception cref="UnknownHostException"></exception>
        internal virtual NbtAddress[] GetAllByName(Name name, IPAddress addr)
        {
            //Log.Out("NameSerciceClient.GetAllByName");

            int n;
            NameQueryRequest  request  = new NameQueryRequest(name);
            NameQueryResponse response = new NameQueryResponse();

            request.Addr        = addr ?? NbtAddress.GetWinsAddress();
            request.IsBroadcast = (request.Addr == null ||
                                   request.Addr.ToString() == Baddr.ToString());

            if (request.IsBroadcast)
            {
                request.Addr = Baddr;
                n            = RetryCount;
            }
            else
            {
                request.IsBroadcast = false;
                n = 1;
            }
            do
            {
                try
                {
                    Send(request, response, RetryTimeout);
                }
                catch (IOException ioe)
                {
                    if (_log.Level > 1)
                    {
                        Runtime.PrintStackTrace(ioe, _log);
                    }
                    throw new UnknownHostException(ioe);
                }
                if (response.Received && response.ResultCode == 0)
                {
                    return(response.AddrEntry);
                }
            }while (--n > 0 && request.IsBroadcast);
            throw new UnknownHostException();
        }
コード例 #2
0
        /// <exception cref="UnknownHostException"></exception>
        internal virtual NbtAddress GetByName(Name name, IPAddress addr)
        {
            int n;

            NameQueryRequest request = new NameQueryRequest(name);
            NameQueryResponse response = new NameQueryResponse();
            if (addr != null)
            {
                request.Addr = addr;
                request.IsBroadcast = (addr.GetAddressBytes()[3] == unchecked(unchecked(0xFF)));
                n = RetryCount;
                do
                {
                    try
                    {
                        Send(request, response, RetryTimeout);
                    }
                    catch (IOException ioe)
                    {
                        if (_log.Level > 1)
                        {
                            Runtime.PrintStackTrace(ioe, _log);
                        }
                        throw new UnknownHostException(ioe);
                    }
                    if (response.Received && response.ResultCode == 0
                        && response.IsResponse)
                    {
                        int last = response.AddrEntry.Length - 1;
                        response.AddrEntry[last].HostName.SrcHashCode = addr.GetHashCode();
                        return response.AddrEntry[last];
                    }
                }
                while (--n > 0 && request.IsBroadcast);
                throw new UnknownHostException();
            }
            for (int i = 0; i < _resolveOrder.Length; i++)
            {
                try
                {
                    switch (_resolveOrder[i])
                    {
                        case ResolverLmhosts:
                            {
                                NbtAddress ans = Lmhosts.GetByName(name);
                                if (ans != null)
                                {
                                    ans.HostName.SrcHashCode = 0;
                                    // just has to be different
                                    // from other methods
                                    return ans;
                                }
                                break;
                            }

                        case ResolverWins:
                        case ResolverBcast:
                            {
                                if (_resolveOrder[i] == ResolverWins && name.name != NbtAddress.MasterBrowserName
                                     && name.HexCode != unchecked(0x1d))
                                {
                                    request.Addr = NbtAddress.GetWinsAddress();
                                    request.IsBroadcast = false;
                                }
                                else
                                {
                                    request.Addr = Baddr;
                                    request.IsBroadcast = true;
                                }
                                n = RetryCount;
                                while (n-- > 0)
                                {
                                    try
                                    {
                                        Send(request, response, RetryTimeout);
                                    }
                                    catch (IOException ioe)
                                    {
                                        if (_log.Level > 1)
                                        {
                                            Runtime.PrintStackTrace(ioe, _log);
                                        }
                                        throw new UnknownHostException(ioe);
                                    }
                                    if (response.Received && response.ResultCode == 0
                                        && response.IsResponse)
                                    {

                                        response.AddrEntry[0].HostName.SrcHashCode = request.Addr.GetHashCode();
                                        return response.AddrEntry[0];
                                    }
                                    if (_resolveOrder[i] == ResolverWins)
                                    {
                                        break;
                                    }
                                }
                                break;
                            }
                    }
                }
                catch (IOException)
                {
                }
            }
            throw new UnknownHostException();
        }
コード例 #3
0
 /// <exception cref="UnknownHostException"></exception>
 internal virtual NbtAddress[] GetAllByName(Name name, IPAddress addr)
 {
     int n;
     NameQueryRequest request = new NameQueryRequest(name);
     NameQueryResponse response = new NameQueryResponse();
     request.Addr = addr ?? NbtAddress.GetWinsAddress();
     request.IsBroadcast = request.Addr == null;
     if (request.IsBroadcast)
     {
         request.Addr = Baddr;
         n = RetryCount;
     }
     else
     {
         request.IsBroadcast = false;
         n = 1;
     }
     do
     {
         try
         {
             Send(request, response, RetryTimeout);
         }
         catch (IOException ioe)
         {
             if (_log.Level > 1)
             {
                 Runtime.PrintStackTrace(ioe, _log);
             }
             throw new UnknownHostException(ioe);
         }
         if (response.Received && response.ResultCode == 0)
         {
             return response.AddrEntry;
         }
     }
     while (--n > 0 && request.IsBroadcast);
     throw new UnknownHostException();
 }
コード例 #4
0
        /// <exception cref="UnknownHostException"></exception>
        internal virtual NbtAddress GetByName(Name name, IPAddress addr)
        {
            int n;

            NameQueryRequest  request  = new NameQueryRequest(name);
            NameQueryResponse response = new NameQueryResponse();

            if (addr != null)
            {
                request.Addr        = addr;
                request.IsBroadcast = (addr.GetAddressBytes()[3] == unchecked (unchecked (0xFF)));
                n = RetryCount;
                do
                {
                    try
                    {
                        Send(request, response, RetryTimeout);
                    }
                    catch (IOException ioe)
                    {
                        if (_log.Level > 1)
                        {
                            Runtime.PrintStackTrace(ioe, _log);
                        }
                        throw new UnknownHostException(ioe);
                    }
                    if (response.Received && response.ResultCode == 0 &&
                        response.IsResponse)
                    {
                        int last = response.AddrEntry.Length - 1;
                        response.AddrEntry[last].HostName.SrcHashCode = addr.GetHashCode();
                        return(response.AddrEntry[last]);
                    }
                }while (--n > 0 && request.IsBroadcast);
                throw new UnknownHostException();
            }
            for (int i = 0; i < _resolveOrder.Length; i++)
            {
                try
                {
                    switch (_resolveOrder[i])
                    {
                    case ResolverLmhosts:
                    {
                        NbtAddress ans = Lmhosts.GetByName(name);
                        if (ans != null)
                        {
                            ans.HostName.SrcHashCode = 0;
                            // just has to be different
                            // from other methods
                            return(ans);
                        }
                        break;
                    }

                    case ResolverWins:
                    case ResolverBcast:
                    {
                        if (_resolveOrder[i] == ResolverWins && name.name != NbtAddress.MasterBrowserName &&
                            name.HexCode != unchecked (0x1d))
                        {
                            request.Addr        = NbtAddress.GetWinsAddress();
                            request.IsBroadcast = false;
                        }
                        else
                        {
                            request.Addr        = Baddr;
                            request.IsBroadcast = true;
                        }
                        n = RetryCount;
                        while (n-- > 0)
                        {
                            try
                            {
                                Send(request, response, RetryTimeout);
                            }
                            catch (IOException ioe)
                            {
                                if (_log.Level > 1)
                                {
                                    Runtime.PrintStackTrace(ioe, _log);
                                }
                                throw new UnknownHostException(ioe);
                            }
                            if (response.Received && response.ResultCode == 0 &&
                                response.IsResponse)
                            {
                                response.AddrEntry[0].HostName.SrcHashCode = request.Addr.GetHashCode();
                                return(response.AddrEntry[0]);
                            }
                            if (_resolveOrder[i] == ResolverWins)
                            {
                                break;
                            }
                        }
                        break;
                    }
                    }
                }
                catch (IOException)
                {
                }
            }
            throw new UnknownHostException();
        }