logresolve.c revision 0abdf2011dc34cf3251a61fda516c7ff64c39a11
2073N/A * UUNET Canada, April 16, 1995 2073N/A * Rewritten by David Robinson. (drtr@ast.cam.ac.uk) 2073N/A * Usage: logresolve [-s filename] [-c] < access_log > new_log 2073N/A * -s filename name of a file to record statistics 2073N/A * -c check the DNS for a matching A record for the host. 2073N/A * To generate meaningful statistics from an HTTPD log file, it's good 2073N/A * to have the domain name of each machine that accessed your site, but 2073N/A * doing this on the fly can slow HTTPD down. 2073N/A * Compiling NCSA HTTPD with the -DMINIMAL_DNS flag turns IP#->hostname 2073N/A * resolution off. Before running your stats program, just run your log 2899N/A * file through this program (logresolve) and all of your IP numbers will 2073N/A * be resolved into hostnames (where possible). 2073N/A * logresolve takes an HTTPD access log (in the COMMON log file format, 2073N/A * field for that matter), and outputs the same file with all of the 2073N/A * domain names looked up. Where no domain name can be found, the IP 2073N/A * To minimize impact on your nameserver, logresolve has its very own 2073N/A * internal hash-table cache. This means that each IP number will only 2073N/A * be looked up the first time it is found in the log file. 2073N/A * The -c option causes logresolve to apply the same check as httpd 2073N/A * compiled with -DMAXIMUM_DNS; after finding the hostname from the IP 2899N/A * address, it looks up the IP addresses for the hostname and checks 2899N/A * that one of these matches the original address. 2073N/A/* maximum length of a domain name */ 2073N/A/* number of buckets in cache hash apr_table_t */ * struct nsrec - record of nameservice for cache linked list * ipnum - IP number hostname - hostname noname - nonzero if IP number has no * hostname, i.e. hostname=IP number extern int h_errno;
/* some machines don't have this in their headers */ /* largest value for h_errno */ * cgethost - gets hostname by IP address, caching, and adding unresolvable * IP numbers with their IP number as hostname, setting noname flag /* size of string == MAXDNAME +1 */ * prints various statistics to output static int getline (
char *s,
int n)
for (i =
1; i <
argc; i++) {
fprintf(
stderr,
"Usage: logresolve [-s statfile] [-c] < input > output\n");
fprintf(
stderr,
"logresolve: could not open statistics file '%s'\n"