From sasha@direct1.com Thu Jun 17 00:56:37 1999 Date: Wed, 16 Jun 1999 14:49:22 +0000 From: Sasha Pachev To: brad@mrunix.net Subject: Patch to do reverse DNS lookup Brad: I really liked you Webalizer. Compiled right out of the box, make install fix the config file to tell it where my logs are and where to put the results, and lo and behold, got a beautiful report with all the stuff I needed, with only one exception. I configure my Apache not to do reverse lookups, but I wanted to see them in the reports. Well, here is the beauty of open source - I wrote a patch to do it, first just dumb straighforward way, too slow , then optimized a bit to cache previous lookups, still too slow because some stupid DNS servers are just down, and the default resovler timeouts are set too high, so I added a hack to do a forced timeout of gethostbyaddr(). The hack is really ugly, that's why I call it a hack, but I could not come up with anything cleaner. gethostbyaddr() will retry if you terminate a select() with SIGALRM, so I really had only two choices - either mess with _res structure in the signal handler before returning control to gethostbyaddr() or do longjmp() back out of gethostbyaddr(). Of the two evils I chose the latter. Let me know if you are aware of a better solution. On some systems it may cause a resource leak if gethostbyaddr() allocates resources that it frees only after select() that I am timing out. I am also not doing a proper cleanup of the DNS cache resources, because this will be done by the system on exit anyway. In the future, this may be useful right before generating a report to re-claim some memory so there would be enough to do the job. Anyway, here is the patch for version 1.22_06. To apply just run patch < reverse_lookup.patch in the source directory. It adds three options to the config file: ReverseLookup, DNSCache , and DNSTimeout . Let me know what you think. Also, if there are any features that you are working on and would like to delegate, I am available. -- Sasha Pachev http://www.sashanet.com/ (home) http://www.direct1.com/ (work)