public HTTPSession(NanoHTTPD httpd, ITempFileManager tempFileManager, InputStream inputStream, OutputStream outputStream, InetAddress inetAddress) { this.httpd = httpd; this.tempFileManager = tempFileManager; this.inputStream = new BufferedInputStream(inputStream, HTTPSession.BUFSIZE); this.outputStream = outputStream; this.remoteIp = inetAddress.isLoopbackAddress() || inetAddress.isAnyLocalAddress() ? "127.0.0.1" : inetAddress.getHostAddress().toString(); this.remoteHostname = inetAddress.isLoopbackAddress() || inetAddress.isAnyLocalAddress() ? "localhost" : inetAddress.getHostName().toString(); this.headers = new HashMap<String, String>(); }
public static boolean isThisMyIpAddress(InetAddress addr) { // Check if the address is a valid special local or loop back if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) return true; // Check if the address is defined on any interface try { return NetworkInterface.getByInetAddress(addr) != null; } catch (SocketException e) { return false; } }
private static int scoreAddress(InetAddress addr) { if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) { return 0; } if (addr.isMulticastAddress()) { return 1; } if (addr.isLinkLocalAddress()) { return 2; } if (addr.isSiteLocalAddress()) { return 3; } return 4; }
private static int scoreAddress(InetAddress addr) { if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) { return 0; } if (addr.isMulticastAddress()) { return 1; } if (addr.isLinkLocalAddress()) { return 2; } if (addr.isSiteLocalAddress()) { return 3; } return 4; }
/** * Check is passed socket address belong to current node. This method should return true only if the passed * in address represent an address which will result in a connection to the local node. * * @param addr address to check. * @return true if passed address belongs to local node, otherwise false. */ private boolean isLocalNodeAddress(InetSocketAddress addr) { return addr.getPort() == boundTcpPort && (locHost.equals(addr.getAddress()) || addr.getAddress().isAnyLocalAddress() || (locHost.isAnyLocalAddress() && U.isLocalAddress(addr.getAddress()))); }
/** * Tests if the address is externally resolvable. Address must not be wildcard, link local, * loopback address, non-IPv4, or other unreachable addresses. * * @param address The testing address * @param timeoutMs Timeout in milliseconds to use for checking that a possible local IP is * reachable * @return a {@code boolean} indicating if the given address is externally resolvable address */ private static boolean isValidAddress(InetAddress address, int timeoutMs) throws IOException { return !address.isAnyLocalAddress() && !address.isLinkLocalAddress() && !address.isLoopbackAddress() && address.isReachable(timeoutMs) && (address instanceof Inet4Address); }
private String getDefaultAddress() { Enumeration<NetworkInterface> nets; try { nets = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e) { return null; } NetworkInterface netinf; while (nets.hasMoreElements()) { netinf = nets.nextElement(); Enumeration<InetAddress> addresses = netinf.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress address = addresses.nextElement(); if (!address.isAnyLocalAddress() && !address.isMulticastAddress() && !(address instanceof Inet6Address)) { return address.getHostAddress(); } } } return null; }
/** * @return Get default interface to use since the user hasn't specified one. */ protected String getDefaultAddress() { Enumeration<NetworkInterface> nets; try { nets = NetworkInterface.getNetworkInterfaces(); } catch (SocketException e) { return null; } NetworkInterface netinf; while (nets.hasMoreElements()) { netinf = nets.nextElement(); Enumeration<InetAddress> addresses = netinf.getInetAddresses(); while (addresses.hasMoreElements()) { InetAddress address = addresses.nextElement(); if (!address.isAnyLocalAddress() && !address.isMulticastAddress() && !(address instanceof Inet6Address)) { return address.getHostAddress(); } } } return null; }
private void setupClientPort() throws ConfigException { if (serverId == UNSET_SERVERID) { return; } QuorumServer qs = quorumVerifier.getAllMembers().get(serverId); if (clientPortAddress != null && qs != null && qs.clientAddr != null) { if ((!clientPortAddress.getAddress().isAnyLocalAddress() && !clientPortAddress.equals(qs.clientAddr)) || (clientPortAddress.getAddress().isAnyLocalAddress() && clientPortAddress.getPort() != qs.clientAddr.getPort())) throw new ConfigException("client address for this server (id = " + serverId + ") in static config file is " + clientPortAddress + " is different from client address found in dynamic file: " + qs.clientAddr); } if (qs != null && qs.clientAddr != null) clientPortAddress = qs.clientAddr; if (qs != null && qs.clientAddr == null) { qs.clientAddr = clientPortAddress; qs.isClientAddrFromStatic = true; } }
private static boolean isGoodV6Address(InetAddress address) { return address instanceof Inet6Address && !address.isAnyLocalAddress() && !address.isLoopbackAddress() && !address.isMulticastAddress(); }
private static boolean isGoodV4Address(InetAddress address) { return address instanceof Inet4Address && !address.isAnyLocalAddress() && !address.isLoopbackAddress() && !address.isMulticastAddress(); }
private static boolean isLocalHost(String host) { if (!host.isEmpty()) { try { String normalizedHost = "http://" + removeScheme(host); InetAddress hostAddr = InetAddress.getByName(new URL(normalizedHost).getHost()); return hostAddr.isAnyLocalAddress() || hostAddr.isLoopbackAddress(); } catch (Exception e) { // ignore } } return false; }
private static String bossThreadName(ServerPort port) { final InetSocketAddress localAddr = port.localAddress(); final String localHostName = localAddr.getAddress().isAnyLocalAddress() ? "*" : localAddr.getHostString(); // e.g. 'armeria-boss-http-*:8080' // 'armeria-boss-http-127.0.0.1:8443' // 'armeria-boss-proxy+http+https-127.0.0.1:8443' final String protocolNames = port.protocols().stream() .map(SessionProtocol::uriText) .collect(Collectors.joining("+")); return "armeria-boss-" + protocolNames + '-' + localHostName + ':' + localAddr.getPort(); } }
public boolean isLocalAddress(Node node) { String host = node.getHost(); InetAddress hostAddress; try { hostAddress = InetAddress.getByName(host); } catch(UnknownHostException ex) { throw new VoldemortApplicationException("Error retrieving InetAddress for host " + host, ex); } return hostAddress.isAnyLocalAddress() || hostAddress.isLoopbackAddress(); }
public boolean doesTagMatch(final UdpChannel udpChannel) { if (!hasTag || !udpChannel.hasTag() || tag != udpChannel.tag()) { return false; } if (udpChannel.remoteData().getAddress().isAnyLocalAddress() && udpChannel.remoteData().getPort() == 0 && udpChannel.localData().getAddress().isAnyLocalAddress() && udpChannel.localData().getPort() == 0) { return true; } throw new IllegalArgumentException("matching tag has set endpoint or control address"); }
public MCMPConfig(Builder builder) { this.managementSocketAddress = new InetSocketAddress(builder.managementHost, builder.managementPort); if (managementSocketAddress.isUnresolved()) { throw UndertowLogger.PROXY_REQUEST_LOGGER.unableToResolveModClusterManagementHost(builder.managementHost); } if (managementSocketAddress.getAddress().isAnyLocalAddress()) { throw UndertowLogger.PROXY_REQUEST_LOGGER.cannotUseWildcardAddressAsModClusterManagementHost(builder.managementHost); } if (builder.advertiseBuilder != null) { this.advertiseConfig = new AdvertiseConfig(builder.advertiseBuilder, this); } else { this.advertiseConfig = null; } }
@Test public void testPortConfiguration() throws Exception { final Collection<ServerPort> ports = server.activePorts().values(); assertThat(ports.stream().filter(ServerPort::hasHttp)).hasSize(3); assertThat(ports.stream().filter(p -> p.localAddress().getAddress().isAnyLocalAddress())).hasSize(2); assertThat(ports.stream().filter(p -> p.localAddress().getAddress().isLoopbackAddress())).hasSize(1); }
@Override public DatagramChannelConfig setBroadcast(boolean broadcast) { try { // See: https://github.com/netty/netty/issues/576 if (broadcast && !javaSocket.getLocalAddress().isAnyLocalAddress() && !PlatformDependent.isWindows() && !PlatformDependent.maybeSuperUser()) { // Warn a user about the fact that a non-root user can't receive a // broadcast packet on *nix if the socket is bound on non-wildcard address. logger.warn( "A non-root user can't receive a broadcast packet if the socket " + "is not bound to a wildcard address; setting the SO_BROADCAST flag " + "anyway as requested on the socket which is bound to " + javaSocket.getLocalSocketAddress() + '.'); } javaSocket.setBroadcast(broadcast); } catch (SocketException e) { throw new ChannelException(e); } return this; }
@Override public DatagramChannelConfig setBroadcast(boolean broadcast) { try { // See: https://github.com/netty/netty/issues/576 if (broadcast && !javaSocket.getLocalAddress().isAnyLocalAddress() && !PlatformDependent.isWindows() && !PlatformDependent.maybeSuperUser()) { // Warn a user about the fact that a non-root user can't receive a // broadcast packet on *nix if the socket is bound on non-wildcard address. logger.warn( "A non-root user can't receive a broadcast packet if the socket " + "is not bound to a wildcard address; setting the SO_BROADCAST flag " + "anyway as requested on the socket which is bound to " + javaSocket.getLocalSocketAddress() + '.'); } javaSocket.setBroadcast(broadcast); } catch (SocketException e) { throw new ChannelException(e); } return this; }
!((InetSocketAddress) localAddress).getAddress().isAnyLocalAddress() && !PlatformDependent.isWindows() && !PlatformDependent.maybeSuperUser()) {