Resolve the IP address.
@throws NotConnectedException
@throws InterruptedException
554187
@Override
    public synchronized void resolve(JingleSession session) throws XMPPException, NotConnectedException, InterruptedException {
        if (!isResolving()) {
            setResolveInit();

            clearCandidates();

            if (fixedCandidate.getLocalIp() == null)
                fixedCandidate.setLocalIp(fixedCandidate.getIp());

            if (fixedCandidate != null) {
                addCandidate(fixedCandidate);
            }

            setResolveEnd();
        }
    }
937062
private boolean isIPAddress(@Nonnull String address) {
        return (InetAddressUtils.isIPv4Address(address) || InetAddressUtils.isIPv6Address(address));
    }
512513
void reconnect() throws InterruptedException {
        long maxTries = options.getMaxReconnect();
        long tries = 0;
        String lastServer = null;

        if (isClosed()) {
            return;
        }

        if (maxTries == 0) {
            this.close();
            return;
        }

        this.writer.setReconnectMode(true);

        while (!isConnected() && !isClosed() && !this.isClosing()) {
            Collection<String> serversToTry = buildReconnectList();

            for (String server : serversToTry) {
                if (isClosed()) {
                    break;
                }

                if (server.equals(lastServer)) {
                    this.reconnectWaiter = new CompletableFuture<>();
                    waitForReconnectTimeout();
                }

                if (isDisconnectingOrClosed() || this.isClosing()) {
                    break;
                }

                updateStatus(Status.RECONNECTING);

                tryToConnect(server);
                lastServer = server;
                tries++;

                if (maxTries > 0 && tries >= maxTries) {
                    break;
                } else if (isConnected()) {
                    this.statistics.incrementReconnects();
                    break;
                }
            }

            if (maxTries > 0 && tries >= maxTries) {
                break;
            }
        }

        if (!isConnected()) {
            this.close();
            return;
        }

        this.subscribers.forEach((sid, sub) -> {
            if (sub.getDispatcher() == null && !sub.isDraining()) {
                sendSubscriptionMessage(sub.getSID(), sub.getSubject(), sub.getQueueName(), true);
            }
        });

        this.dispatchers.forEach((nuid, d) -> {
            if (!d.isDraining()) {
                d.resendSubscriptions();
            }
        });

        try {
            this.flush(this.options.getConnectionTimeout());
        } catch (Exception exp) {
            this.processException(exp);
        }
        
        // When the flush returns we are done sending internal messages, so we can switch to the
        // non-reconnect queue
        this.writer.setReconnectMode(false);

        processConnectionEvent(Events.RESUBSCRIBED);
    }
470647
@Nullable
    public static String determineIpAddress() throws SocketException {
        SocketException caughtException = null;
        for (final Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces(); networkInterfaces.hasMoreElements();) {
            try {
                final NetworkInterface nextInterface = networkInterfaces.nextElement();
                if (! nextInterface.isLoopback() && ! nextInterface.isVirtual() && ! nextInterface.isPointToPoint()) {
                    for (final Enumeration<InetAddress> addresses = nextInterface.getInetAddresses(); addresses.hasMoreElements(); ) {
                        final InetAddress inetAddress = addresses.nextElement();
                        final byte[] address = inetAddress.getAddress();
                        if ((address.length == 4) //  we don't need no steenking IPv6
                                && ((address[0] != 127) || (address[1] != 0))) {    //  don't want localhost IP
                            return inetAddress.getHostAddress();
                        }
                    }
                }
            } catch (SocketException ex) {
                // We're not going to extract an IP address from this interface, so move on to the next one.
                // If we find a qualifying interface, we won't care that some other interface gave us problems.
                // If we don't find one, this exception might be informative.
                caughtException = ex;
            }
        }

        if (caughtException != null) {
            throw caughtException;
        }
        return null;
    }
93260
private Proxy nextProxy() throws IOException {
    if (!hasNextProxy()) {
      throw new SocketException("No route to " + address.url().host()
          + "; exhausted proxy configurations: " + proxies);
    }
    Proxy result = proxies.get(nextProxyIndex++);
    resetNextInetSocketAddress(result);
    return result;
  }
