logresolve.c revision cf79f5a1c696efe7c0b959a3c375f669ac496065
252N/A/* Licensed to the Apache Software Foundation (ASF) under one or more 252N/A * contributor license agreements. See the NOTICE file distributed with 252N/A * this work for additional information regarding copyright ownership. 252N/A * The ASF licenses this file to You under the Apache License, Version 2.0 252N/A * (the "License"); you may not use this file except in compliance with 252N/A * the License. You may obtain a copy of the License at 252N/A * Unless required by applicable law or agreed to in writing, software 252N/A * distributed under the License is distributed on an "AS IS" BASIS, 252N/A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 252N/A * See the License for the specific language governing permissions and 252N/A * limitations under the License. 252N/A * UUNET Canada, April 16, 1995 252N/A * Rewritten by David Robinson. (drtr ast.cam.ac.uk) 252N/A * Rewritten again, and ported to APR by Colm MacCarthaigh 252N/A * Usage: logresolve [-s filename] [-c] < access_log > new_log 252N/A * -s filename name of a file to record statistics 252N/A * -c check the DNS for a matching A record for the host. 252N/A * Notes: (For historical interest) 252N/A * To generate meaningful statistics from an HTTPD log file, it's good 252N/A * to have the domain name of each machine that accessed your site, but 252N/A * doing this on the fly can slow HTTPD down. 252N/A * Compiling NCSA HTTPD with the -DMINIMAL_DNS flag turns IP#->hostname 252N/A * resolution off. Before running your stats program, just run your log 252N/A * file through this program (logresolve) and all of your IP numbers will 252N/A * be resolved into hostnames (where possible). 252N/A * logresolve takes an HTTPD access log (in the COMMON log file format, 252N/A * field for that matter), and outputs the same file with all of the 252N/A * domain names looked up. Where no domain name can be found, the IP 252N/A * To minimize impact on your nameserver, logresolve has its very own 252N/A * internal hash-table cache. This means that each IP number will only 252N/A * be looked up the first time it is found in the log file. 252N/A * The -c option causes logresolve to apply the same check as httpd 252N/A * compiled with -DMAXIMUM_DNS; after finding the hostname from the IP 252N/A * address, it looks up the IP addresses for the hostname and checks 252N/A * that one of these matches the original address. 252N/A * prints various statistics to output 252N/A "%s -- Resolve IP-addresses to hostnames in Apache log files." NL 252N/A "Usage: %s [-s STATFILE] [-c]" NL 252N/A " -s Record statistics to STATFILE when finished." NL 252N/A " -c Perform double lookups when resolving IP addresses." NL,
252N/A /* Allocate two new 10k file buffers */ 252N/A /* Count our log entries */ 252N/A /* Check if this could even be an IP address */ 252N/A /* Terminate the line at the next space */ 252N/A /* See if we have it in our cache */ 252N/A /* Parse the IP address */ 252N/A /* Not an IP address */ 252N/A /* This does not make much sense, but historically "resolves" means 252N/A * "parsed as an IP address". It does not mean we actually resolved 252N/A * the IP address into a hostname. 252N/A /* From here on our we cache each result, even if it was not 252N/A /* Try and perform a reverse lookup */ 252N/A /* Could not perform a reverse lookup */ 252N/A /* Perform a double lookup */ 252N/A /* Do a forward lookup on our hostname, and see if that matches our 252N/A /* Double-lookup failed */ 252N/A /* Outout the resolved name */ 252N/A /* Store it in the cache */ 252N/A /* Flush any remaining output */