2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
5
* DNS Library for handling lookups and updates.
9
* Copyright (c) 2010, Mike Pultz <mike@mikepultz.com>.
10
* All rights reserved.
12
* Redistribution and use in source and binary forms, with or without
13
* modification, are permitted provided that the following conditions
16
* * Redistributions of source code must retain the above copyright
17
* notice, this list of conditions and the following disclaimer.
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
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.
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.
41
* @category Networking
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: Socket.php 176 2012-11-16 02:14:09Z mike.pultz $
47
* @link http://pear.php.net/package/Net_DNS2
48
* @since File available since Release 0.6.0
53
* check to see if the socket defines exist; if they don't, then define them
55
if (defined('SOCK_STREAM') == false) {
56
define('SOCK_STREAM', 1);
58
if (defined('SOCK_DGRAM') == false) {
59
define('SOCK_DGRAM', 2);
63
* This is the abstract base class for the two sockets classes; this simply
64
* provides the class definition for the two sockets classes.
66
* @category Networking
68
* @author Mike Pultz <mike@mikepultz.com>
69
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
70
* @link http://pear.php.net/package/Net_DNS2
71
* @see Net_DNS2_Socket_Sockets, Net_DNS2_Socket_Streams
74
abstract class Net_DNS2_Socket
82
protected $local_host;
83
protected $local_port;
90
const SOCK_STREAM = SOCK_STREAM;
91
const SOCK_DGRAM = SOCK_DGRAM;
94
* constructor - set the port details
96
* @param integer $type the socket type
97
* @param string $host the IP address of the DNS server to connect to
98
* @param integer $port the port of the DNS server to connect to
99
* @param integer $timeout the timeout value to use for socket functions
104
public function __construct($type, $host, $port, $timeout)
109
$this->timeout = $timeout;
117
public function __destruct()
123
* sets the local address/port for the socket to bind to
125
* @param string $address the local IP address to bind to
126
* @param mixed $port the local port to bind to, or 0 to let the socket
127
* function select a port
133
public function bindAddress($address, $port = 0)
135
$this->local_host = $address;
136
$this->local_port = $port;
142
* opens a socket connection to the DNS server
148
abstract public function open();
151
* closes a socket connection to the DNS server
157
abstract public function close();
160
* writes the given string to the DNS server socket
162
* @param string $data a binary packed DNS packet
168
abstract public function write($data);
171
* reads a response from a DNS server
173
* @param integer &$size the size of the DNS packet read is passed back
175
* @return mixed returns the data on success and false on error
179
abstract public function read(&$size);
186
* c-hanging-comment-ender-p: nil