⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arlib.3

📁 网络时间协议NTP 源码 版本v4.2.0b 该源码用于linux平台下
💻 3
字号:
.TH arlib 3.SH NAMEar_answer, ar_close, ar_delete, ar_gethostbyname, ar_gethostbyaddr,ar_init, ar_open, ar_timeout - Asynchronous DNS library routines.SH SYNOPSIS.nf.B #include "arlib.h".B struct hostent *ar_answer(dataptr, size).B char *dataptr;.B int size;.B void ar_close();.B int ar_delete(dataptr, size).B char *dataptr;.B int size;.B int ar_gethostbyname(name, dataptr, size).B char *name;.B char *dataptr;.B int size;.B int ar_gethostbyaddr(name, dataptr, size).B char *name;.B char *dataptr;.B int size;.B int ar_init(flags).B int flags;.B int ar_open();.B long ar_timeout(time, dataptr, size).B long time;.B char *dataptr;.B int size;.fi.SH DESCRIPTION.PP   This small library of DNS routines is intended to provide anasynchronous interface to performing hostname and IP number lookups.Only lookups of Internet domain are handled as yet.  To use thisset of routines properly, the presence of the.B "BIND 4.8"resolvelibraries is required (or any library derived from it)..PP   This library should be used in conjunction with.B select(2)to wait forthe name server's reply to arrive or the lookup to timeout..PP   To open a fd for talking to the name server, either.B ar_open()orar_init()must be used..B  ar_open() will open either a datagram socketor a virtual circuit with the name server, depending on the flagsset in the _res structure (see.B resolv(5)).  In both cases, if the socket> i.B  ar_init()isused to both open the socket (as in.B ar_open()) and initialize thequeues used by this library.  The values recognized as parameters to.B ar_init()are:.RS#define ARES_INITLIST   1.RE.RS#define ARES_CALLINIT   2.RE.RS#define ARES_INITSOCK   4.RE.RS#define ARES_INITDEBG   8.RE   ARES_INITLIST initializes the list of queries waiting for replies.ARES_CALLINIT is a flag which when set causes.B res_init()to be called.ARES_INITSOCK will close the current socket if it is open and call.B ar_open()to open a new one, returning the fd for that socket.ARES_INITDEBG sets the RES_DEBUG flag of the.B _resstructure.ARES_INITCACH is as yet, unused and is for future use where the librarykeeps its own cache of replies.   To send a query about either a hostname or an IP number,.B ar_gethostbyname()and.B ar_gethostbyaddr()must be used.  Each takeseither a pointer to the hostname or the IP number respectively for usewhen making the query.  In addition to this, both (optionally) can bepassed a pointer to data, dataptr, with the size also passed which canbe used for identifying individual queries.  A copy of the area pointedto is made if dataptr is non NULL and size is non zero.  These functionswill always return NULL unless the answer to the query is found ininternal caches.  A new flag, RES_CHECKPTR is checked during theprocessing of answers for.B ar_gethostbyname()which will automaticallycause a reverse lookup to be queued, causing a failure if that replydiffers from the original.   To check for a query,.B ar_answer()is called with a pointer to an  areaof memory which is sufficient to hold what was originally passed via.B ar_gethostbyname()or.B ar_gethostbyaddr()through dataptr.  If an answeris found, a pointer to the host information is returned and the datasegment copied if dataptr is non NULL and it was originally passed.  Thesize of the copied data is the smaller of the passed size and that oforiginal data stored.   To expire old queries,.B ar_timeout()is called with the 'current' time(or the time for which you want to do timeouts for).  If a queue entryis too old, it will be expired when it has exhausted all available avenuesfor lookups and the data segment for the expired query copied intodataptr.  The size of the copied data is the smaller of the passed sizeand that of the original stored data.  Only 1 entry is thus expired witheach call, requiring that it be called immediately after an expirationto check for others.  In addition to expiring lookups,.B ar_timeout()alsotriggers resends of queries and the searching of the domain tree for thehost, the latter works from the.B _resstructure of.B resolv(5).   To delete entries from the queue,.B ar_delete()can be used and bypassing the pointer and size of the data segment, all queries have theirdata segments checked (if present) for an exact match, being deleted ifand 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 thatof the data stored for the queue entry being compared.   To close a socket opened by.B ar_open(),.B ar_close()should  be used sothat it is closed and also marked closed within this library.   .SH DIAGNOSIS.B 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..B ar_init()returns -1 for any errors, the value returned by.B res_init()if.B res_init()was called, the return value for.B ar_open()if that wascalled or the current socket open if 0 is passed and a socket is open.If neither.B res_init()or.B ar_open()are called and the flags are non-zero, -2 is returned. .B ar_gethostbyaddr()and.B ar_gethostbyname()will always return NULL in this version but may return a pointer to a hostentstructure if a cache is being used and the answer is found in the cache..B ar_answer()returns NULL if the answer is either not found or thequery returned an error and another attempt at a lookup is attempted.If an answer was found, it returned a pointer to this structure andthe contents of the data segment copied over..B ar_timeout()returns the time when it should be called next or 0 ifthere are no queries in the queue to be checked later.  If any queriesare expired, the data segment is copied over if dataptr is non NULL..B ar_delete()returns the number of entries that were found to matchand consequently deleted..SH SEE ALSOgethostbyaddr(3), gethostbyname(3), resolv(5).SH FILES.nfarlib.h/usr/include/resolv.h/usr/include/arpa/nameser.h/etc/resolv.conf.SH BUGSThe results of a successful call to ar_answer() destroy the structurefor any previous calls..SH AUTHORDarren Reed.  Email address: avalon@coombs.anu.edu.au

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -