Dibbler - a portable DHCPv6  1.0.2RC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
pos_cliresolver Class Reference

resolver for client applications More...

#include <resolver.h>

+ Inheritance diagram for pos_cliresolver:
+ Collaboration diagram for pos_cliresolver:

Public Member Functions

 pos_cliresolver ()
 resolver constructor
virtual ~pos_cliresolver ()
 destructor
void query (DnsMessage *q, DnsMessage *&a, _addr *server, int flags=0)
 high-level query function
_addr query (DnsMessage *q, DnsMessage *&a, std::list< _addr > &servers, int flags=0)
 high-level query function using multiple servers
void sendmessage (DnsMessage *msg, _addr *res, int sockid=-1)
 low-level resolver function for sending a message
void stop ()
 stops the resolving process asap
bool waitanswer (DnsMessage *&ans, std::list< WaitAnswerData > &wait, int timeout, std::list< WaitAnswerData >::iterator &it, int sockid=-1)
 low-level resolver function for waiting for an answer
- Public Member Functions inherited from pos_resolver
 pos_resolver ()
 default constructor
virtual ~pos_resolver ()
 destructor
virtual int tcpconnect (_addr *res)
 establishes a TCP connection to a DNS server
virtual void tcpdisconnect (int sockid)
 disconnects from a DNS server
virtual void tcpquery (DnsMessage *q, DnsMessage *&a, int sockid)
 TCP query function.
virtual void tcpsendmessage (DnsMessage *msg, int sockid)
 TCP low-level function for sending a message.
virtual void tcpwaitanswer (DnsMessage *&ans, int sockid)
 TCP low-level function for waiting for an answer.

Private Member Functions

void clrstop ()

Private Attributes

int clipipes [2]
bool is_tcp
bool quit_flag
int sockid

Additional Inherited Members

- Public Attributes inherited from pos_resolver
int n_udp_tries
 number of UDP attempts
int tcp_timeout
 TCP timeout value.
int * udp_tries
 UDP timeout values.

Detailed Description

resolver for client applications

This is an implementation of the pos_resolver class meant for client applications. It does not maintain a centralized query database like pos_srvresolver. Instead, it will open up a new socket for each query it attempts. The advantage is that it does not require the multi-thread architecture pos_srvresolver depends on.

pos_cliresolver implements the pos_resolver query(), sendmessage() and waitanswer() functions.

Constructor & Destructor Documentation

pos_cliresolver::pos_cliresolver ( )

resolver constructor

Resolver for the client resolver.

pos_cliresolver::~pos_cliresolver ( )
virtual

destructor

Destructor for the client resolver

Member Function Documentation

void pos_cliresolver::clrstop ( )
private
void pos_cliresolver::query ( DnsMessage q,
DnsMessage *&  a,
_addr server,
int  flags = 0 
)
virtual

high-level query function

This function will query the given DNS server for the information identified by the DNS query message q. If it succeeds, it will return and put the answer from the server in a, which need not be initialized previously (in fact, this will result in a memory leak). If not, it will raise a PException.

If the query() function does not receive an answer in time, it will retry for n_udp_tries times, using the timeout values from the udp_tries array. If the answer it receives is truncated, it will retry using TCP, unless instructed not to by the flags parameter.

The behavior of the query function can be changed by the flags parameter. Currently, this can only be Q_DFL (default flags) or Q_NOTCP (do not retry using UDP).

Parameters
qThe DNS query message
aVariable to put the answer in
serverThe server to query
flagsFlags controlling query behavior.

Implements pos_resolver.

_addr pos_cliresolver::query ( DnsMessage q,
DnsMessage *&  a,
std::list< _addr > &  servers,
int  flags = 0 
)
virtual

high-level query function using multiple servers

This function generally behaves the same as the query() function, except it takes a list of servers instead of one. The query algorithm differs in that for each timeout value from udp_tries, all servers will be queried. Also, if the answer is truncated, only the server that returned the truncated answer will be tried using TCP. This function will start querying at a random place in the servers list; after that, it will run through all servers listed in the order in which you specify them.

Parameters
q
alikely an answer
serversList of servers to query
flags
Returns
The address of the server that returned this answer
See Also
query()

< Server failure

< Action refused

< Feature not implemented

Implements pos_resolver.

void pos_cliresolver::sendmessage ( DnsMessage msg,
_addr res,
int  sockid = -1 
)
virtual

low-level resolver function for sending a message

This function sends a DNS message to a specified server using UDP.

Parameters
msgThe DNS message to send
resThe host to send the message to
sockidThe socket to use

< Maximum size of an UDP packet.

Implements pos_resolver.

void pos_cliresolver::stop ( )

stops the resolving process asap

This function will try to stop the resolving process as soon as possible. Thus, it will need to be called asynchronously (since the query functions block), either from another thread or from a signal handler. It will tease the query functions a bit by closing their sockets, and urge them to quit.

bool pos_cliresolver::waitanswer ( DnsMessage *&  ans,
std::list< WaitAnswerData > &  wait,
int  timeout,
std::list< WaitAnswerData >::iterator &  it,
int  sockid = -1 
)
virtual

low-level resolver function for waiting for an answer

This function waits for at most the amount of milliseconds specified by timeout until an answer to our query arrives. Since multiple messages for the same query might have been sent out, it asks for a list of sent queries.

If no answer is received in time, this function will raise an exception.

Parameters
ansIf an answer is received, it ill be put in this variable. This should already be a valid DNS message, presumably initialized with q->initialize_answer()
waitList of sent queries we might get an answer to
timeoutNumber of milliseconds to wait at most
itIf an answer is received, this iterator will point to the message this was an answer to.
sockidThe socket id the answers will come from.

< Maximum size of an UDP packet.

Implements pos_resolver.

Member Data Documentation

int pos_cliresolver::clipipes[2]
private
bool pos_cliresolver::is_tcp
private
bool pos_cliresolver::quit_flag
private
int pos_cliresolver::sockid
private

The documentation for this class was generated from the following files: