remotelyliving / php-dns

A DNS abstraction for PHP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SRV records

joeh opened this issue · comments

Describe the bug
SRV lookups fail with:
RemotelyLiving\PHPDNS\Exceptions\InvalidArgumentException : 0 sipfed.microsoft.com could not be created with type SRV

To Reproduce
$hostname = '_sipfederationtls._tcp.microsoft.com'; $records = $resolver->getRecords($hostname, \RemotelyLiving\PHPDNS\Entities\DNSRecordType::TYPE_SRV);

Expected behavior
nslookup returns:
Non-authoritative answer: _sipfederationtls._tcp.microsoft.com SRV service location: priority = 0 weight = 0 port = 5061 svr hostname = sipfed.microsoft.com
It looks like createFromTypeAndString only handles TXT, NS, CNAME, MX, CAA and SOA records.

if I edit DataAbstract.php to add:
if ($recordType->isA(DNSRecordType::TYPE_SRV)) { return new TXTData($data); }
I see some of the data I am looking for.

I took the TXTData.php and mocked up a SRVData.php file that works and added
if ($recordType->isA(DNSRecordType::TYPE_SRV)) { return new SRVData( $parsed[0] ?? 0, new Hostname($parsed[1]), $parsed[2] ?? 0, $data ); }

Which I think works.

Is this the right direction? Or am I missing something obvious?

Hi @joeh, thanks for reporting this and yes, you're on the right track! If you want to submit a PR that would be great, otherwise I can probably get to this sometime today or tomorrow. Thanks!

I can submit a pull request, but I should warn you that it will be pretty rough. Still, it should save you some typing at least.

Updated PR: #25