/** * Given the name of a host, returns an array of its IP addresses, * based on the configured name service on the system. * * <p> The host name can either be a machine name, such as * '<code>java.sun.com</code>', or a textual representation of its IP * address. If a literal IP address is supplied, only the * validity of the address format is checked. * * <p> For <code>host</code> specified in <i>literal IPv6 address</i>, * either the form defined in RFC 2732 or the literal IPv6 address * format defined in RFC 2373 is accepted. A literal IPv6 address may * also be qualified by appending a scoped zone identifier or scope_id. * The syntax and usage of scope_ids is described * <a href='Inet6Address.html#scoped'>here</a>. * <p> If the host is <tt>null</tt> then an <tt>InetAddress</tt> * representing an address of the loopback interface is returned. * See <a href='http://www.ietf.org/rfc/rfc3330.txt'>RFC 3330</a> * section 2 and <a href='http://www.ietf.org/rfc/rfc2373.txt'>RFC 2373</a> * section 2.5.3. </p> * * <p> If there is a security manager and <code>host</code> is not * null and <code>host.length() </code> is not equal to zero, the * security manager's * <code>checkConnect</code> method is called * with the hostname and <code>-1</code> * as its arguments to see if the operation is allowed. * * @param host the name of the host, or <code>null</code>. * @return array[InetAddress] an array of all the IP addresses for a given host name. * * @exception UnknownHostException if no IP address for the * <code>host</code> could be found, or if a scope_id was specified * for a global IPv6 address. * @exception SecurityException if a security manager exists and its * <code>checkConnect</code> method doesn't allow the operation. * * @see SecurityManager#checkConnect */ public static function getAllByName($host, InetAddress $reqAddr = null) { $host = \blaze\lang\String::asWrapper($host); if ($host->length() == 0) { $ret = new \blaze\collections\arrays\ArrayObject(1); $ret[0] = $impl->loopbackAddress(); return $ret; } $ipv6Expected = false; if ($host->charAt(0) == '[') { // This is supposed to be an IPv6 litteral if ($host->length() > 2 && $host->charAt($host->length() - 1) == ']') { $host = $host->substring(1, $host->length() - 1); $ipv6Expected = true; } else { // This was supposed to be a IPv6 address, but it's not! // throw new UnknownHostException(4host); } } // if host is an IP address, we won't do further lookup if (\blaze\lang\Character::digit($host->charAt(0), 16) != -1 || $host->charAt(0) == ':') { $addr = null; $numericZone = -1; $ifname = null; // see if it is IPv4 address $addr = self::textToNumericFormatV4($host); if ($addr == null) { // see if it is IPv6 address // Check if a numeric or string zone id is present if (($pos = $host->indexOf('%')) != -1) { $numericZone = $self::checkNumericZone($host); if ($numericZone == -1) { /* remainder of string must be an ifname */ $ifname = $host->substring($pos + 1); } } $addr = IPAddressUtil::textToNumericFormatV6($host); } else { if ($ipv6Expected) { // Means an IPv4 litteral between brackets! // throw new UnknownHostException('['+host+']'); } } $ret = new ArrayObject(1); if ($addr != null) { if ($addr->length == Inet4Address::INADDRSZ) { $ret[0] = new Inet4Address(null, $addr); } else { if ($ifname != null) { $ret[0] = new Inet6Address(null, $addr, $ifname); } else { $ret[0] = new Inet6Address(null, $addr, $numericZone); } } return $ret; } } else { if ($ipv6Expected) { // We were expecting an IPv6 Litteral, but got something else // throw new UnknownHostException('['+host+']'); } } return self::getAllByName0($host, $reqAddr, true); }
private function checkId($id) { if ($id == null) { return; } $str = \blaze\lang\String::asNative($id); if (strlen($str) == 0) { throw new \blaze\lang\IllegalArgumentException('Component id must have a length of at least one character'); } $firstChar = $str[0]; if ($firstChar != '_' && !\blaze\lang\Character::isLetter($firstChar)) { throw new \blaze\lang\IllegalArgumentException('Component id\'s first character must be a letter or underscore (_) and not ' . $firstChar); } if (!preg_match('/^..[a-zA-Z0-9\\-\\_]*$/', $str)) { throw new \blaze\lang\IllegalArgumentException('Component id\'s may only contain digits, letters, underscores(_) and dashes(-)'); } }