119957
def dns_resolve(self):
        
        new_addresses = []
        for address in self.addresses:
            try:
                info = getaddrinfo(address[0], address[1], 0, SOCK_STREAM, IPPROTO_TCP)
            except gaierror:
                raise AddressError("Cannot resolve address {!r}".format(address))
            else:
                for _, _, _, _, address in info:
                    if len(address) == 4 and address[3] != 0:
                        # skip any IPv6 addresses with a non-zero scope id
                        # as these appear to cause problems on some platforms
                        continue
                    new_addresses.append(address)
        self.addresses = new_addresses
1036645
@Override
    public InetAddress toInetAddress () throws UnknownHostException {
        if ( this.addr instanceof Address ) {
            return ( (Address) this.addr ).toInetAddress();
        }
        else if ( this.addr instanceof InetAddress ) {
            return (InetAddress) this.addr;
        }
        return null;
    }
256194
private void addReconnectTimer()
    {
        int rcIvl = getNewReconnectIvl();
        ioObject.addTimer(rcIvl, RECONNECT_TIMER_ID);

        // resolve address again to take into account other addresses
        // besides the failing one (e.g. multiple dns entries).
        try {
            addr.resolve(options.ipv6);
        }
        catch (Exception ignored) {
            // This will fail if the network goes away and the
            // address cannot be resolved for some reason. Try
            // not to fail as the event loop will quit
        }

        socket.eventConnectRetried(addr.toString(), rcIvl);
        timerStarted = true;
    }
549956
public function next()
    {
        if ($this->valid()) {
            $this->current = $this->current->getIntValue() == $this->range->getEnd()->getIntValue()
                ? null
                : new IP($this->current->getIntValue() + 1);
        }
    }
164454
void connect(boolean reconnectOnConnect) throws InterruptedException, IOException {
        if (options.getServers().size() == 0) {
            throw new IllegalArgumentException("No servers provided in options");
        }

        for (String serverURI : getServers()) {

            if (isClosed()) {
                break;
            }

            updateStatus(Status.CONNECTING);

            tryToConnect(serverURI);

            if (isConnected()) {
                break;
            } else {
                updateStatus(Status.DISCONNECTED);
            }
        }

        if (!isConnected() && !isClosed()) {
            if (reconnectOnConnect) {
                reconnect();
            } else {
                close();
                throw new IOException("Unable to connect to gnatsd server.");
            }
        }
    }
85457
@Override
  public InetSocketAddress ipRemote()
  {
    if (_ipRemote == null) {
      try {
        _ipRemote = InetSocketAddress.createUnresolved(getLocalHost(),
                                                      portLocal());
      } catch (Exception e) {
        log.log(Level.FINE, e.toString(), e);
      }
    }

    return _ipLocal;
  }
79727
public Endpoint withIpAddr(@Nullable String ipAddr) {
        ensureSingle();
        if (ipAddr == null) {
            return withoutIpAddr();
        }

        if (NetUtil.isValidIpV4Address(ipAddr)) {
            return withIpAddr(ipAddr, StandardProtocolFamily.INET);
        }

        if (NetUtil.isValidIpV6Address(ipAddr)) {
            if (ipAddr.charAt(0) == '[') {
                ipAddr = ipAddr.substring(1, ipAddr.length() - 1);
            }
            return withIpAddr(ipAddr, StandardProtocolFamily.INET6);
        }

        throw new IllegalArgumentException("ipAddr: " + ipAddr + " (expected: an IP address)");
    }
1043623
public static String resolveIpAddress(String hostname) throws UnknownHostException {
    Preconditions.checkNotNull(hostname, "hostname");
    Preconditions.checkArgument(!hostname.isEmpty(),
            "Cannot resolve IP address for empty hostname");
    return InetAddress.getByName(hostname).getHostAddress();
  }
