Skip to content

Commit

Permalink
Fix for Issue #14
Browse files Browse the repository at this point in the history
  • Loading branch information
metaregistrar committed Oct 31, 2022
1 parent 05990b4 commit d635cda
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
15 changes: 6 additions & 9 deletions DNS/dnsProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ function Query($question,$type='A')
}

$this->rawheader=substr($this->rawbuffer,0,12); // first 12 bytes is the header
$this->rawresponse=substr($this->rawbuffer,12); // after that the response
#$this->rawresponse=substr($this->rawbuffer,12); // after that the response
#$this->DebugBinary($this->rawbuffer);
$this->header=unpack("nid/nflags/nqdcount/nancount/nnscount/narcount",$this->rawheader);
$flags = sprintf("%016b\n",$this->header['flags']);
Expand All @@ -232,7 +232,7 @@ function Query($question,$type='A')
$c=1;
while ($c!=0)
{
$c=hexdec(bin2hex($response->ReadResponse($this->rawbuffer, 1)));
$c=hexdec(bin2hex($response->ReadResponse($this->rawbuffer)));
$q .= $c;
}
$response->addQuery($q);
Expand Down Expand Up @@ -331,23 +331,20 @@ function algorithm($code)
# Diffie-Helman
return 'dh';
case 3:
return 'sha1';
case 4:
return 'reserved';
case 5:
return 'sha1';
case 4:
case 9:
case 11:
return 'reserved';
case 6:
return 'dsansec3sha1';
case 7:
return 'rsasha1nsec3';
case 8:
return 'sha256';
case 9:
return 'reserved';
case 10:
return 'sha512';
case 11:
return 'reserved';
case 12:
return 'gost';
case 13:
Expand Down
7 changes: 2 additions & 5 deletions DNS/dnsResponses/dnsResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,6 @@ public function ReadRecord($buffer, $resulttype = '')
$result->setClass($ans_header['class']);
$result->setTtl($ans_header['ttl']);
$this->addResult($result, $resulttype);
return;
}


Expand All @@ -297,8 +296,7 @@ private function keytag($key, $keysize)
$ac += (($i & 1) ? $keyp[1] : $keyp[1] << 8);
}
$ac += ($ac >> 16) & 0xFFFF;
$keytag = $ac & 0xFFFF;
return $keytag;
return $ac & 0xFFFF;
}

private function keytag2($key, $keysize)
Expand All @@ -309,8 +307,7 @@ private function keytag2($key, $keysize)
$ac += ($i % 2 ? $keyp[1] : 256 * $keyp[1]);
}
$ac += ($ac / 65536) % 65536;
$keytag = $ac % 65536;
return $keytag;
return $ac % 65536;
}

private function ReadDomainLabel($buffer)
Expand Down
4 changes: 2 additions & 2 deletions test.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

$dns = new Metaregistrar\DNS\dnsProtocol();
$dns->setServer('ns1.google.com');
$result = $dns->Query('google.com','TXT');
$result = $dns->Query('metaregistrar.com','SRV');
/* @var $result Metaregistrar\DNS\dnsResponse */
foreach ($result->getResourceResults() as $resource) {
//var_dump($resource);
var_dump($resource);
if ($resource instanceof Metaregistrar\DNS\dnsAresult) {
echo $resource->getDomain().' - '.$resource->getIpv4().' - '.$resource->getTtl()."\n";
}
Expand Down

0 comments on commit d635cda

Please sign in to comment.