Find a non loopback address for this machine on which to start the server.
@return a non loopback address
@throws SocketException if a socket error occurs
194722
private static InetAddress findNonLoopbackAddress() throws SocketException {
        final Enumeration<NetworkInterface> enumInterfaceAddress = NetworkInterface.getNetworkInterfaces();
        while (enumInterfaceAddress.hasMoreElements()) {
            final NetworkInterface netIf = enumInterfaceAddress.nextElement();

            // Iterate over inet address
            final Enumeration<InetAddress> enumInetAdress = netIf.getInetAddresses();
            while (enumInetAdress.hasMoreElements()) {
                final InetAddress address = enumInetAdress.nextElement();
                if (!address.isLoopbackAddress()) {
                    return address;
                }
            }
        }
        return null;
    }
1082959
@Override
  public InetSocketAddress ipLocal()
  {
    Socket s = getSocket();
    
    if (s != null) {
      return (InetSocketAddress) s.getLocalSocketAddress();
    }
    else {
      return null;
    }
  }
385818
public NetworkInterface getNetworkInterface() throws SocketException {
        Integer niIndex
            = (Integer)getImpl().getOption(SocketOptions.IP_MULTICAST_IF2);
        if (niIndex == 0) {
            InetAddress[] addrs = new InetAddress[1];
            addrs[0] = InetAddress.anyLocalAddress();
            return new NetworkInterface(addrs[0].getHostName(), 0, addrs);
        } else {
            return NetworkInterface.getByIndex(niIndex);
        }
    }
32212
public static InetAddress getLocalIpAddress() throws RuntimeException
	{
		try
		{
			List<InetAddress> ips = getLocalIpAddresses(false, true);

			for (InetAddress ip : ips)
			{
				log.debug("[IpHelper] {getLocalIpAddress} Considering locality of " + ip.getHostAddress());
				if (!ip.isAnyLocalAddress() && (ip instanceof Inet4Address))
				{
					// Ubuntu sets the unix hostname to resolve to 127.0.1.1; this is annoying so treat it as a loopback
					if (!ip.getHostAddress().startsWith("127.0."))
					{
						log.debug("[IpHelper] {getLocalIpAddress} Found nonloopback IP: " + ip.getHostAddress());
						return ip;
					}
				}
			}

			log.trace("[IpHelper] {getLocalIpAddress} Couldn't find a public IP in the ip (size " + ips.size() + ")");
			return InetAddress.getLocalHost();
		}
		catch (UnknownHostException e)
		{
			throw new RuntimeException("[FileHelper] {getLocalIp}: Unable to acquire the current machine's InetAddress", e);
		}
	}
1154025
public function getIp(): string
    {
        $name = $this->getName();

        if ($name) {
            return self::getNamePart($name, self::NAME_PART_IP);
        } else {
            throw new SocketException('Cannot get socket IP address');
        }
    }
1147380
public String getServerAddr()
    {
        if (_connection instanceof Socket)
            return ((Socket)_connection).getLocalAddress().getHostAddress();
        return _listener.getHost();
    }
1187713
public SockAddr getDstAddr() {
		SockAddr sockAddr = null;
		if (this.dstaddr != null) {
			sockAddr = new SockAddr(this.dstaddr.getSaFamily().getValue(), this.dstaddr.getData());
		}
		return sockAddr;
	}
171421
@Override
  public int portRemote()
  {
    if (_channel != null) {
      try {
        SocketAddress addr = _channel.getRemoteAddress();
        
        return 0;
      } catch (Exception e) {
        e.printStackTrace();
        return 0;
      }
    }
    else
      return 0;
  }
339740
public InetSocketAddress getEndpoint() {
        return endpoint == null ? new InetSocketAddress(uri.getHost(), uri.getPort()) : endpoint;
    }
1143505
@Override
  public InetSocketAddress ipLocal()
  {
    SocketChannel s = _channel;
    
    if (s != null) {
      try {
        return (InetSocketAddress) s.getLocalAddress();
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
    else {
      return null;
    }
  }
374811
public int start() throws IOException {
		synchronized (this.monitor) {
			Assert.state(this.serverThread == null, "Server already started");
			ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
			serverSocketChannel.socket().bind(new InetSocketAddress(this.listenPort));
			int port = serverSocketChannel.socket().getLocalPort();
			logger.trace("Listening for TCP traffic to tunnel on port " + port);
			this.serverThread = new ServerThread(serverSocketChannel);
			this.serverThread.start();
			return port;
		}
	}
424096
public static Socket getCurrentSocket() {
        ConnectionHandler handler = connectionMap.get(Thread.currentThread());
        return (handler == null ? null : handler.getSocket());
    }
1361187
@Override
  public InetAddress addressLocal()
  {
    SocketChannel s = _channel;
    
    if (s != null) {
      try {
        InetSocketAddress addr = (InetSocketAddress) s.getLocalAddress();
        
        return addr.getAddress();
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
    else {
      return null;
    }
  }
827637
public SockAddr getBroadAddr() {
		SockAddr sockAddr = null;
		if (this.broadaddr != null) {
			sockAddr = new SockAddr(this.broadaddr.getSaFamily().getValue(), this.broadaddr.getData());
		}
		return sockAddr;
	}
639085
private static InetAddress[] getAllLocalInetAddresses(final Log log) 
    throws SocketException {

        final List addresses = new ArrayList();
        
        // get the network adapters
        final Enumeration netInterfaces = NetworkInterface.getNetworkInterfaces();
        while (netInterfaces.hasMoreElements()) {
            final NetworkInterface ni = (NetworkInterface)netInterfaces.nextElement();
            if (log != null) {
                log.debug("Found interface: " + ni.getName());
            }
            
            // get the IPs for this network interface
            final Enumeration ips = ni.getInetAddresses();
            while (ips.hasMoreElements()) {
                final InetAddress ip = (InetAddress)ips.nextElement();
                if (log != null) {
                    log.debug("Found ip: " + ip.getHostName() + "/" 
                        + ip.getHostAddress() + " on interface: " + ni.getName());
                }

                // ignore the local loopback address: 127.0.0.1
                if (!ip.isLoopbackAddress()) {
                    if (log != null) {
                        log.debug("Let's add this IP: " + ip.getCanonicalHostName());
                    }
                    addresses.add(ip);
                }
            }
        }
        
        return (InetAddress[])addresses.toArray(new InetAddress[addresses.size()]);
    }
1302696
@Override
  public InetAddress addressLocal()
  {
    Socket s = getSocket();
    
    if (s != null) {
      return s.getLocalAddress();
    }
    else {
      return null;
    }
  }
726472
@Override
  public InetAddress addressRemote()
  {
    SocketChannel s = _channel;
    
    if (s != null) {
      try {
        InetSocketAddress addr = (InetSocketAddress) s.getRemoteAddress();
        
        return addr.getAddress();
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
    else {
      return null;
    }
  }