Java Code Examples for sun.net.util.IPAddressUtil#textToNumericFormatV4()
The following examples show how to use
sun.net.util.IPAddressUtil#textToNumericFormatV4() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InetAddress.java From Bytecoder with Apache License 2.0 | 5 votes |
private byte [] createAddressByteArray(String addrStr) { byte[] addrArray; // check if IPV4 address - most likely addrArray = IPAddressUtil.textToNumericFormatV4(addrStr); if (addrArray == null) { addrArray = IPAddressUtil.textToNumericFormatV6(addrStr); } return addrArray; }
Example 2
Source File: InetAddress.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private byte [] createAddressByteArray(String addrStr) { byte[] addrArray; // check if IPV4 address - most likely addrArray = IPAddressUtil.textToNumericFormatV4(addrStr); if (addrArray == null) { addrArray = IPAddressUtil.textToNumericFormatV6(addrStr); } return addrArray; }
Example 3
Source File: SocketPermission.java From jdk-1.7-annotated with Apache License 2.0 | 4 votes |
/** * Initialize the SocketPermission object. We don't do any DNS lookups * as this point, instead we hold off until the implies method is * called. */ private void init(String host, int mask) { // Set the integer mask that represents the actions if ((mask & ALL) != mask) throw new IllegalArgumentException("invalid actions mask"); // always OR in RESOLVE if we allow any of the others this.mask = mask | RESOLVE; // Parse the host name. A name has up to three components, the // hostname, a port number, or two numbers representing a port // range. "www.sun.com:8080-9090" is a valid host name. // With IPv6 an address can be 2010:836B:4179::836B:4179 // An IPv6 address needs to be enclose in [] // For ex: [2010:836B:4179::836B:4179]:8080-9090 // Refer to RFC 2732 for more information. int rb = 0 ; int start = 0, end = 0; int sep = -1; String hostport = host; if (host.charAt(0) == '[') { start = 1; rb = host.indexOf(']'); if (rb != -1) { host = host.substring(start, rb); } else { throw new IllegalArgumentException("invalid host/port: "+host); } sep = hostport.indexOf(':', rb+1); } else { start = 0; sep = host.indexOf(':', rb); end = sep; if (sep != -1) { host = host.substring(start, end); } } if (sep != -1) { String port = hostport.substring(sep+1); try { portrange = parsePort(port); } catch (Exception e) { throw new IllegalArgumentException("invalid port range: "+port); } } else { portrange = new int[] { PORT_MIN, PORT_MAX }; } hostname = host; // is this a domain wildcard specification if (host.lastIndexOf('*') > 0) { throw new IllegalArgumentException("invalid host wildcard specification"); } else if (host.startsWith("*")) { wildcard = true; if (host.equals("*")) { cname = ""; } else if (host.startsWith("*.")) { cname = host.substring(1).toLowerCase(); } else { throw new IllegalArgumentException("invalid host wildcard specification"); } return; } else { if (host.length() > 0) { // see if we are being initialized with an IP address. char ch = host.charAt(0); if (ch == ':' || Character.digit(ch, 16) != -1) { byte ip[] = IPAddressUtil.textToNumericFormatV4(host); if (ip == null) { ip = IPAddressUtil.textToNumericFormatV6(host); } if (ip != null) { try { addresses = new InetAddress[] {InetAddress.getByAddress(ip) }; init_with_ip = true; } catch (UnknownHostException uhe) { // this shouldn't happen invalid = true; } } } } } }
Example 4
Source File: SocketPermission.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
/** * Initialize the SocketPermission object. We don't do any DNS lookups * as this point, instead we hold off until the implies method is * called. */ private void init(String host, int mask) { // Set the integer mask that represents the actions if ((mask & ALL) != mask) throw new IllegalArgumentException("invalid actions mask"); // always OR in RESOLVE if we allow any of the others this.mask = mask | RESOLVE; // Parse the host name. A name has up to three components, the // hostname, a port number, or two numbers representing a port // range. "www.sun.com:8080-9090" is a valid host name. // With IPv6 an address can be 2010:836B:4179::836B:4179 // An IPv6 address needs to be enclose in [] // For ex: [2010:836B:4179::836B:4179]:8080-9090 // Refer to RFC 2732 for more information. int rb = 0 ; int start = 0, end = 0; int sep = -1; String hostport = host; if (host.charAt(0) == '[') { start = 1; rb = host.indexOf(']'); if (rb != -1) { host = host.substring(start, rb); } else { throw new IllegalArgumentException("invalid host/port: "+host); } sep = hostport.indexOf(':', rb+1); } else { start = 0; sep = host.indexOf(':', rb); end = sep; if (sep != -1) { host = host.substring(start, end); } } if (sep != -1) { String port = hostport.substring(sep+1); try { portrange = parsePort(port); } catch (Exception e) { throw new IllegalArgumentException("invalid port range: "+port); } } else { portrange = new int[] { PORT_MIN, PORT_MAX }; } hostname = host; // is this a domain wildcard specification if (host.lastIndexOf('*') > 0) { throw new IllegalArgumentException("invalid host wildcard specification"); } else if (host.startsWith("*")) { wildcard = true; if (host.equals("*")) { cname = ""; } else if (host.startsWith("*.")) { cname = host.substring(1).toLowerCase(); } else { throw new IllegalArgumentException("invalid host wildcard specification"); } return; } else { if (host.length() > 0) { // see if we are being initialized with an IP address. char ch = host.charAt(0); if (ch == ':' || Character.digit(ch, 16) != -1) { byte ip[] = IPAddressUtil.textToNumericFormatV4(host); if (ip == null) { ip = IPAddressUtil.textToNumericFormatV6(host); } if (ip != null) { try { addresses = new InetAddress[] {InetAddress.getByAddress(ip) }; init_with_ip = true; } catch (UnknownHostException uhe) { // this shouldn't happen invalid = true; } } } } } }
Example 5
Source File: SocketPermission.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * Initialize the SocketPermission object. We don't do any DNS lookups * as this point, instead we hold off until the implies method is * called. */ private void init(String host, int mask) { // Set the integer mask that represents the actions if ((mask & ALL) != mask) throw new IllegalArgumentException("invalid actions mask"); // always OR in RESOLVE if we allow any of the others this.mask = mask | RESOLVE; // Parse the host name. A name has up to three components, the // hostname, a port number, or two numbers representing a port // range. "www.sun.com:8080-9090" is a valid host name. // With IPv6 an address can be 2010:836B:4179::836B:4179 // An IPv6 address needs to be enclose in [] // For ex: [2010:836B:4179::836B:4179]:8080-9090 // Refer to RFC 2732 for more information. int rb = 0 ; int start = 0, end = 0; int sep = -1; String hostport = host; if (host.charAt(0) == '[') { start = 1; rb = host.indexOf(']'); if (rb != -1) { host = host.substring(start, rb); } else { throw new IllegalArgumentException("invalid host/port: "+host); } sep = hostport.indexOf(':', rb+1); } else { start = 0; sep = host.indexOf(':', rb); end = sep; if (sep != -1) { host = host.substring(start, end); } } if (sep != -1) { String port = hostport.substring(sep+1); try { portrange = parsePort(port); } catch (Exception e) { throw new IllegalArgumentException("invalid port range: "+port); } } else { portrange = new int[] { PORT_MIN, PORT_MAX }; } hostname = host; // is this a domain wildcard specification if (host.lastIndexOf('*') > 0) { throw new IllegalArgumentException("invalid host wildcard specification"); } else if (host.startsWith("*")) { wildcard = true; if (host.equals("*")) { cname = ""; } else if (host.startsWith("*.")) { cname = host.substring(1).toLowerCase(); } else { throw new IllegalArgumentException("invalid host wildcard specification"); } return; } else { if (host.length() > 0) { // see if we are being initialized with an IP address. char ch = host.charAt(0); if (ch == ':' || Character.digit(ch, 16) != -1) { byte ip[] = IPAddressUtil.textToNumericFormatV4(host); if (ip == null) { ip = IPAddressUtil.textToNumericFormatV6(host); } if (ip != null) { try { addresses = new InetAddress[] {InetAddress.getByAddress(ip) }; init_with_ip = true; } catch (UnknownHostException uhe) { // this shouldn't happen invalid = true; } } } } } }
Example 6
Source File: SocketPermission.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
/** * Initialize the SocketPermission object. We don't do any DNS lookups * as this point, instead we hold off until the implies method is * called. */ private void init(String host, int mask) { // Set the integer mask that represents the actions if ((mask & ALL) != mask) throw new IllegalArgumentException("invalid actions mask"); // always OR in RESOLVE if we allow any of the others this.mask = mask | RESOLVE; // Parse the host name. A name has up to three components, the // hostname, a port number, or two numbers representing a port // range. "www.sun.com:8080-9090" is a valid host name. // With IPv6 an address can be 2010:836B:4179::836B:4179 // An IPv6 address needs to be enclose in [] // For ex: [2010:836B:4179::836B:4179]:8080-9090 // Refer to RFC 2732 for more information. int rb = 0 ; int start = 0, end = 0; int sep = -1; String hostport = host; if (host.charAt(0) == '[') { start = 1; rb = host.indexOf(']'); if (rb != -1) { host = host.substring(start, rb); } else { throw new IllegalArgumentException("invalid host/port: "+host); } sep = hostport.indexOf(':', rb+1); } else { start = 0; sep = host.indexOf(':', rb); end = sep; if (sep != -1) { host = host.substring(start, end); } } if (sep != -1) { String port = hostport.substring(sep+1); try { portrange = parsePort(port); } catch (Exception e) { throw new IllegalArgumentException("invalid port range: "+port); } } else { portrange = new int[] { PORT_MIN, PORT_MAX }; } hostname = host; // is this a domain wildcard specification if (host.lastIndexOf('*') > 0) { throw new IllegalArgumentException("invalid host wildcard specification"); } else if (host.startsWith("*")) { wildcard = true; if (host.equals("*")) { cname = ""; } else if (host.startsWith("*.")) { cname = host.substring(1).toLowerCase(); } else { throw new IllegalArgumentException("invalid host wildcard specification"); } return; } else { if (host.length() > 0) { // see if we are being initialized with an IP address. char ch = host.charAt(0); if (ch == ':' || Character.digit(ch, 16) != -1) { byte ip[] = IPAddressUtil.textToNumericFormatV4(host); if (ip == null) { ip = IPAddressUtil.textToNumericFormatV6(host); } if (ip != null) { try { addresses = new InetAddress[] {InetAddress.getByAddress(ip) }; init_with_ip = true; } catch (UnknownHostException uhe) { // this shouldn't happen invalid = true; } } } } } }
Example 7
Source File: SocketPermission.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
/** * Initialize the SocketPermission object. We don't do any DNS lookups * as this point, instead we hold off until the implies method is * called. */ private void init(String host, int mask) { // Set the integer mask that represents the actions if ((mask & ALL) != mask) throw new IllegalArgumentException("invalid actions mask"); // always OR in RESOLVE if we allow any of the others this.mask = mask | RESOLVE; // Parse the host name. A name has up to three components, the // hostname, a port number, or two numbers representing a port // range. "www.sun.com:8080-9090" is a valid host name. // With IPv6 an address can be 2010:836B:4179::836B:4179 // An IPv6 address needs to be enclose in [] // For ex: [2010:836B:4179::836B:4179]:8080-9090 // Refer to RFC 2732 for more information. int rb = 0 ; int start = 0, end = 0; int sep = -1; String hostport = host; if (host.charAt(0) == '[') { start = 1; rb = host.indexOf(']'); if (rb != -1) { host = host.substring(start, rb); } else { throw new IllegalArgumentException("invalid host/port: "+host); } sep = hostport.indexOf(':', rb+1); } else { start = 0; sep = host.indexOf(':', rb); end = sep; if (sep != -1) { host = host.substring(start, end); } } if (sep != -1) { String port = hostport.substring(sep+1); try { portrange = parsePort(port); } catch (Exception e) { throw new IllegalArgumentException("invalid port range: "+port); } } else { portrange = new int[] { PORT_MIN, PORT_MAX }; } hostname = host; // is this a domain wildcard specification if (host.lastIndexOf('*') > 0) { throw new IllegalArgumentException("invalid host wildcard specification"); } else if (host.startsWith("*")) { wildcard = true; if (host.equals("*")) { cname = ""; } else if (host.startsWith("*.")) { cname = host.substring(1).toLowerCase(); } else { throw new IllegalArgumentException("invalid host wildcard specification"); } return; } else { if (host.length() > 0) { // see if we are being initialized with an IP address. char ch = host.charAt(0); if (ch == ':' || Character.digit(ch, 16) != -1) { byte ip[] = IPAddressUtil.textToNumericFormatV4(host); if (ip == null) { ip = IPAddressUtil.textToNumericFormatV6(host); } if (ip != null) { try { addresses = new InetAddress[] {InetAddress.getByAddress(ip) }; init_with_ip = true; } catch (UnknownHostException uhe) { // this shouldn't happen invalid = true; } } } } } }
Example 8
Source File: SocketPermission.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
/** * Initialize the SocketPermission object. We don't do any DNS lookups * as this point, instead we hold off until the implies method is * called. */ private void init(String host, int mask) { // Set the integer mask that represents the actions if ((mask & ALL) != mask) throw new IllegalArgumentException("invalid actions mask"); // always OR in RESOLVE if we allow any of the others this.mask = mask | RESOLVE; // Parse the host name. A name has up to three components, the // hostname, a port number, or two numbers representing a port // range. "www.sun.com:8080-9090" is a valid host name. // With IPv6 an address can be 2010:836B:4179::836B:4179 // An IPv6 address needs to be enclose in [] // For ex: [2010:836B:4179::836B:4179]:8080-9090 // Refer to RFC 2732 for more information. int rb = 0 ; int start = 0, end = 0; int sep = -1; String hostport = host; if (host.charAt(0) == '[') { start = 1; rb = host.indexOf(']'); if (rb != -1) { host = host.substring(start, rb); } else { throw new IllegalArgumentException("invalid host/port: "+host); } sep = hostport.indexOf(':', rb+1); } else { start = 0; sep = host.indexOf(':', rb); end = sep; if (sep != -1) { host = host.substring(start, end); } } if (sep != -1) { String port = hostport.substring(sep+1); try { portrange = parsePort(port); } catch (Exception e) { throw new IllegalArgumentException("invalid port range: "+port); } } else { portrange = new int[] { PORT_MIN, PORT_MAX }; } hostname = host; // is this a domain wildcard specification if (host.lastIndexOf('*') > 0) { throw new IllegalArgumentException("invalid host wildcard specification"); } else if (host.startsWith("*")) { wildcard = true; if (host.equals("*")) { cname = ""; } else if (host.startsWith("*.")) { cname = host.substring(1).toLowerCase(); } else { throw new IllegalArgumentException("invalid host wildcard specification"); } return; } else { if (host.length() > 0) { // see if we are being initialized with an IP address. char ch = host.charAt(0); if (ch == ':' || Character.digit(ch, 16) != -1) { byte ip[] = IPAddressUtil.textToNumericFormatV4(host); if (ip == null) { ip = IPAddressUtil.textToNumericFormatV6(host); } if (ip != null) { try { addresses = new InetAddress[] {InetAddress.getByAddress(ip) }; init_with_ip = true; } catch (UnknownHostException uhe) { // this shouldn't happen invalid = true; } } } } } }
Example 9
Source File: SocketPermission.java From hottub with GNU General Public License v2.0 | 4 votes |
/** * Initialize the SocketPermission object. We don't do any DNS lookups * as this point, instead we hold off until the implies method is * called. */ private void init(String host, int mask) { // Set the integer mask that represents the actions if ((mask & ALL) != mask) throw new IllegalArgumentException("invalid actions mask"); // always OR in RESOLVE if we allow any of the others this.mask = mask | RESOLVE; // Parse the host name. A name has up to three components, the // hostname, a port number, or two numbers representing a port // range. "www.sun.com:8080-9090" is a valid host name. // With IPv6 an address can be 2010:836B:4179::836B:4179 // An IPv6 address needs to be enclose in [] // For ex: [2010:836B:4179::836B:4179]:8080-9090 // Refer to RFC 2732 for more information. int rb = 0 ; int start = 0, end = 0; int sep = -1; String hostport = host; if (host.charAt(0) == '[') { start = 1; rb = host.indexOf(']'); if (rb != -1) { host = host.substring(start, rb); } else { throw new IllegalArgumentException("invalid host/port: "+host); } sep = hostport.indexOf(':', rb+1); } else { start = 0; sep = host.indexOf(':', rb); end = sep; if (sep != -1) { host = host.substring(start, end); } } if (sep != -1) { String port = hostport.substring(sep+1); try { portrange = parsePort(port); } catch (Exception e) { throw new IllegalArgumentException("invalid port range: "+port); } } else { portrange = new int[] { PORT_MIN, PORT_MAX }; } hostname = host; // is this a domain wildcard specification if (host.lastIndexOf('*') > 0) { throw new IllegalArgumentException("invalid host wildcard specification"); } else if (host.startsWith("*")) { wildcard = true; if (host.equals("*")) { cname = ""; } else if (host.startsWith("*.")) { cname = host.substring(1).toLowerCase(); } else { throw new IllegalArgumentException("invalid host wildcard specification"); } return; } else { if (host.length() > 0) { // see if we are being initialized with an IP address. char ch = host.charAt(0); if (ch == ':' || Character.digit(ch, 16) != -1) { byte ip[] = IPAddressUtil.textToNumericFormatV4(host); if (ip == null) { ip = IPAddressUtil.textToNumericFormatV6(host); } if (ip != null) { try { addresses = new InetAddress[] {InetAddress.getByAddress(ip) }; init_with_ip = true; } catch (UnknownHostException uhe) { // this shouldn't happen invalid = true; } } } } } }
Example 10
Source File: SocketPermission.java From Java8CN with Apache License 2.0 | 4 votes |
/** * Initialize the SocketPermission object. We don't do any DNS lookups * as this point, instead we hold off until the implies method is * called. */ private void init(String host, int mask) { // Set the integer mask that represents the actions if ((mask & ALL) != mask) throw new IllegalArgumentException("invalid actions mask"); // always OR in RESOLVE if we allow any of the others this.mask = mask | RESOLVE; // Parse the host name. A name has up to three components, the // hostname, a port number, or two numbers representing a port // range. "www.sun.com:8080-9090" is a valid host name. // With IPv6 an address can be 2010:836B:4179::836B:4179 // An IPv6 address needs to be enclose in [] // For ex: [2010:836B:4179::836B:4179]:8080-9090 // Refer to RFC 2732 for more information. int rb = 0 ; int start = 0, end = 0; int sep = -1; String hostport = host; if (host.charAt(0) == '[') { start = 1; rb = host.indexOf(']'); if (rb != -1) { host = host.substring(start, rb); } else { throw new IllegalArgumentException("invalid host/port: "+host); } sep = hostport.indexOf(':', rb+1); } else { start = 0; sep = host.indexOf(':', rb); end = sep; if (sep != -1) { host = host.substring(start, end); } } if (sep != -1) { String port = hostport.substring(sep+1); try { portrange = parsePort(port); } catch (Exception e) { throw new IllegalArgumentException("invalid port range: "+port); } } else { portrange = new int[] { PORT_MIN, PORT_MAX }; } hostname = host; // is this a domain wildcard specification if (host.lastIndexOf('*') > 0) { throw new IllegalArgumentException("invalid host wildcard specification"); } else if (host.startsWith("*")) { wildcard = true; if (host.equals("*")) { cname = ""; } else if (host.startsWith("*.")) { cname = host.substring(1).toLowerCase(); } else { throw new IllegalArgumentException("invalid host wildcard specification"); } return; } else { if (host.length() > 0) { // see if we are being initialized with an IP address. char ch = host.charAt(0); if (ch == ':' || Character.digit(ch, 16) != -1) { byte ip[] = IPAddressUtil.textToNumericFormatV4(host); if (ip == null) { ip = IPAddressUtil.textToNumericFormatV6(host); } if (ip != null) { try { addresses = new InetAddress[] {InetAddress.getByAddress(ip) }; init_with_ip = true; } catch (UnknownHostException uhe) { // this shouldn't happen invalid = true; } } } } } }
Example 11
Source File: SocketPermission.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * Initialize the SocketPermission object. We don't do any DNS lookups * as this point, instead we hold off until the implies method is * called. */ private void init(String host, int mask) { // Set the integer mask that represents the actions if ((mask & ALL) != mask) throw new IllegalArgumentException("invalid actions mask"); // always OR in RESOLVE if we allow any of the others this.mask = mask | RESOLVE; // Parse the host name. A name has up to three components, the // hostname, a port number, or two numbers representing a port // range. "www.sun.com:8080-9090" is a valid host name. // With IPv6 an address can be 2010:836B:4179::836B:4179 // An IPv6 address needs to be enclose in [] // For ex: [2010:836B:4179::836B:4179]:8080-9090 // Refer to RFC 2732 for more information. int rb = 0 ; int start = 0, end = 0; int sep = -1; String hostport = host; if (host.charAt(0) == '[') { start = 1; rb = host.indexOf(']'); if (rb != -1) { host = host.substring(start, rb); } else { throw new IllegalArgumentException("invalid host/port: "+host); } sep = hostport.indexOf(':', rb+1); } else { start = 0; sep = host.indexOf(':', rb); end = sep; if (sep != -1) { host = host.substring(start, end); } } if (sep != -1) { String port = hostport.substring(sep+1); try { portrange = parsePort(port); } catch (Exception e) { throw new IllegalArgumentException("invalid port range: "+port); } } else { portrange = new int[] { PORT_MIN, PORT_MAX }; } hostname = host; // is this a domain wildcard specification if (host.lastIndexOf('*') > 0) { throw new IllegalArgumentException("invalid host wildcard specification"); } else if (host.startsWith("*")) { wildcard = true; if (host.equals("*")) { cname = ""; } else if (host.startsWith("*.")) { cname = host.substring(1).toLowerCase(); } else { throw new IllegalArgumentException("invalid host wildcard specification"); } return; } else { if (host.length() > 0) { // see if we are being initialized with an IP address. char ch = host.charAt(0); if (ch == ':' || Character.digit(ch, 16) != -1) { byte ip[] = IPAddressUtil.textToNumericFormatV4(host); if (ip == null) { ip = IPAddressUtil.textToNumericFormatV6(host); } if (ip != null) { try { addresses = new InetAddress[] {InetAddress.getByAddress(ip) }; init_with_ip = true; } catch (UnknownHostException uhe) { // this shouldn't happen invalid = true; } } } } } }
Example 12
Source File: SocketPermission.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * Initialize the SocketPermission object. We don't do any DNS lookups * as this point, instead we hold off until the implies method is * called. */ private void init(String host, int mask) { // Set the integer mask that represents the actions if ((mask & ALL) != mask) throw new IllegalArgumentException("invalid actions mask"); // always OR in RESOLVE if we allow any of the others this.mask = mask | RESOLVE; // Parse the host name. A name has up to three components, the // hostname, a port number, or two numbers representing a port // range. "www.sun.com:8080-9090" is a valid host name. // With IPv6 an address can be 2010:836B:4179::836B:4179 // An IPv6 address needs to be enclose in [] // For ex: [2010:836B:4179::836B:4179]:8080-9090 // Refer to RFC 2732 for more information. int rb = 0 ; int start = 0, end = 0; int sep = -1; String hostport = host; if (host.charAt(0) == '[') { start = 1; rb = host.indexOf(']'); if (rb != -1) { host = host.substring(start, rb); } else { throw new IllegalArgumentException("invalid host/port: "+host); } sep = hostport.indexOf(':', rb+1); } else { start = 0; sep = host.indexOf(':', rb); end = sep; if (sep != -1) { host = host.substring(start, end); } } if (sep != -1) { String port = hostport.substring(sep+1); try { portrange = parsePort(port); } catch (Exception e) { throw new IllegalArgumentException("invalid port range: "+port); } } else { portrange = new int[] { PORT_MIN, PORT_MAX }; } hostname = host; // is this a domain wildcard specification if (host.lastIndexOf('*') > 0) { throw new IllegalArgumentException("invalid host wildcard specification"); } else if (host.startsWith("*")) { wildcard = true; if (host.equals("*")) { cname = ""; } else if (host.startsWith("*.")) { cname = host.substring(1).toLowerCase(); } else { throw new IllegalArgumentException("invalid host wildcard specification"); } return; } else { if (host.length() > 0) { // see if we are being initialized with an IP address. char ch = host.charAt(0); if (ch == ':' || Character.digit(ch, 16) != -1) { byte ip[] = IPAddressUtil.textToNumericFormatV4(host); if (ip == null) { ip = IPAddressUtil.textToNumericFormatV6(host); } if (ip != null) { try { addresses = new InetAddress[] {InetAddress.getByAddress(ip) }; init_with_ip = true; } catch (UnknownHostException uhe) { // this shouldn't happen invalid = true; } } } } } }
Example 13
Source File: SocketPermission.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * Initialize the SocketPermission object. We don't do any DNS lookups * as this point, instead we hold off until the implies method is * called. */ private void init(String host, int mask) { // Set the integer mask that represents the actions if ((mask & ALL) != mask) throw new IllegalArgumentException("invalid actions mask"); // always OR in RESOLVE if we allow any of the others this.mask = mask | RESOLVE; // Parse the host name. A name has up to three components, the // hostname, a port number, or two numbers representing a port // range. "www.example.com:8080-9090" is a valid host name. // With IPv6 an address can be 2010:836B:4179::836B:4179 // An IPv6 address needs to be enclose in [] // For ex: [2010:836B:4179::836B:4179]:8080-9090 // Refer to RFC 2732 for more information. int rb = 0 ; int start = 0, end = 0; int sep = -1; String hostport = host; if (host.charAt(0) == '[') { start = 1; rb = host.indexOf(']'); if (rb != -1) { host = host.substring(start, rb); } else { throw new IllegalArgumentException("invalid host/port: "+host); } sep = hostport.indexOf(':', rb+1); } else { start = 0; sep = host.indexOf(':', rb); end = sep; if (sep != -1) { host = host.substring(start, end); } } if (sep != -1) { String port = hostport.substring(sep+1); try { portrange = parsePort(port); } catch (Exception e) { throw new IllegalArgumentException("invalid port range: "+port); } } else { portrange = new int[] { PORT_MIN, PORT_MAX }; } hostname = host; // is this a domain wildcard specification if (host.lastIndexOf('*') > 0) { throw new IllegalArgumentException("invalid host wildcard specification"); } else if (host.startsWith("*")) { wildcard = true; if (host.equals("*")) { cname = ""; } else if (host.startsWith("*.")) { cname = host.substring(1).toLowerCase(); } else { throw new IllegalArgumentException("invalid host wildcard specification"); } return; } else { if (!host.isEmpty()) { // see if we are being initialized with an IP address. char ch = host.charAt(0); if (ch == ':' || Character.digit(ch, 16) != -1) { byte ip[] = IPAddressUtil.textToNumericFormatV4(host); if (ip == null) { ip = IPAddressUtil.textToNumericFormatV6(host); } if (ip != null) { try { addresses = new InetAddress[] {InetAddress.getByAddress(ip) }; init_with_ip = true; } catch (UnknownHostException uhe) { // this shouldn't happen invalid = true; } } } } } }
Example 14
Source File: SocketPermission.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
/** * Initialize the SocketPermission object. We don't do any DNS lookups * as this point, instead we hold off until the implies method is * called. */ private void init(String host, int mask) { // Set the integer mask that represents the actions if ((mask & ALL) != mask) throw new IllegalArgumentException("invalid actions mask"); // always OR in RESOLVE if we allow any of the others this.mask = mask | RESOLVE; // Parse the host name. A name has up to three components, the // hostname, a port number, or two numbers representing a port // range. "www.sun.com:8080-9090" is a valid host name. // With IPv6 an address can be 2010:836B:4179::836B:4179 // An IPv6 address needs to be enclose in [] // For ex: [2010:836B:4179::836B:4179]:8080-9090 // Refer to RFC 2732 for more information. int rb = 0 ; int start = 0, end = 0; int sep = -1; String hostport = host; if (host.charAt(0) == '[') { start = 1; rb = host.indexOf(']'); if (rb != -1) { host = host.substring(start, rb); } else { throw new IllegalArgumentException("invalid host/port: "+host); } sep = hostport.indexOf(':', rb+1); } else { start = 0; sep = host.indexOf(':', rb); end = sep; if (sep != -1) { host = host.substring(start, end); } } if (sep != -1) { String port = hostport.substring(sep+1); try { portrange = parsePort(port); } catch (Exception e) { throw new IllegalArgumentException("invalid port range: "+port); } } else { portrange = new int[] { PORT_MIN, PORT_MAX }; } hostname = host; // is this a domain wildcard specification if (host.lastIndexOf('*') > 0) { throw new IllegalArgumentException("invalid host wildcard specification"); } else if (host.startsWith("*")) { wildcard = true; if (host.equals("*")) { cname = ""; } else if (host.startsWith("*.")) { cname = host.substring(1).toLowerCase(); } else { throw new IllegalArgumentException("invalid host wildcard specification"); } return; } else { if (host.length() > 0) { // see if we are being initialized with an IP address. char ch = host.charAt(0); if (ch == ':' || Character.digit(ch, 16) != -1) { byte ip[] = IPAddressUtil.textToNumericFormatV4(host); if (ip == null) { ip = IPAddressUtil.textToNumericFormatV6(host); } if (ip != null) { try { addresses = new InetAddress[] {InetAddress.getByAddress(ip) }; init_with_ip = true; } catch (UnknownHostException uhe) { // this shouldn't happen invalid = true; } } } } } }
Example 15
Source File: SocketPermission.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * Initialize the SocketPermission object. We don't do any DNS lookups * as this point, instead we hold off until the implies method is * called. */ private void init(String host, int mask) { // Set the integer mask that represents the actions if ((mask & ALL) != mask) throw new IllegalArgumentException("invalid actions mask"); // always OR in RESOLVE if we allow any of the others this.mask = mask | RESOLVE; // Parse the host name. A name has up to three components, the // hostname, a port number, or two numbers representing a port // range. "www.sun.com:8080-9090" is a valid host name. // With IPv6 an address can be 2010:836B:4179::836B:4179 // An IPv6 address needs to be enclose in [] // For ex: [2010:836B:4179::836B:4179]:8080-9090 // Refer to RFC 2732 for more information. int rb = 0 ; int start = 0, end = 0; int sep = -1; String hostport = host; if (host.charAt(0) == '[') { start = 1; rb = host.indexOf(']'); if (rb != -1) { host = host.substring(start, rb); } else { throw new IllegalArgumentException("invalid host/port: "+host); } sep = hostport.indexOf(':', rb+1); } else { start = 0; sep = host.indexOf(':', rb); end = sep; if (sep != -1) { host = host.substring(start, end); } } if (sep != -1) { String port = hostport.substring(sep+1); try { portrange = parsePort(port); } catch (Exception e) { throw new IllegalArgumentException("invalid port range: "+port); } } else { portrange = new int[] { PORT_MIN, PORT_MAX }; } hostname = host; // is this a domain wildcard specification if (host.lastIndexOf('*') > 0) { throw new IllegalArgumentException("invalid host wildcard specification"); } else if (host.startsWith("*")) { wildcard = true; if (host.equals("*")) { cname = ""; } else if (host.startsWith("*.")) { cname = host.substring(1).toLowerCase(); } else { throw new IllegalArgumentException("invalid host wildcard specification"); } return; } else { if (host.length() > 0) { // see if we are being initialized with an IP address. char ch = host.charAt(0); if (ch == ':' || Character.digit(ch, 16) != -1) { byte ip[] = IPAddressUtil.textToNumericFormatV4(host); if (ip == null) { ip = IPAddressUtil.textToNumericFormatV6(host); } if (ip != null) { try { addresses = new InetAddress[] {InetAddress.getByAddress(ip) }; init_with_ip = true; } catch (UnknownHostException uhe) { // this shouldn't happen invalid = true; } } } } } }
Example 16
Source File: SocketPermission.java From JDKSourceCode1.8 with MIT License | 4 votes |
/** * Initialize the SocketPermission object. We don't do any DNS lookups * as this point, instead we hold off until the implies method is * called. */ private void init(String host, int mask) { // Set the integer mask that represents the actions if ((mask & ALL) != mask) throw new IllegalArgumentException("invalid actions mask"); // always OR in RESOLVE if we allow any of the others this.mask = mask | RESOLVE; // Parse the host name. A name has up to three components, the // hostname, a port number, or two numbers representing a port // range. "www.sun.com:8080-9090" is a valid host name. // With IPv6 an address can be 2010:836B:4179::836B:4179 // An IPv6 address needs to be enclose in [] // For ex: [2010:836B:4179::836B:4179]:8080-9090 // Refer to RFC 2732 for more information. int rb = 0 ; int start = 0, end = 0; int sep = -1; String hostport = host; if (host.charAt(0) == '[') { start = 1; rb = host.indexOf(']'); if (rb != -1) { host = host.substring(start, rb); } else { throw new IllegalArgumentException("invalid host/port: "+host); } sep = hostport.indexOf(':', rb+1); } else { start = 0; sep = host.indexOf(':', rb); end = sep; if (sep != -1) { host = host.substring(start, end); } } if (sep != -1) { String port = hostport.substring(sep+1); try { portrange = parsePort(port); } catch (Exception e) { throw new IllegalArgumentException("invalid port range: "+port); } } else { portrange = new int[] { PORT_MIN, PORT_MAX }; } hostname = host; // is this a domain wildcard specification if (host.lastIndexOf('*') > 0) { throw new IllegalArgumentException("invalid host wildcard specification"); } else if (host.startsWith("*")) { wildcard = true; if (host.equals("*")) { cname = ""; } else if (host.startsWith("*.")) { cname = host.substring(1).toLowerCase(); } else { throw new IllegalArgumentException("invalid host wildcard specification"); } return; } else { if (host.length() > 0) { // see if we are being initialized with an IP address. char ch = host.charAt(0); if (ch == ':' || Character.digit(ch, 16) != -1) { byte ip[] = IPAddressUtil.textToNumericFormatV4(host); if (ip == null) { ip = IPAddressUtil.textToNumericFormatV6(host); } if (ip != null) { try { addresses = new InetAddress[] {InetAddress.getByAddress(ip) }; init_with_ip = true; } catch (UnknownHostException uhe) { // this shouldn't happen invalid = true; } } } } } }
Example 17
Source File: SocketPermission.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
/** * Initialize the SocketPermission object. We don't do any DNS lookups * as this point, instead we hold off until the implies method is * called. */ private void init(String host, int mask) { // Set the integer mask that represents the actions if ((mask & ALL) != mask) throw new IllegalArgumentException("invalid actions mask"); // always OR in RESOLVE if we allow any of the others this.mask = mask | RESOLVE; // Parse the host name. A name has up to three components, the // hostname, a port number, or two numbers representing a port // range. "www.sun.com:8080-9090" is a valid host name. // With IPv6 an address can be 2010:836B:4179::836B:4179 // An IPv6 address needs to be enclose in [] // For ex: [2010:836B:4179::836B:4179]:8080-9090 // Refer to RFC 2732 for more information. int rb = 0 ; int start = 0, end = 0; int sep = -1; String hostport = host; if (host.charAt(0) == '[') { start = 1; rb = host.indexOf(']'); if (rb != -1) { host = host.substring(start, rb); } else { throw new IllegalArgumentException("invalid host/port: "+host); } sep = hostport.indexOf(':', rb+1); } else { start = 0; sep = host.indexOf(':', rb); end = sep; if (sep != -1) { host = host.substring(start, end); } } if (sep != -1) { String port = hostport.substring(sep+1); try { portrange = parsePort(port); } catch (Exception e) { throw new IllegalArgumentException("invalid port range: "+port); } } else { portrange = new int[] { PORT_MIN, PORT_MAX }; } hostname = host; // is this a domain wildcard specification if (host.lastIndexOf('*') > 0) { throw new IllegalArgumentException("invalid host wildcard specification"); } else if (host.startsWith("*")) { wildcard = true; if (host.equals("*")) { cname = ""; } else if (host.startsWith("*.")) { cname = host.substring(1).toLowerCase(); } else { throw new IllegalArgumentException("invalid host wildcard specification"); } return; } else { if (host.length() > 0) { // see if we are being initialized with an IP address. char ch = host.charAt(0); if (ch == ':' || Character.digit(ch, 16) != -1) { byte ip[] = IPAddressUtil.textToNumericFormatV4(host); if (ip == null) { ip = IPAddressUtil.textToNumericFormatV6(host); } if (ip != null) { try { addresses = new InetAddress[] {InetAddress.getByAddress(ip) }; init_with_ip = true; } catch (UnknownHostException uhe) { // this shouldn't happen invalid = true; } } } } } }
Example 18
Source File: Reader.java From ipdb-java with Apache License 2.0 | 4 votes |
public String[] find(String addr, String language) throws IPFormatException, InvalidDatabaseException { int off; try { off = this.meta.Languages.get(language); } catch (NullPointerException e) { return null; } byte[] ipv; if (addr.indexOf(":") > 0) { ipv = IPAddressUtil.textToNumericFormatV6(addr); if (ipv == null) { throw new IPFormatException("ipv6 format error"); } if ((this.meta.IPVersion & 0x02) != 0x02){ throw new IPFormatException("no support ipv6"); } } else if (addr.indexOf(".") > 0) { ipv = IPAddressUtil.textToNumericFormatV4(addr); if (ipv == null) { throw new IPFormatException("ipv4 format error"); } if ((this.meta.IPVersion & 0x01) != 0x01){ throw new IPFormatException("no support ipv4"); } } else { throw new IPFormatException("ip format error"); } int node = 0; try { node = this.findNode(ipv); } catch (NotFoundException nfe) { return null; } final String data = this.resolve(node); return Arrays.copyOfRange(data.split("\t", this.meta.Fields.length * this.meta.Languages.size()), off, off+this.meta.Fields.length); }
Example 19
Source File: SocketPermission.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * Initialize the SocketPermission object. We don't do any DNS lookups * as this point, instead we hold off until the implies method is * called. */ private void init(String host, int mask) { // Set the integer mask that represents the actions if ((mask & ALL) != mask) throw new IllegalArgumentException("invalid actions mask"); // always OR in RESOLVE if we allow any of the others this.mask = mask | RESOLVE; // Parse the host name. A name has up to three components, the // hostname, a port number, or two numbers representing a port // range. "www.sun.com:8080-9090" is a valid host name. // With IPv6 an address can be 2010:836B:4179::836B:4179 // An IPv6 address needs to be enclose in [] // For ex: [2010:836B:4179::836B:4179]:8080-9090 // Refer to RFC 2732 for more information. int rb = 0 ; int start = 0, end = 0; int sep = -1; String hostport = host; if (host.charAt(0) == '[') { start = 1; rb = host.indexOf(']'); if (rb != -1) { host = host.substring(start, rb); } else { throw new IllegalArgumentException("invalid host/port: "+host); } sep = hostport.indexOf(':', rb+1); } else { start = 0; sep = host.indexOf(':', rb); end = sep; if (sep != -1) { host = host.substring(start, end); } } if (sep != -1) { String port = hostport.substring(sep+1); try { portrange = parsePort(port); } catch (Exception e) { throw new IllegalArgumentException("invalid port range: "+port); } } else { portrange = new int[] { PORT_MIN, PORT_MAX }; } hostname = host; // is this a domain wildcard specification if (host.lastIndexOf('*') > 0) { throw new IllegalArgumentException("invalid host wildcard specification"); } else if (host.startsWith("*")) { wildcard = true; if (host.equals("*")) { cname = ""; } else if (host.startsWith("*.")) { cname = host.substring(1).toLowerCase(); } else { throw new IllegalArgumentException("invalid host wildcard specification"); } return; } else { if (host.length() > 0) { // see if we are being initialized with an IP address. char ch = host.charAt(0); if (ch == ':' || Character.digit(ch, 16) != -1) { byte ip[] = IPAddressUtil.textToNumericFormatV4(host); if (ip == null) { ip = IPAddressUtil.textToNumericFormatV6(host); } if (ip != null) { try { addresses = new InetAddress[] {InetAddress.getByAddress(ip) }; init_with_ip = true; } catch (UnknownHostException uhe) { // this shouldn't happen invalid = true; } } } } } }
Example 20
Source File: SocketPermission.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
/** * Initialize the SocketPermission object. We don't do any DNS lookups * as this point, instead we hold off until the implies method is * called. */ private void init(String host, int mask) { // Set the integer mask that represents the actions if ((mask & ALL) != mask) throw new IllegalArgumentException("invalid actions mask"); // always OR in RESOLVE if we allow any of the others this.mask = mask | RESOLVE; // Parse the host name. A name has up to three components, the // hostname, a port number, or two numbers representing a port // range. "www.sun.com:8080-9090" is a valid host name. // With IPv6 an address can be 2010:836B:4179::836B:4179 // An IPv6 address needs to be enclose in [] // For ex: [2010:836B:4179::836B:4179]:8080-9090 // Refer to RFC 2732 for more information. int rb = 0 ; int start = 0, end = 0; int sep = -1; String hostport = host; if (host.charAt(0) == '[') { start = 1; rb = host.indexOf(']'); if (rb != -1) { host = host.substring(start, rb); } else { throw new IllegalArgumentException("invalid host/port: "+host); } sep = hostport.indexOf(':', rb+1); } else { start = 0; sep = host.indexOf(':', rb); end = sep; if (sep != -1) { host = host.substring(start, end); } } if (sep != -1) { String port = hostport.substring(sep+1); try { portrange = parsePort(port); } catch (Exception e) { throw new IllegalArgumentException("invalid port range: "+port); } } else { portrange = new int[] { PORT_MIN, PORT_MAX }; } hostname = host; // is this a domain wildcard specification if (host.lastIndexOf('*') > 0) { throw new IllegalArgumentException("invalid host wildcard specification"); } else if (host.startsWith("*")) { wildcard = true; if (host.equals("*")) { cname = ""; } else if (host.startsWith("*.")) { cname = host.substring(1).toLowerCase(); } else { throw new IllegalArgumentException("invalid host wildcard specification"); } return; } else { if (host.length() > 0) { // see if we are being initialized with an IP address. char ch = host.charAt(0); if (ch == ':' || Character.digit(ch, 16) != -1) { byte ip[] = IPAddressUtil.textToNumericFormatV4(host); if (ip == null) { ip = IPAddressUtil.textToNumericFormatV6(host); } if (ip != null) { try { addresses = new InetAddress[] {InetAddress.getByAddress(ip) }; init_with_ip = true; } catch (UnknownHostException uhe) { // this shouldn't happen invalid = true; } } } } } }