本文整理汇总了PHP中Net_DNS2_Packet::get方法的典型用法代码示例。如果您正苦于以下问题:PHP Net_DNS2_Packet::get方法的具体用法?PHP Net_DNS2_Packet::get怎么用?PHP Net_DNS2_Packet::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Net_DNS2_Packet
的用法示例。
在下文中一共展示了Net_DNS2_Packet::get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendPacket
/**
* sends a standard Net_DNS2_Packet_Request packet
*
* @param Net_DNS2_Packet $request a Net_DNS2_Packet_Request object
* @param boolean $use_tcp true/false if the function should
* use TCP for the request
*
* @return mixed returns a Net_DNS2_Packet_Response object, or false on error
* @throws Net_DNS2_Exception
* @access protected
*
*/
protected function sendPacket(Net_DNS2_Packet $request, $use_tcp)
{
//
// get the data from the packet
//
$data = $request->get();
if (strlen($data) < Net_DNS2_Lookups::DNS_HEADER_SIZE) {
throw new Net_DNS2_Exception('invalid or empty packet for sending!', Net_DNS2_Lookups::E_PACKET_INVALID, null, $request);
}
reset($this->nameservers);
//
// randomize the name server list if it's asked for
//
if ($this->ns_random == true) {
shuffle($this->nameservers);
}
//
// loop so we can handle server errors
//
$response = null;
$ns = '';
while (1) {
//
// grab the next DNS server
//
$ns = each($this->nameservers);
if ($ns === false) {
if (is_null($this->last_exception) == false) {
throw $this->last_exception;
} else {
throw new Net_DNS2_Exception('every name server provided has failed', Net_DNS2_Lookups::E_NS_FAILED);
}
}
$ns = $ns[1];
//
// if the use TCP flag (force TCP) is set, or the packet is bigger than our
// max allowed UDP size- which is either 512, or if this is DNSSEC request,
// then whatever the configured dnssec_payload_size is.
//
$max_udp_size = Net_DNS2_Lookups::DNS_MAX_UDP_SIZE;
if ($this->dnssec == true) {
$max_udp_size = $this->dnssec_payload_size;
}
if ($use_tcp == true || strlen($data) > $max_udp_size) {
try {
$response = $this->sendTCPRequest($ns, $data, $request->question[0]->qtype == 'AXFR' ? true : false);
} catch (Net_DNS2_Exception $e) {
$this->last_exception = $e;
$this->last_exception_list[$ns] = $e;
continue;
}
//
// otherwise, send it using UDP
//
} else {
try {
$response = $this->sendUDPRequest($ns, $data);
//
// check the packet header for a trucated bit; if it was truncated,
// then re-send the request as TCP.
//
if ($response->header->tc == 1) {
$response = $this->sendTCPRequest($ns, $data);
}
} catch (Net_DNS2_Exception $e) {
$this->last_exception = $e;
$this->last_exception_list[$ns] = $e;
continue;
}
}
//
// make sure header id's match between the request and response
//
if ($request->header->id != $response->header->id) {
$this->last_exception = new Net_DNS2_Exception('invalid header: the request and response id do not match.', Net_DNS2_Lookups::E_HEADER_INVALID, null, $request, $response);
$this->last_exception_list[$ns] = $this->last_exception;
continue;
}
//
// make sure the response is actually a response
//
// 0 = query, 1 = response
//
if ($response->header->qr != Net_DNS2_Lookups::QR_RESPONSE) {
$this->last_exception = new Net_DNS2_Exception('invalid header: the response provided is not a response packet.', Net_DNS2_Lookups::E_HEADER_INVALID, null, $request, $response);
$this->last_exception_list[$ns] = $this->last_exception;
continue;
}
//.........这里部分代码省略.........
示例2: sendPacket
/**
* sends a standard Net_DNS2_Packet_Request packet
*
* @param Net_DNS2_Packet $request a Net_DNS2_Packet_Request object
* @param boolean $use_tcp true/false if the function should
* use TCP for the request
*
* @return mixed returns a Net_DNS2_Packet_Response object, or false on error
* @throws Net_DNS2_Exception
* @access protected
*
*/
protected function sendPacket(Net_DNS2_Packet $request, $use_tcp)
{
//
// get the data from the packet
//
$data = $request->get();
if (strlen($data) < Net_DNS2_Lookups::DNS_HEADER_SIZE) {
throw new Net_DNS2_Exception('invalid or empty packet for sending!', Net_DNS2_Lookups::E_PACKET_INVALID, null, $request);
}
reset($this->nameservers);
//
// randomize the name server list if it's asked for
//
if ($this->ns_random == true) {
shuffle($this->nameservers);
}
//
// loop so we can handle server errors
//
$response = null;
$ns = '';
$socket_type = null;
$tcp_fallback = false;
while (1) {
//
// grab the next DNS server
//
if ($tcp_fallback == false) {
$ns = each($this->nameservers);
if ($ns === false) {
throw new Net_DNS2_Exception('every name server provided has failed: ' . $this->_last_socket_error, Net_DNS2_Lookups::E_NS_FAILED);
}
$ns = $ns[1];
}
//
// if the use TCP flag (force TCP) is set, or the packet is bigger
// than 512 bytes, use TCP for sending the packet
//
if ($use_tcp == true || strlen($data) > Net_DNS2_Lookups::DNS_MAX_UDP_SIZE || $tcp_fallback == true) {
$tcp_fallback = false;
$socket_type = Net_DNS2_Socket::SOCK_STREAM;
//
// create the socket object
//
if (!isset($this->sock['tcp'][$ns]) || !$this->sock['tcp'][$ns] instanceof Net_DNS2_Socket) {
if ($this->sockets_enabled === true) {
$this->sock['tcp'][$ns] = new Net_DNS2_Socket_Sockets(Net_DNS2_Socket::SOCK_STREAM, $ns, $this->dns_port, $this->timeout);
} else {
$this->sock['tcp'][$ns] = new Net_DNS2_Socket_Streams(Net_DNS2_Socket::SOCK_STREAM, $ns, $this->dns_port, $this->timeout);
}
}
//
// if a local IP address / port is set, then add it
//
if (strlen($this->local_host) > 0) {
$this->sock['tcp'][$ns]->bindAddress($this->local_host, $this->local_port);
}
//
// open it; if it fails, continue in the while loop
//
if ($this->sock['tcp'][$ns]->open() === false) {
$this->_last_socket_error = $this->sock['tcp'][$ns]->last_error;
continue;
}
//
// write the data to the socket; if it fails, continue on
// the while loop
//
if ($this->sock['tcp'][$ns]->write($data) === false) {
$this->_last_socket_error = $this->sock['tcp'][$ns]->last_error;
continue;
}
//
// read the content, using select to wait for a response
//
$size = 0;
$result = null;
//
// handle zone transfer requests differently than other requests.
//
if ($request->question[0]->qtype == 'AXFR') {
$soa_count = 0;
while (1) {
//
// read the data off the socket
//
$result = $this->sock['tcp'][$ns]->read($size);
if ($result === false || $size < Net_DNS2_Lookups::DNS_HEADER_SIZE) {
//.........这里部分代码省略.........
示例3: sendPacket
/**
* sends a standard Net_DNS2_Packet_Request packet
*
* @param Net_DNS2_Packet $request a Net_DNS2_Packet_Request object
* @param boolean $use_tcp true/false if the function should
* use TCP for the request
*
* @return mixed returns a Net_DNS2_Packet_Response object, or false on error
* @throws Net_DNS2_Exception
* @access protected
*
*/
protected function sendPacket(Net_DNS2_Packet $request, $use_tcp)
{
//
// get the data from the packet
//
$data = $request->get();
if (strlen($data) < Net_DNS2_Lookups::DNS_HEADER_SIZE) {
throw new Net_DNS2_Exception('invalid or empty packet for sending!', Net_DNS2_Lookups::E_PACKET_INVALID);
}
reset($this->nameservers);
//
// randomize the name server list if it's asked for
//
if ($this->ns_random == true) {
shuffle($this->nameservers);
}
//
// loop so we can handle server errors
//
$response = null;
$ns = '';
$tcp_fallback = false;
while (1) {
//
// grab the next DNS server
//
if ($tcp_fallback == false) {
$ns = each($this->nameservers);
if ($ns === false) {
throw new Net_DNS2_Exception('every name server provided has failed: ' . $this->_last_socket_error, Net_DNS2_Lookups::E_NS_FAILED);
}
$ns = $ns[1];
}
//
// if the use TCP flag (force TCP) is set, or the packet is bigger
// than 512 bytes, use TCP for sending the packet
//
if ($use_tcp == true || strlen($data) > Net_DNS2_Lookups::DNS_MAX_UDP_SIZE || $tcp_fallback == true) {
$tcp_fallback = false;
//
// create the socket object
//
if (!isset($this->sock['tcp'][$ns]) || !$this->sock['tcp'][$ns] instanceof Net_DNS2_Socket) {
if ($this->sockets_enabled === true) {
$this->sock['tcp'][$ns] = new Net_DNS2_Socket_Sockets(SOCK_STREAM, $ns, $this->dns_port, $this->timeout);
} else {
$this->sock['tcp'][$ns] = new Net_DNS2_Socket_Streams(SOCK_STREAM, $ns, $this->dns_port, $this->timeout);
}
}
//
// if a local IP address / port is set, then add it
//
if (strlen($this->local_host) > 0) {
$this->sock['tcp'][$ns]->bindAddress($this->local_host, $this->local_port);
}
//
// open it; if it fails, continue in the while loop
//
if ($this->sock['tcp'][$ns]->open() === false) {
$this->_last_socket_error = $this->sock['tcp'][$ns]->last_error;
continue;
}
//
// write the data to the socket; if it fails, continue on
// the while loop
//
if ($this->sock['tcp'][$ns]->write($data) === false) {
$this->_last_socket_error = $this->sock['tcp'][$ns]->last_error;
continue;
}
//
// read the content, using select to wait for a response
//
$size = 0;
$result = $this->sock['tcp'][$ns]->read($size);
if ($result === false || $size < Net_DNS2_Lookups::DNS_HEADER_SIZE) {
$this->_last_socket_error = $this->sock['tcp'][$ns]->last_error;
continue;
}
//
// create the packet object
//
$response = new Net_DNS2_Packet_Response($result, $size);
break;
} else {
//
// create the socket object
//
//.........这里部分代码省略.........