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

Posadis abstract resolver class. More...

#include <resolver.h>

+ Inheritance diagram for pos_resolver:
+ Collaboration diagram for pos_resolver:

Public Member Functions

 pos_resolver ()
 default constructor
virtual ~pos_resolver ()
 destructor
virtual void query (DnsMessage *q, DnsMessage *&a, _addr *server, int flags=0)=0
 high-level query function
virtual _addr query (DnsMessage *q, DnsMessage *&a, std::list< _addr > &servers, int flags=0)=0
 high-level query function using multiple servers
virtual void sendmessage (DnsMessage *msg, _addr *res, int sockid=-1)=0
 low-level resolver function for sending a message
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.
virtual bool waitanswer (DnsMessage *&ans, std::list< WaitAnswerData > &wait, int timeout, std::list< WaitAnswerData >::iterator &it, int sockid=-1)=0
 low-level resolver function for waiting for an answer

Public Attributes

int n_udp_tries
 number of UDP attempts
int tcp_timeout
 TCP timeout value.
int * udp_tries
 UDP timeout values.

Detailed Description

Posadis abstract resolver class.

This is the abstract base class for the Posadis resolver functionality. The pos_resolver class offers functions for both UDP and TCP resolving. For UDP resolving, use the high-level query() functions. sendmessage() and waitanswer() are low-level functions that applications would not normally want to call. The same goes for TCP: tcpconnect() tcpdisconnect() and tcpquery() are the functions it's all about.

You can modify some parameters by setting member functions of the class, and by specifying custom flags for the query functions.

Like we mentioned, this is an abstract class that should not be used directly. For client applications, use the pos_cliresolver class, and for server applications, use pos_srvresolver.

Note that pos_resolver actually does contain a complete TCP implementation, so, theoretically it could be instantiated directly for use as a TCP resolver. This is however not encouraged.

Constructor & Destructor Documentation

pos_resolver::pos_resolver ( )

default constructor

This constructor intializes the resolver, and sets the udp_tries, n_udp_tries and tcp_timeout values to their defaults.

pos_resolver::~pos_resolver ( )
virtual

destructor

This function clears all memory associated with the resolver object.

Member Function Documentation

virtual void pos_resolver::query ( DnsMessage q,
DnsMessage *&  a,
_addr server,
int  flags = 0 
)
pure 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.

Implemented in pos_cliresolver.

virtual _addr pos_resolver::query ( DnsMessage q,
DnsMessage *&  a,
std::list< _addr > &  servers,
int  flags = 0 
)
pure 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()

Implemented in pos_cliresolver.

virtual void pos_resolver::sendmessage ( DnsMessage msg,
_addr res,
int  sockid = -1 
)
pure 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
sockidImplementation-dependent argument.

Implemented in pos_cliresolver.

int pos_resolver::tcpconnect ( _addr res)
virtual

establishes a TCP connection to a DNS server

This function will try to connect to the given address using TCP.

Parameters
resThe server to connect to
Returns
A socket identifier to use for other tcp resolver functions
See Also
tcpdisconnect()
void pos_resolver::tcpdisconnect ( int  sockid)
virtual

disconnects from a DNS server

This function will disconnect from a server we connected to earlier using tcpconnect().

See Also
tcpconnect()
void pos_resolver::tcpquery ( DnsMessage q,
DnsMessage *&  a,
int  sockid 
)
virtual

TCP query function.

This is the high-level TCP query function. It will query the server we connected to, and put the answer to the query q in a. It will wait at most tcp_timeout milliseconds before it receives an answer.

If the function receives a message which does not answer our query, it will stop waiting and raise an exception.

Parameters
qThe DNS query message
aVariable to put the answer in
sockidThe TCP connection (as returned by tcpconnect())
void pos_resolver::tcpsendmessage ( DnsMessage msg,
int  sockid 
)
virtual

TCP low-level function for sending a message.

This function sends a DNS message over a TCP connection.

Parameters
msgThe message to send
sockidThe TCP connection (as returned by tcpconnect())

< Maximum size of a TCP packet.

void pos_resolver::tcpwaitanswer ( DnsMessage *&  ans,
int  sockid 
)
virtual

TCP low-level function for waiting for an answer.

This function waits for at most tcp_timeout milliseconds until it receives an answer from the server on the other end of the line. Unlike its UDP conterpart, this function does not check whether the server actually answered our query.

Parameters
ansVariable to put the received message in. This should already point to an existing DNS message, which should be initialized by calling q->initialize_answer(); even if an error occurs, this may be non-NULL.
sockidThe TCP connection (as returned by tcpconnect())
virtual bool pos_resolver::waitanswer ( DnsMessage *&  ans,
std::list< WaitAnswerData > &  wait,
int  timeout,
std::list< WaitAnswerData >::iterator &  it,
int  sockid = -1 
)
pure 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 will 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.
sockidImplementation-dependent argument.

Implemented in pos_cliresolver.

Member Data Documentation

int pos_resolver::n_udp_tries

number of UDP attempts

Sets the number of times Posadis attempts to retry querying using UDP if a previous attempt did not return an answer. If you change this value, you should also change udp_tries to have at least as many items as this value.

int pos_resolver::tcp_timeout

TCP timeout value.

This is the time, in milliseconds, we're willing to wait for TCP transmission. Because there are four operations involved in a TCP query (two send operations and two read operations), each operation gets 25% of this timeout to complete. Since TCP is a connection-based protocol, we're not responsible for retransmission, thus we only attempt queries once.

int* pos_resolver::udp_tries

UDP timeout values.

This is an array of UDP retry values, in milliseconds. This array can be changed by hand. If you want to change the dimensions, a mere realloc() is enough. Just make sure it has at least as many items as the n_udp_tries value, otherwise your application might crash :(


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