1349824
public void connect(Object address) throws Exception {

        this.targetAddress = (HttpAddress) address;
        // if we're connecting on an existing SC, then clear it if need be
        // we do not want to clear when the reconnect flag is false because
        // that means we're in the middle of a reconnect (we called this method
        // and not an external user)
        if (null != this.myInterface && isReconnectAllowed()) {
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Clearing existing OSC on connect");
            }
            this.myInterface.clear();
        }
        super.connect(address);
    }
954451
public SocketAddress resolve(RedisURI redisURI) {

        LettuceAssert.notNull(redisURI, "RedisURI must not be null");

        return resolve(redisURI, dnsResolver);
    }
1332260
@Override
    public synchronized void resolve(JingleSession session) throws XMPPException, SmackException, InterruptedException {
        this.setResolveInit();

        for (TransportCandidate candidate : this.getCandidatesList()) {
            if (candidate instanceof ICECandidate) {
                ICECandidate iceCandidate = (ICECandidate) candidate;
                iceCandidate.removeCandidateEcho();
            }
        }

        this.clear();

        // Create a transport candidate for each ICE negotiator candidate we have.
        ICENegociator iceNegociator = negociatorsMap.get(server);
        for (Candidate candidate : iceNegociator.getSortedCandidates())
            try {
                Candidate.CandidateType type = candidate.getCandidateType();
                ICECandidate.Type iceType;
                if (type.equals(Candidate.CandidateType.ServerReflexive))
                    iceType = ICECandidate.Type.srflx;
                else if (type.equals(Candidate.CandidateType.PeerReflexive))
                    iceType = ICECandidate.Type.prflx;
                else if (type.equals(Candidate.CandidateType.Relayed))
                    iceType = ICECandidate.Type.relay;
                else
                    iceType = ICECandidate.Type.host;

               // JBW/GW - 17JUL08: Figure out the zero-based NIC number for this candidate.
                short nicNum = 0;
                try {
                    Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
                    short i = 0;
                    NetworkInterface nic = NetworkInterface.getByInetAddress(candidate.getAddress().getInetAddress());
                    while (nics.hasMoreElements()) {
                        NetworkInterface checkNIC = nics.nextElement();
                        if (checkNIC.equals(nic)) {
                            nicNum = i;
                            break;
                        }
                        i++;
                    }
                } catch (SocketException e1) {
                    LOGGER.log(Level.WARNING, "exeption", e1);
                }

                TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress().getHostAddress(), 1, nicNum, String.valueOf(random.nextInt(Integer.MAX_VALUE)), candidate.getPort(), "1", candidate.getPriority(), iceType);
                transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
                transportCandidate.setPort(getFreePort());
                try {
                    transportCandidate.addCandidateEcho(session);
                }
                catch (SocketException e) {
                    LOGGER.log(Level.WARNING, "exception", e);
                }
                this.addCandidate(transportCandidate);

                LOGGER.fine("Candidate addr: " + candidate.getAddress().getInetAddress() + "|" + candidate.getBase().getAddress().getInetAddress() + " Priority:" + candidate.getPriority());

            }
            catch (UtilityException e) {
                LOGGER.log(Level.WARNING, "exception", e);
            }
            catch (UnknownHostException e) {
                LOGGER.log(Level.WARNING, "exception", e);
            }

        // Get a Relay Candidate from XMPP Server

        if (RTPBridge.serviceAvailable(connection)) {
//            try {

                String localIp;
                int network;


                // JBW/GW - 17JUL08: ICENegotiator.getPublicCandidate() always returned null in JSTUN 1.7.0, and now the API doesn't exist in JSTUN 1.7.1
//                if (iceNegociator.getPublicCandidate() != null) {
//                    localIp = iceNegociator.getPublicCandidate().getBase().getAddress().getInetAddress().getHostAddress();
//                    network = iceNegociator.getPublicCandidate().getNetwork();
//                }
//                else {
                {
                    localIp = BridgedResolver.getLocalHost();
                    network = 0;
                }

                sid = random.nextInt(Integer.MAX_VALUE);

                RTPBridge rtpBridge = RTPBridge.getRTPBridge(connection, String.valueOf(sid));

                TransportCandidate localCandidate = new ICECandidate(
                    rtpBridge.getIp(), 1, network, String.valueOf(random.nextInt(Integer.MAX_VALUE)), rtpBridge.getPortA(), "1", 0, ICECandidate.Type.relay);
                localCandidate.setLocalIp(localIp);

                TransportCandidate remoteCandidate = new ICECandidate(
                        rtpBridge.getIp(), 1, network, String.valueOf(random.nextInt(Integer.MAX_VALUE)), rtpBridge.getPortB(), "1", 0, ICECandidate.Type.relay);
                remoteCandidate.setLocalIp(localIp);

                localCandidate.setSymmetric(remoteCandidate);
                remoteCandidate.setSymmetric(localCandidate);

                localCandidate.setPassword(rtpBridge.getPass());
                remoteCandidate.setPassword(rtpBridge.getPass());

                localCandidate.setSessionId(rtpBridge.getSid());
                remoteCandidate.setSessionId(rtpBridge.getSid());

                localCandidate.setConnection(this.connection);
                remoteCandidate.setConnection(this.connection);

                addCandidate(localCandidate);

//            }
//            catch (UtilityException e) {
//                LOGGER.log(Level.WARNING, "exception", e);
//            }
//            catch (UnknownHostException e) {
//                LOGGER.log(Level.WARNING, "exception", e);
//            }

            // Get Public Candidate From XMPP Server

 // JBW/GW - 17JUL08 - ICENegotiator.getPublicCandidate() always returned null in JSTUN 1.7.0, and now it doesn't exist in JSTUN 1.7.1
 //          if (iceNegociator.getPublicCandidate() == null) {
            if (true) {

                String publicIp = RTPBridge.getPublicIP(connection);

                if (publicIp != null && !publicIp.equals("")) {

                    Enumeration<NetworkInterface> ifaces = null;

                    try {
                        ifaces = NetworkInterface.getNetworkInterfaces();
                    }
                    catch (SocketException e) {
                        LOGGER.log(Level.WARNING, "exception", e);
                    }

                    // If detect this address in local machine, don't use it.

                    boolean found = false;

                    while (ifaces.hasMoreElements() && !false) {

                        NetworkInterface iface = ifaces.nextElement();
                        Enumeration<InetAddress> iaddresses = iface.getInetAddresses();

                        while (iaddresses.hasMoreElements()) {
                            InetAddress iaddress = iaddresses.nextElement();
                            if (iaddress.getHostAddress().indexOf(publicIp) > -1) {
                                found = true;
                                break;
                            }
                        }
                    }

                    if (!found) {
                        try {
                            TransportCandidate publicCandidate = new ICECandidate(
                                    publicIp, 1, 0, String.valueOf(random.nextInt(Integer.MAX_VALUE)), getFreePort(), "1", 0, ICECandidate.Type.srflx);
                            publicCandidate.setLocalIp(InetAddress.getLocalHost().getHostAddress());

                            try {
                                publicCandidate.addCandidateEcho(session);
                            }
                            catch (SocketException e) {
                                LOGGER.log(Level.WARNING, "exception", e);
                            }

                            addCandidate(publicCandidate);
                        }
                        catch (UnknownHostException e) {
                            LOGGER.log(Level.WARNING, "exception", e);
                        }
                    }
                }
            }

        }

        this.setResolveEnd();
    }
226713
@Override
    public synchronized void resolve(JingleSession session) throws XMPPException, NotConnectedException, InterruptedException {

        setResolveInit();

        clearCandidates();

        TransportCandidate candidate = new TransportCandidate.Fixed(
                resolvedPublicIP, getFreePort());
        candidate.setLocalIp(resolvedLocalIP);

        LOGGER.fine("RESOLVING : " + resolvedPublicIP + ":" + candidate.getPort());

        addCandidate(candidate);

        setResolveEnd();

    }