Ejemplo n.º 1
0
function gethostbynamel6($host, $try_a = false)
{
    // get AAAA records for $host,
    // if $try_a is true, if AAAA fails, it tries for A
    // results are returned in an array of ips found matching type
    // otherwise returns false
    $ip6 = array();
    $ip4 = array();
    // First try /etc/hosts
    /// FIXME. Mike: it is necessary to use nsswitch, but I yet didn't think up as.
    $etc = ipFromEtcHosts($host);
    if ($etc && strstr($etc, ':')) {
        $ip6[] = $etc;
    }
    if ($try_a == true) {
        if ($etc && strstr($etc, '.')) {
            $ip4[] = $etc;
        }
        $dns = dns_get_record($host, DNS_A + DNS_AAAA);
    } else {
        $dns = dns_get_record($host, DNS_AAAA);
    }
    foreach ($dns as $record) {
        switch ($record['type']) {
            case 'A':
                $ip4[] = $record['ip'];
                break;
            case 'AAAA':
                $ip6[] = $record['ipv6'];
                break;
        }
    }
    if (count($ip6) < 1) {
        if ($try_a == true) {
            if (count($ip4) < 1) {
                return false;
            } else {
                return $ip4;
            }
        } else {
            return false;
        }
    } else {
        return $ip6;
    }
}
Ejemplo n.º 2
0
function gethostbynamel6($host, $try_a = TRUE)
{
    // get AAAA records for $host,
    // if $try_a is true, if AAAA fails, it tries for A
    // results are returned in an array of ips found matching type
    // otherwise returns FALSE
    $ip6 = array();
    $ip4 = array();
    // First try /etc/hosts
    $etc = ipFromEtcHosts($host);
    if ($try_a == TRUE) {
        if ($etc && strstr($etc, '.')) {
            $ip4[] = $etc;
        }
        $dns = dns_get_record($host, DNS_A + DNS_AAAA);
    } else {
        if ($etc && strstr($etc, ':')) {
            $ip6[] = $etc;
        }
        $dns = dns_get_record($host, DNS_AAAA);
    }
    foreach ($dns as $record) {
        switch ($record['type']) {
            case 'A':
                $ip4[] = $record['ip'];
                break;
            case 'AAAA':
                $ip6[] = $record['ipv6'];
                break;
        }
    }
    if ($try_a && count($ip4)) {
        // Merge ipv4 & ipv6
        $ip6 = array_merge($ip4, $ip6);
    }
    if (count($ip6)) {
        return $ip6;
    }
    return FALSE;
}
Ejemplo n.º 3
0
function gethostbynamel6($host, $try_a = TRUE)
{
    // get AAAA records for $host,
    // if $try_a is true, if AAAA fails, it tries for A
    // results are returned in an array of ips found matching type
    // otherwise returns FALSE
    $ip6 = array();
    $ip4 = array();
    // First try /etc/hosts
    $etc = ipFromEtcHosts($host);
    if ($try_a == TRUE) {
        if ($etc && strstr($etc, '.')) {
            $ip4[] = $etc;
        }
        // Separate A and AAAA queries, see: https://www.mail-archive.com/observium@observium.org/msg09239.html
        $dns = dns_get_record($host, DNS_A);
        if (!is_array($dns)) {
            $dns = array();
        }
        $dns6 = dns_get_record($host, DNS_AAAA);
        if (is_array($dns6)) {
            $dns = array_merge($dns, $dns6);
        }
    } else {
        if ($etc && strstr($etc, ':')) {
            $ip6[] = $etc;
        }
        $dns = dns_get_record($host, DNS_AAAA);
    }
    foreach ($dns as $record) {
        switch ($record['type']) {
            case 'A':
                $ip4[] = $record['ip'];
                break;
            case 'AAAA':
                $ip6[] = $record['ipv6'];
                break;
        }
    }
    if ($try_a && count($ip4)) {
        // Merge ipv4 & ipv6
        $ip6 = array_merge($ip4, $ip6);
    }
    if (count($ip6)) {
        return $ip6;
    }
    return FALSE;
}