Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support resolving from default hosts file #75

Merged
merged 10 commits into from
Aug 18, 2017
2 changes: 1 addition & 1 deletion src/Query/HostsFileExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private function getIpFromHost($host)
return inet_ntop(strrev($ip));
} elseif (substr($host, -9) === '.ip6.arpa') {
// IPv6: replace dots, reverse nibbles and interpret as hexadecimal string
$ip = @inet_ntop(hex2bin(strrev(str_replace('.', '', substr($host, 0, -9)))));
$ip = @inet_ntop(pack('H*', strrev(str_replace('.', '', substr($host, 0, -9)))));
clue marked this conversation as resolved.
Show resolved Hide resolved
if ($ip === false) {
return null;
}
Expand Down
10 changes: 9 additions & 1 deletion tests/Query/HostsFileExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,19 @@ public function testReverseFallsBackForInvalidIpv4Address()
$this->executor->query('8.8.8.8', new Query('::1.in-addr.arpa', Message::TYPE_PTR, Message::CLASS_IN, 0));
}

public function testReverseFallsBackForInvalidIpv6Address()
public function testReverseFallsBackForInvalidLengthIpv6Address()
{
$this->hosts->expects($this->never())->method('getHostsForIp');
$this->fallback->expects($this->once())->method('query');

$this->executor->query('8.8.8.8', new Query('abcd.ip6.arpa', Message::TYPE_PTR, Message::CLASS_IN, 0));
}

public function testReverseFallsBackForInvalidHexIpv6Address()
{
$this->hosts->expects($this->never())->method('getHostsForIp');
$this->fallback->expects($this->once())->method('query');

$this->executor->query('8.8.8.8', new Query('zZz.ip6.arpa', Message::TYPE_PTR, Message::CLASS_IN, 0));
}
}