logresolve.c revision e7157eb98138148328d992336570f1d3a9002928
e9458b1a7a19a63aa4c179f9ab20f4d50681c168Jens Elkner * logresolve 1.1
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * Tom Rathborne - tomr@uunet.ca - http://www.uunet.ca/~tomr/
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * UUNET Canada, April 16, 1995
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * Rewritten by David Robinson. (drtr@ast.cam.ac.uk)
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * Usage: logresolve [-s filename] [-c] < access_log > new_log
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * -s filename name of a file to record statistics
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * -c check the DNS for a matching A record for the host.
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * To generate meaningful statistics from an HTTPD log file, it's good
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * to have the domain name of each machine that accessed your site, but
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * doing this on the fly can slow HTTPD down.
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * Compiling NCSA HTTPD with the -DMINIMAL_DNS flag turns IP#->hostname
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * resolution off. Before running your stats program, just run your log
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * file through this program (logresolve) and all of your IP numbers will
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * be resolved into hostnames (where possible).
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * logresolve takes an HTTPD access log (in the COMMON log file format,
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * or any other format that has the IP number/domain name as the first
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * field for that matter), and outputs the same file with all of the
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * domain names looked up. Where no domain name can be found, the IP
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * number is left in.
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * To minimize impact on your nameserver, logresolve has its very own
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * internal hash-table cache. This means that each IP number will only
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * be looked up the first time it is found in the log file.
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * The -c option causes logresolve to apply the same check as httpd
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * compiled with -DMAXIMUM_DNS; after finding the hostname from the IP
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * address, it looks up the IP addresses for the hostname and checks
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * that one of these matches the original address.
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroederstatic void cgethost(struct in_addr ipnum, char *string, int check);
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroederstatic int get_line(char *s, int n);
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder/* maximum line length */
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder/* maximum length of a domain name */
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder/* number of buckets in cache hash apr_table_t */
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder if (!(dup = (char *) malloc(strlen(str) + 1)))
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * struct nsrec - record of nameservice for cache linked list
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * ipnum - IP number hostname - hostname noname - nonzero if IP number has no
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * hostname, i.e. hostname=IP number
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroeder * statistics - obvious
081559cfba7150d19604bdeafdc2d9983f7216b3Jonathan von Schroederextern __declspec(dllimport) int h_errno;
static int cachehits = 0;
static int cachesize = 0;
static int entries = 0;
static int resolves = 0;
static int withname = 0;
char *name;
cachesize++;
AF_INET);
if (check) {
char **hptr;
cachehits++;
char *ipstring;
for (i = 0; i < BUCKETS; i++)
ipstring);
static int get_line (char *s, int n)
char *cp;
if (cp)
int i, check;
#ifdef WIN32
/* If we apr'ify this code, apr_pool_create/apr_pool_destroy
* should perform the WSAStartup/WSACleanup for us.
check = 0;
exit(0);
for (i = 0; i < BUCKETS; i++)
errors[i] = 0;
entries++;
withname++;
withname++;
resolves++;
#ifdef WIN32
WSACleanup();
,statfile);