Commit version 24.12.13800
This commit is contained in:
@ -43,8 +43,8 @@ class Net_DNS2_Socket
|
||||
/*
|
||||
* the local IP and port we'll send the request from
|
||||
*/
|
||||
private $local_host;
|
||||
private $local_port;
|
||||
private $local_host = '';
|
||||
private $local_port = 0;
|
||||
|
||||
/*
|
||||
* the last error message on the object
|
||||
@ -129,12 +129,46 @@ class Net_DNS2_Socket
|
||||
//
|
||||
// bind to a local IP/port if it's set
|
||||
//
|
||||
if (strlen($this->local_host) > 0) {
|
||||
if ( ((is_null($this->local_host) == false) && (strlen($this->local_host) > 0)) || ($this->local_port > 0) ) {
|
||||
|
||||
$opts['socket']['bindto'] = $this->local_host;
|
||||
//
|
||||
// build the host
|
||||
//
|
||||
if ( (is_null($this->local_host) == false) && (strlen($this->local_host) > 0) ) {
|
||||
|
||||
//
|
||||
// it's possible users are already setting the IPv6 brackets, so I'll just clean them off first
|
||||
//
|
||||
$host = str_replace([ '[', ']' ], '', $this->local_host);
|
||||
|
||||
if (Net_DNS2::isIPv4($this->local_host) == true) {
|
||||
|
||||
$opts['socket']['bindto'] = $this->local_host;
|
||||
|
||||
} else if (Net_DNS2::isIPv6($this->local_host) == true) {
|
||||
|
||||
$opts['socket']['bindto'] = '[' . $this->local_host . ']';
|
||||
|
||||
} else
|
||||
{
|
||||
$this->last_error = 'invalid bind address value: ' . $this->local_host;
|
||||
return false;
|
||||
}
|
||||
|
||||
} else
|
||||
{
|
||||
$opts['socket']['bindto'] = '0';
|
||||
}
|
||||
|
||||
//
|
||||
// then add the port
|
||||
//
|
||||
if ($this->local_port > 0) {
|
||||
|
||||
$opts['socket']['bindto'] .= ':' . $this->local_port;
|
||||
} else {
|
||||
|
||||
$opts['socket']['bindto'] .= ':0';
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,9 +180,6 @@ class Net_DNS2_Socket
|
||||
//
|
||||
// create socket
|
||||
//
|
||||
$errno;
|
||||
$errstr;
|
||||
|
||||
switch($this->type) {
|
||||
case Net_DNS2_Socket::SOCK_STREAM:
|
||||
|
||||
@ -212,7 +243,7 @@ class Net_DNS2_Socket
|
||||
//
|
||||
// set it to non-blocking and set the timeout
|
||||
//
|
||||
@stream_set_blocking($this->sock, 0);
|
||||
@stream_set_blocking($this->sock, false);
|
||||
@stream_set_timeout($this->sock, $this->timeout);
|
||||
|
||||
return true;
|
||||
@ -264,7 +295,7 @@ class Net_DNS2_Socket
|
||||
//
|
||||
// select on write
|
||||
//
|
||||
$result = stream_select($read, $write, $except, $this->timeout);
|
||||
$result = @stream_select($read, $write, $except, $this->timeout);
|
||||
if ($result === false) {
|
||||
|
||||
$this->last_error = 'failed on write select()';
|
||||
@ -328,12 +359,12 @@ class Net_DNS2_Socket
|
||||
//
|
||||
// make sure our socket is non-blocking
|
||||
//
|
||||
@stream_set_blocking($this->sock, 0);
|
||||
@stream_set_blocking($this->sock, false);
|
||||
|
||||
//
|
||||
// select on read
|
||||
//
|
||||
$result = stream_select($read, $write, $except, $this->timeout);
|
||||
$result = @stream_select($read, $write, $except, $this->timeout);
|
||||
if ($result === false) {
|
||||
|
||||
$this->last_error = 'error on read select()';
|
||||
@ -360,8 +391,8 @@ class Net_DNS2_Socket
|
||||
$this->last_error = 'failed on fread() for data length';
|
||||
return false;
|
||||
}
|
||||
if (strlen($data) == 0)
|
||||
{
|
||||
if (strlen($data) < 2) {
|
||||
|
||||
$this->last_error = 'failed on fread() for data length';
|
||||
return false;
|
||||
}
|
||||
@ -380,7 +411,7 @@ class Net_DNS2_Socket
|
||||
// so the easiest thing to do, is just turn off socket blocking, and
|
||||
// wait for the data.
|
||||
//
|
||||
@stream_set_blocking($this->sock, 1);
|
||||
@stream_set_blocking($this->sock, true);
|
||||
|
||||
//
|
||||
// read the data from the socket
|
||||
@ -404,7 +435,7 @@ class Net_DNS2_Socket
|
||||
//
|
||||
while (1) {
|
||||
|
||||
$chunk = fread($this->sock, $chunk_size);
|
||||
$chunk = fread($this->sock, max(0, $chunk_size));
|
||||
if ($chunk === false) {
|
||||
|
||||
$this->last_error = 'failed on fread() for data';
|
||||
@ -425,8 +456,8 @@ class Net_DNS2_Socket
|
||||
// if it's UDP, it's a single fixed-size frame, and the streams library
|
||||
// doesn't seem to have a problem reading it.
|
||||
//
|
||||
$data = fread($this->sock, $length);
|
||||
if ($length === false) {
|
||||
$data = fread($this->sock, max(0, $length));
|
||||
if ($data === false) {
|
||||
|
||||
$this->last_error = 'failed on fread() for data';
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user