Skip to content

Commit

Permalink
- finished support for the AAAA RR
Browse files Browse the repository at this point in the history
- changed the A RR to use inet_ntop()/inet_pton() for network to printable conversions
  • Loading branch information
mike.pultz committed Aug 25, 2010
1 parent 4f71129 commit 8360928
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 11 deletions.
17 changes: 7 additions & 10 deletions Net/DNS2/RR/A.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,14 @@ protected function _set(Net_DNS2_Packet &$packet)
{
if ($this->rdlength > 0) {

$this->address = ord($this->rdata[0]) . '.' . ord($this->rdata[1]) . '.' .
ord($this->rdata[2]) . '.' . ord($this->rdata[3]);
$this->address = inet_ntop($this->rdata);
if ($this->address !== FALSE) {

return true;
}
}

return true;
return false;
}

/**
Expand All @@ -137,13 +140,7 @@ protected function _set(Net_DNS2_Packet &$packet)
*/
protected function _get(Net_DNS2_Packet &$packet)
{
$x = explode('.', $this->address);
if (count($x) == 4) {

return chr($x[0]) . chr($x[1]) . chr($x[2]) . chr($x[3]);
}

return null;
return inet_pton($this->address);
}
}

Expand Down
47 changes: 47 additions & 0 deletions Net/DNS2/RR/AAAA.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@
*/
class Net_DNS2_RR_AAAA extends Net_DNS2_RR
{
/*
* the IPv6 address in the preferred hexadecimal values of the eight 16-bit pieces
* per RFC1884
*
*/
public $address;

/**
* method to return the rdata portion of the packet as a string
*
Expand All @@ -79,6 +86,7 @@ class Net_DNS2_RR_AAAA extends Net_DNS2_RR
*/
protected function _toString()
{
return $this->address;
}

/**
Expand All @@ -91,8 +99,28 @@ protected function _toString()
*/
protected function _fromString(array $rdata)
{
$address = array_shift($rdata);

//
// expand out compressed formats
//
if (strpos($address, '::') !== false) {

$address = str_replace('::', str_repeat(':0', 8 - substr_count($address, ':')).':', $address);
}
if (strpos($address, ':') === 0) {

$address = '0' . $address;
}

$this->address = $address;

return true;
}

private function ExpandIPv6Notation($Ip) {
}

/**
* parses the rdata of the Net_DNS2_Packet object
*
Expand All @@ -103,6 +131,24 @@ protected function _fromString(array $rdata)
*/
protected function _set(Net_DNS2_Packet &$packet)
{
//
// must be 8 x 16bit chunks, or 16 x 8bit
//
if ($this->rdlength == 16) {

//
// PHP's inet_ntop returns IPv6 addresses in their compressed form, but we want
// to keep with the preferred standard, so we'll parse it manually.
//
$x = unpack('n8', $this->rdata);
if (count($x) == 8) {

$this->address = vsprintf("%x:%x:%x:%x:%x:%x:%x:%x", $x);
return true;
}
}

return false;
}

/**
Expand All @@ -115,6 +161,7 @@ protected function _set(Net_DNS2_Packet &$packet)
*/
protected function _get(Net_DNS2_Packet &$packet)
{
return inet_pton($this->address);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Net/DNS2/TODO
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Net_DNS2 TODO List

- finish missing RR's

- AAAA, NSAP, SIG, LOC, CERT, OPT, APL, SSHFP,
- NSAP, SIG, LOC, CERT, OPT, APL, SSHFP,
IPSECKEY, NSEC, DHCID, NSEC3, NSEC3PARAM, HIP

DONE - parse BIND style input and set all the appropriate values of the RR object
Expand Down
1 change: 1 addition & 0 deletions tests/Net_DNS2_ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function testParser()
'RT' => 'example.com. 300 IN RT 2 relay.prime.com.',
'KEY' => 'example.com. 300 IN KEY 256 3 7 AwEAAYCXh/ZABi8kiJIDXYmyUlHzC0CHeBzqcpyZAIjC7dK1wkRYVcUvIlpTOpnOVVfcC3Py9Ui/x45qKb0LytvK7WYAe3WyOOwk5klwIqRC/0p4luafbd2yhRMF7quOBVqYrLoHwv8i9LrV+r8dhB7rXv/lkTSI6mEZsg5rDfee8Yy1',
'PX' => 'example.com. 300 IN PX 10 ab.net2.it. o-ab.prmd-net2.admdb.c-it.',
'AAAA' => 'example.com. 300 IN AAAA 1080:0:0:0:8:800:200c:417a',
'SRV' => 'example.com. 300 IN SRV 20 0 5269 xmpp-server2.l.google.com.',
'NAPTR' => 'example.com. 300 IN NAPTR 100 10 S SIP+D2U !^.*$!sip:customer-service@example.com! _sip._udp.example.com.',
'KX' => 'example.com. 300 IN KX 10 mx1.mrhost.ca.',
Expand Down

0 comments on commit 8360928

Please sign in to comment.