Make Dns::getSrvRecors being more generic

The `target' property of a returned service record is too specific and causes
other properties being ignored.
This commit is contained in:
Matthias Jentsch 2014-10-09 10:19:21 +02:00 committed by Johannes Meyer
parent dd21b7b5d1
commit df69fd2264
1 changed files with 2 additions and 12 deletions

View File

@ -9,7 +9,6 @@ namespace Icinga\Protocol;
*/ */
class Dns class Dns
{ {
/** /**
* Discover all service records on a given domain * Discover all service records on a given domain
* *
@ -17,21 +16,12 @@ class Dns
* @param string $service The type of the service, like for example 'ldaps' or 'ldap' * @param string $service The type of the service, like for example 'ldaps' or 'ldap'
* @param string $protocol The transport protocol used by the service, defaults to 'tcp' * @param string $protocol The transport protocol used by the service, defaults to 'tcp'
* *
* @return array|null An array of all service domains * @return array An array of all found service records
*/ */
public static function getSrvRecords($domain, $service, $protocol = 'tcp') public static function getSrvRecords($domain, $service, $protocol = 'tcp')
{ {
$records = dns_get_record('_' . $service . '._' . $protocol . '.' . $domain, DNS_SRV); $records = dns_get_record('_' . $service . '._' . $protocol . '.' . $domain, DNS_SRV);
if ($records === false) { return $records === false ? array() : $records;
return null;
}
$targets = array();
foreach ($records as $record) {
if (array_key_exists('target', $record)) {
$targets[] = $record['target'];
}
}
return $targets;
} }
/** /**