arlib(3)

NAME
ar_answer, ar_close, ar_delete, ar_gethostbyname, ar_gethostbyaddr, ar_init, ar_open, ar_timeout - Asynchronous DNS library routines

SYNOPSIS
#include arlib.h
struct hostent *ar_answer(dataptr, size)
char *dataptr;
int size;
void ar_close();
int ar_delete(dataptr, size)
char *dataptr;
int size;
int ar_gethostbyname(name, dataptr, size)
char *name;
char *dataptr;
int size;
int ar_gethostbyaddr(name, dataptr, size)
char *name;
char *dataptr;
int size;
int ar_init(flags)
int flags;
int ar_open();
long ar_timeout(time, dataptr, size)
long time;
char *dataptr;
int size;

DESCRIPTION

   This small library of DNS routines is intended to provide an asynchronous interface to performing hostname and IP number lookups. Only lookups of Internet domain are handled as yet. To use this set of routines properly, the presence of the BIND 4.8 resolve libraries is required (or any library derived from it).

   This library should be used in conjuction with select(2) to wait for the name server's reply to arrive or the lookup to timeout.

   To open a fd for talking to the name server, either ar_open() or ar_init() must be used. ar_open()
 will open either a datagram socket or a virtual circuit with the name server, depending on the flags set in the _res structure (see resolv(5) ). In both cases, if the socket is successfully opened, it is flaged for non-blocking IO. ar_init() is used to both open the socket (as in ar_open() ) and initialize the queues used by this library. The values recognized as parameters to ar_init() are:
    #define ARES_INITLIST 1
    #define ARES_CALLINIT 2
    #define ARES_INITSOCK 4
    #define ARES_INITDEBG 8
   ARES_INITLIST initializes the list of queries waiting for replies. ARES_CALLINIT is a flag which when set causes res_init() to be called. ARES_INITSOCK will close the current socket if it is open and call ar_open() to open a new one, returning the fd for that socket. ARES_INITDEBG sets the RES_DEBUG flag of the _res structure. ARES_INITCACH is as yet, unused and is for future use where the library keeps its own cache of replies.
   To send a query about either a hostname or an IP number, ar_gethostbyname() and ar_gethostbyaddr() must be used. Each takes either a pointer to the hostname or the IP number respectively for use when making the query. In addition to this, both (optionally) can be passed a pointer to data, dataptr, with the size also passed which can be used for indentifying individual queries. A copy of the area pointed to is made if dataptr is non NULL and size is non zero. These functions will always return NULL unless the answer to the query is found in internal caches. A new flag, RES_CHECKPTR is checked during the processing of answers for ar_gethostbyname() which will automatically cause a reverse lookup to be queued, causing a failure if that reply differs from the original.
   To check for a query, ar_answer() is called with a pointer to an area of memory which is sufficient to hold what was originally passed via ar_gethostbyname() or ar_gethostbyaddr() through dataptr. If an answer is found, a pointer to the host information is returned and the data segment copied if dataptr is non NULL and it was originally passed. The size of the copied data is the smaller of the passed size and that of original data stored.
   To expire old queries, ar_timeout() is called with the 'current' time (or the time for which you want to do timeouts for). If a queue entry is too old, it will be expired when it has exhausted all available avenus for lookups and the data segment for the expired query copied into dataptr. The size of the copied data is the smaller of the passed size and that of the original stored data. Only 1 entry is thus expired with each call, requiring that it be called immeadiately after an expiration to check for others. In addition to expiring lookups, ar_timeout() also triggers resends of queries and the searching of the domain tree for the host, the latter works from the _res structure of resolv(5).
   To delete entries from the queue, ar_delete() can be used and by passing the pointer and size of the data segment, all queries have their data segments checked (if present) for an exact match, being deleted if and only if there is a match. A NULL pointer passed to ar_deleted() matches all queries which were called with a NULL dataptr parameter. The amount of data compared is the smaller of the size passed and that of the data stored for the queue entry being compared.
   To close a socket opened by ar_open() , ar_close() should be used so that it is closed and also marked closed within this library.

DIAGNOSIS
ar_open() returns -1 if a socket isn't open and could not be opened; otherwise returns the current fd open or the fd it opened. ar_init() returns -1 for any errors, the value returned by res_init() if res_init() was called, the return value for ar_open() if that was called or the current socket open if 0 is passed and a socket is open. If neither res_init() or ar_open() are called and the flags are non-zero, -2 is returned.

ar_gethostbyaddr() and ar_gethostbyname() will always return NULL in this version but may return a pointer to a hostent structure if a cache is being used and the answer is found in the fache. ar_answer() returns NULL if the answer is either not found or the query returned an error and another attempt at a lookup is attempted. If an answer was found, it returned a pointer to this structure and the contents of the data sengment copied over. ar_timeout() returns the time when it should be called next or 0 if there are no queries in the queue to be checked later. If any queries are expired, the data segment is copied over if dataptr is non NULL. ar_delete() returns the number of entries that were found to match and consequently delted.

SEE ALSO
gethostbyaddr(3), gethostbyname(3), resolv(5)

FILES
arlib.h
/usr/include/resolv.h
/usr/include/arpa/nameser.h
/etc/resolv.conf

BUGS
The results of a successful call to ar_answer() destroy the structure for any previous calls.

AUTHOR
Darren Reed. Email address: avalon@coombs.anu.edu.au