You define this DNS-class function.
Syntax
DNS fn=your-dns-function
Only the first applicable DNS function is called, starting from the most restrictive object. In the rare case that you need to call multiple DNS functions, the function can return REQ_NOACTION.
The DNS function must have this prototype:
int your_dns_function(pblock *pb, Session *sn, Request *rq);
To get the host name use:
pblock_findval("dns-host", rq->vars)
and set the host entry using the new NSAPI function
dns_set_hostent
The struct hostent * will not be freed by the caller but will be treated as a pointer to a static area, as with the gethostbyname call. Keep a pointer in a static variable in the custom DNS function and on the next call either use the same struct hostent or free it before allocating a new one.
The DNS function returns REQ_PROCEED if it is successful, and REQ_NOACTION if the next DNS function (or gethostbyname, if no other applicable DNS class functions exist) should be called instead. Any other return value is treated as failure to resolve the host name.
This example uses the normal gethostbyname call to resolve the host name:
#include <nsapi.h> int my_dns_func(pblock *pb, Session *sn, Request *rq) { char *host = pblock_findval("dns-host", rq->vars); struct hostent *hostent; hostent = gethostbyname(host); // replace with custom DNS implementation dns_set_hostent(hostent, sn, rq); return REQ_PROCEED; } |