1<?php 2/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 3 4/** 5 * DNS Library for handling lookups and updates. 6 * 7 * PHP Version 5 8 * 9 * Copyright (c) 2010, Mike Pultz <mike@mikepultz.com>. 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 16 * * Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 19 * * Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in 21 * the documentation and/or other materials provided with the 22 * distribution. 23 * 24 * * Neither the name of Mike Pultz nor the names of his contributors 25 * may be used to endorse or promote products derived from this 26 * software without specific prior written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 31 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 32 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 33 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 34 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 35 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 36 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC 37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 38 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 39 * POSSIBILITY OF SUCH DAMAGE. 40 * 41 * @category Networking 42 * @package Net_DNS2 43 * @author Mike Pultz <mike@mikepultz.com> 44 * @copyright 2010 Mike Pultz <mike@mikepultz.com> 45 * @license http://www.opensource.org/licenses/bsd-license.php BSD License 46 * @version SVN: $Id: HINFO.php 179 2012-11-23 05:49:01Z mike.pultz $ 47 * @link http://pear.php.net/package/Net_DNS2 48 * @since File available since Release 0.6.0 49 * 50 */ 51 52/** 53 * HINFO Resource Record - RFC1035 section 3.3.2 54 * 55 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 56 * / CPU / 57 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 58 * / OS / 59 * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ 60 * 61 * @category Networking 62 * @package Net_DNS2 63 * @author Mike Pultz <mike@mikepultz.com> 64 * @license http://www.opensource.org/licenses/bsd-license.php BSD License 65 * @link http://pear.php.net/package/Net_DNS2 66 * @see Net_DNS2_RR 67 * 68 */ 69class Net_DNS2_RR_HINFO extends Net_DNS2_RR 70{ 71 /* 72 * computer informatino 73 */ 74 public $cpu; 75 76 /* 77 * operataing system 78 */ 79 public $os; 80 81 /** 82 * method to return the rdata portion of the packet as a string 83 * 84 * @return string 85 * @access protected 86 * 87 */ 88 protected function rrToString() 89 { 90 return $this->formatString($this->cpu) . ' ' . 91 $this->formatString($this->os); 92 } 93 94 /** 95 * parses the rdata portion from a standard DNS config line 96 * 97 * @param array $rdata a string split line of values for the rdata 98 * 99 * @return boolean 100 * @access protected 101 * 102 */ 103 protected function rrFromString(array $rdata) 104 { 105 $data = $this->buildString($rdata); 106 if (count($data) == 2) { 107 108 $this->cpu = $data[0]; 109 $this->os = $data[1]; 110 111 return true; 112 } 113 114 return false; 115 } 116 117 /** 118 * parses the rdata of the Net_DNS2_Packet object 119 * 120 * @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet to parse the RR from 121 * 122 * @return boolean 123 * @access protected 124 * 125 */ 126 protected function rrSet(Net_DNS2_Packet &$packet) 127 { 128 if ($this->rdlength > 0) { 129 130 $offset = $packet->offset; 131 132 $this->cpu = trim(Net_DNS2_Packet::label($packet, $offset), '"'); 133 $this->os = trim(Net_DNS2_Packet::label($packet, $offset), '"'); 134 135 return true; 136 } 137 138 return false; 139 } 140 141 /** 142 * returns the rdata portion of the DNS packet 143 * 144 * @param Net_DNS2_Packet &$packet a Net_DNS2_Packet packet use for 145 * compressed names 146 * 147 * @return mixed either returns a binary packed 148 * string or null on failure 149 * @access protected 150 * 151 */ 152 protected function rrGet(Net_DNS2_Packet &$packet) 153 { 154 if (strlen($this->cpu) > 0) { 155 156 $data = chr(strlen($this->cpu)) . $this->cpu; 157 $data .= chr(strlen($this->os)) . $this->os; 158 159 $packet->offset += strlen($data); 160 161 return $data; 162 } 163 164 return null; 165 } 166} 167 168/* 169 * Local variables: 170 * tab-width: 4 171 * c-basic-offset: 4 172 * c-hanging-comment-ender-p: nil 173 * End: 174 */ 175?> 176