Refine search
public byte[] getAddressBytes() { return inetSocketAddress.getAddress().getAddress(); }
/** * Converts string representation of host/ip to 4-bytes byte[] IPv4 */ public static byte[] hostToBytes(String ip) { byte[] bytesIp; try { bytesIp = InetAddress.getByName(ip).getAddress(); } catch (UnknownHostException e) { bytesIp = new byte[4]; // fall back to invalid 0.0.0.0 address } return bytesIp; }
public byte[] getAddress() throws UnknownHostException { if (hostAddress != null) { return InetAddress.getByName(hostAddress).getAddress(); } return null; }
public static ByteBuffer socketAddress2ByteBuffer(final SocketAddress socketAddress, final ByteBuffer byteBuffer) { InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress; byteBuffer.put(inetSocketAddress.getAddress().getAddress(), 0, 4); byteBuffer.putInt(inetSocketAddress.getPort()); byteBuffer.flip(); return byteBuffer; }
public IP4Address(String address) throws UnknownHostException{ mString = address; mAddress = InetAddress.getByName(address); mByteArray = mAddress.getAddress(); mInteger = ((mByteArray[0] & 0xFF) << 24) + ((mByteArray[1] & 0xFF) << 16) + ((mByteArray[2] & 0xFF) << 8) + (mByteArray[3] & 0xFF); }
@Override public byte[] getAddress() { return remotePeer.getAddress().getAddress(); }
InetAddress ip = InetAddress.getByName("192.168.2.1"); byte[] bytes = ip.getAddress(); for (byte b : bytes) { System.out.println(b & 0xFF); }
/** * Returns a binary representation of the peer's IP. */ public byte[] getRawIp() { final InetAddress address = this.address.getAddress(); if (address == null) return null; return address.getAddress(); }
IPv6AddressRep(String initial_addr) { try { address = InetAddress.getByName(initial_addr); } catch (UnknownHostException e) { // throw new RuntimeException ("Multicast address " + initial_addr + " has incorrect format", e) ; } catch (SecurityException e) { // throw new RuntimeException ("Security violation in accessing multicast address " + initial_addr, e) ; } // get the byte representation bv = address.getAddress(); }
public static String createMessageId(SocketAddress socketAddress, long transactionIdhashCode) { ByteBuffer byteBuffer = ByteBuffer.allocate(MessageDecoder.MSG_ID_LENGTH); InetSocketAddress inetSocketAddress = (InetSocketAddress) socketAddress; byteBuffer.put(inetSocketAddress.getAddress().getAddress()); byteBuffer.putInt(inetSocketAddress.getPort()); byteBuffer.putLong(transactionIdhashCode); byteBuffer.flip(); return UtilAll.bytes2string(byteBuffer.array()); }
private static byte[] parseIPv4Address(String strAddress) throws UnknownHostException { byte[] addr; int slashIndex = strAddress.indexOf('/'); if (slashIndex == -1) { addr = InetAddress.getByName(strAddress).getAddress(); } else { addr = new byte[8]; byte[] baseAddress = InetAddress.getByName(strAddress.substring(0, slashIndex)).getAddress(); byte[] mask = InetAddress.getByName(strAddress.substring(slashIndex + 1)).getAddress(); System.arraycopy(baseAddress, 0, addr, 0, 4); System.arraycopy(mask, 0, addr, 4, 4); } return addr; }
private static InetSocketAddress getMulticastControlAddress(final InetSocketAddress endpointAddress) throws UnknownHostException { final byte[] addressAsBytes = endpointAddress.getAddress().getAddress(); validateDataAddress(addressAsBytes); addressAsBytes[addressAsBytes.length - 1]++; return new InetSocketAddress(getByAddress(addressAsBytes), endpointAddress.getPort()); }
/** * Returns the bytes of the given IP address or masked IP address. */ public static byte[] ipStrToBytes(String ip) throws IOException { if (!InetAddress.isNumeric(ip)) { throw new IOException("Not an IP address: " + ip); } return InetAddress.getByName(ip).getAddress(); }
/** * Adds the hostname string to the specified {@link InetSocketAddress} so that * Jetty's {@code ServletRequest.getLocalName()} implementation returns the configured hostname. */ private static InetSocketAddress addHostname(InetSocketAddress address, @Nullable String hostname) { try { return new InetSocketAddress(InetAddress.getByAddress( hostname, address.getAddress().getAddress()), address.getPort()); } catch (UnknownHostException e) { throw new Error(e); // Should never happen } }
InetAddress inetAddress = InetAddress.getByName(address); byte[] addr = inetAddress.getAddress();
public static InetSocketAddress computeRemoteAddr(InetSocketAddress remoteAddr, InetSocketAddress osRemoteAddr) { if (osRemoteAddr != null) { if (PlatformDependent.javaVersion() >= 7) { try { // Only try to construct a new InetSocketAddress if we using java >= 7 as getHostString() does not // exists in earlier releases and so the retrieval of the hostname could block the EventLoop if a // reverse lookup would be needed. return new InetSocketAddress(InetAddress.getByAddress(remoteAddr.getHostString(), osRemoteAddr.getAddress().getAddress()), osRemoteAddr.getPort()); } catch (UnknownHostException ignore) { // Should never happen but fallback to osRemoteAddr anyway. } } return osRemoteAddr; } return remoteAddr; } }
private static byte[] parseIPv6Address(String strAddress) throws ASN1Exception, UnknownHostException { byte[] addr; int slashIndex = strAddress.indexOf('/'); if (slashIndex == -1) { addr = InetAddress.getByName(strAddress).getAddress(); } else { addr = new byte[32]; byte[] baseAddress = InetAddress.getByName(strAddress.substring(0, slashIndex)).getAddress(); System.arraycopy(baseAddress, 0, addr, 0, 16); int prefixLength = Integer.parseInt(strAddress.substring(slashIndex + 1)); if (prefixLength > 128) { throw log.asnInvalidGeneralNameForIpAddressType(); } byte[] mask = new byte[16]; int maskIndex, bit; for (int i = 0; i < prefixLength; i++) { maskIndex = i / 8; bit = 1 << (7 - (i % 8)); mask[maskIndex] |= bit; } System.arraycopy(mask, 0, addr, 16, 16); } return addr; } }
@Override public byte[] getAddress() throws UnknownHostException { final SocketAddress remoteAddress = ioSession.getRemoteAddress(); if (remoteAddress == null) throw new UnknownHostException(); final InetSocketAddress socketAddress = (InetSocketAddress) remoteAddress; final InetAddress address = socketAddress.getAddress(); return address.getAddress(); }
public boolean isInternal(String ip) { try { return isInternal(InetAddress.getByName(ip).getAddress()); } catch (UnknownHostException e) { Logger.error(e.getMessage()); } return false; }
public static InetSocketAddress computeRemoteAddr(InetSocketAddress remoteAddr, InetSocketAddress osRemoteAddr) { if (osRemoteAddr != null) { if (PlatformDependent.javaVersion() >= 7) { try { // Only try to construct a new InetSocketAddress if we using java >= 7 as getHostString() does not // exists in earlier releases and so the retrieval of the hostname could block the EventLoop if a // reverse lookup would be needed. return new InetSocketAddress(InetAddress.getByAddress(remoteAddr.getHostString(), osRemoteAddr.getAddress().getAddress()), osRemoteAddr.getPort()); } catch (UnknownHostException ignore) { // Should never happen but fallback to osRemoteAddr anyway. } } return osRemoteAddr; } return remoteAddr; } }