logresolve.c revision b76764362f1f69ced135b0f2e1481a26fef04347
2a0b626c070fea0a68a071a4160ff695eb4731dand/* Licensed to the Apache Software Foundation (ASF) under one or more
2a0b626c070fea0a68a071a4160ff695eb4731dand * contributor license agreements. See the NOTICE file distributed with
2a0b626c070fea0a68a071a4160ff695eb4731dand * this work for additional information regarding copyright ownership.
2a0b626c070fea0a68a071a4160ff695eb4731dand * The ASF licenses this file to You under the Apache License, Version 2.0
2a0b626c070fea0a68a071a4160ff695eb4731dand * (the "License"); you may not use this file except in compliance with
2a0b626c070fea0a68a071a4160ff695eb4731dand * the License. You may obtain a copy of the License at
2a0b626c070fea0a68a071a4160ff695eb4731dand *
2a0b626c070fea0a68a071a4160ff695eb4731dand * http://www.apache.org/licenses/LICENSE-2.0
2a0b626c070fea0a68a071a4160ff695eb4731dand *
2a0b626c070fea0a68a071a4160ff695eb4731dand * Unless required by applicable law or agreed to in writing, software
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * distributed under the License is distributed on an "AS IS" BASIS,
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * See the License for the specific language governing permissions and
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * limitations under the License.
2a0b626c070fea0a68a071a4160ff695eb4731dand */
2a0b626c070fea0a68a071a4160ff695eb4731dand
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen/*
3f08db06526d6901aa08c110b5bc7dde6bc39905nd * logresolve 2.0
2a0b626c070fea0a68a071a4160ff695eb4731dand *
2a0b626c070fea0a68a071a4160ff695eb4731dand * Tom Rathborne - tomr uunet.ca - http://www.uunet.ca/~tomr/
2a0b626c070fea0a68a071a4160ff695eb4731dand * UUNET Canada, April 16, 1995
3f08db06526d6901aa08c110b5bc7dde6bc39905nd *
2a0b626c070fea0a68a071a4160ff695eb4731dand * Rewritten by David Robinson. (drtr ast.cam.ac.uk)
2a0b626c070fea0a68a071a4160ff695eb4731dand * Rewritten again, and ported to APR by Colm MacCarthaigh
2a0b626c070fea0a68a071a4160ff695eb4731dand *
27dcd8d81085fd60aadcd8a9bad35a607b26b758nilgun * Usage: logresolve [-s filename] [-c] < access_log > new_log
2a0b626c070fea0a68a071a4160ff695eb4731dand *
e609c337f729875bc20e01096c7e610f45356f54nilgun * Arguments:
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung * -s filename name of a file to record statistics
2a0b626c070fea0a68a071a4160ff695eb4731dand * -c check the DNS for a matching A record for the host.
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem *
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * Notes: (For historical interest)
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem *
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem * To generate meaningful statistics from an HTTPD log file, it's good
2a0b626c070fea0a68a071a4160ff695eb4731dand * to have the domain name of each machine that accessed your site, but
2a0b626c070fea0a68a071a4160ff695eb4731dand * doing this on the fly can slow HTTPD down.
2a0b626c070fea0a68a071a4160ff695eb4731dand *
2a0b626c070fea0a68a071a4160ff695eb4731dand * Compiling NCSA HTTPD with the -DMINIMAL_DNS flag turns IP#->hostname
2a0b626c070fea0a68a071a4160ff695eb4731dand * resolution off. Before running your stats program, just run your log
2a0b626c070fea0a68a071a4160ff695eb4731dand * file through this program (logresolve) and all of your IP numbers will
2a0b626c070fea0a68a071a4160ff695eb4731dand * be resolved into hostnames (where possible).
2a0b626c070fea0a68a071a4160ff695eb4731dand *
2a0b626c070fea0a68a071a4160ff695eb4731dand * logresolve takes an HTTPD access log (in the COMMON log file format,
2a0b626c070fea0a68a071a4160ff695eb4731dand * or any other format that has the IP number/domain name as the first
2a0b626c070fea0a68a071a4160ff695eb4731dand * field for that matter), and outputs the same file with all of the
2a0b626c070fea0a68a071a4160ff695eb4731dand * domain names looked up. Where no domain name can be found, the IP
2a0b626c070fea0a68a071a4160ff695eb4731dand * number is left in.
2a0b626c070fea0a68a071a4160ff695eb4731dand *
2a0b626c070fea0a68a071a4160ff695eb4731dand * To minimize impact on your nameserver, logresolve has its very own
2a0b626c070fea0a68a071a4160ff695eb4731dand * internal hash-table cache. This means that each IP number will only
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh * be looked up the first time it is found in the log file.
2a0b626c070fea0a68a071a4160ff695eb4731dand *
2a0b626c070fea0a68a071a4160ff695eb4731dand * The -c option causes logresolve to apply the same check as httpd
2a0b626c070fea0a68a071a4160ff695eb4731dand * compiled with -DMAXIMUM_DNS; after finding the hostname from the IP
2a0b626c070fea0a68a071a4160ff695eb4731dand * address, it looks up the IP addresses for the hostname and checks
2a0b626c070fea0a68a071a4160ff695eb4731dand * that one of these matches the original address.
2a0b626c070fea0a68a071a4160ff695eb4731dand */
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand#include "apr.h"
2a0b626c070fea0a68a071a4160ff695eb4731dand#include "apr_lib.h"
2a0b626c070fea0a68a071a4160ff695eb4731dand#include "apr_hash.h"
2a0b626c070fea0a68a071a4160ff695eb4731dand#include "apr_getopt.h"
2a0b626c070fea0a68a071a4160ff695eb4731dand#include "apr_strings.h"
2a0b626c070fea0a68a071a4160ff695eb4731dand#include "apr_file_io.h"
2a0b626c070fea0a68a071a4160ff695eb4731dand#include "apr_network_io.h"
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand#if APR_HAVE_STDLIB_H
2a0b626c070fea0a68a071a4160ff695eb4731dand#include <stdlib.h>
2a0b626c070fea0a68a071a4160ff695eb4731dand#endif
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand#define READ_BUF_SIZE 10240
2a0b626c070fea0a68a071a4160ff695eb4731dand#define WRITE_BUF_SIZE 10240
2a0b626c070fea0a68a071a4160ff695eb4731dand#define LINE_BUF_SIZE 2048
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dandstatic apr_file_t *errfile;
2a0b626c070fea0a68a071a4160ff695eb4731dandstatic const char *shortname = "logresolve";
2a0b626c070fea0a68a071a4160ff695eb4731dandstatic apr_hash_t *cache;
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand/* Statistics */
2a0b626c070fea0a68a071a4160ff695eb4731dandstatic int cachehits = 0;
2a0b626c070fea0a68a071a4160ff695eb4731dandstatic int cachesize = 0;
2a0b626c070fea0a68a071a4160ff695eb4731dandstatic int entries = 0;
2a0b626c070fea0a68a071a4160ff695eb4731dandstatic int resolves = 0;
2a0b626c070fea0a68a071a4160ff695eb4731dandstatic int withname = 0;
2a0b626c070fea0a68a071a4160ff695eb4731dandstatic int doublefailed = 0;
2a0b626c070fea0a68a071a4160ff695eb4731dandstatic int noreverse = 0;
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand/*
2a0b626c070fea0a68a071a4160ff695eb4731dand * prints various statistics to output
2a0b626c070fea0a68a071a4160ff695eb4731dand */
2a0b626c070fea0a68a071a4160ff695eb4731dand#define NL APR_EOL_STR
2a0b626c070fea0a68a071a4160ff695eb4731dandstatic void print_statistics (apr_file_t *output)
2a0b626c070fea0a68a071a4160ff695eb4731dand{
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_file_printf(output, "logresolve Statistics:" NL);
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_file_printf(output, "Entries: %d" NL, entries);
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_file_printf(output, " With name : %d" NL, withname);
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_file_printf(output, " Resolves : %d" NL, resolves);
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand if (noreverse) {
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_file_printf(output, " - No reverse : %d" NL,
2a0b626c070fea0a68a071a4160ff695eb4731dand noreverse);
2a0b626c070fea0a68a071a4160ff695eb4731dand }
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand if (doublefailed) {
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_file_printf(output, " - Double lookup failed : %d" NL,
2a0b626c070fea0a68a071a4160ff695eb4731dand doublefailed);
2a0b626c070fea0a68a071a4160ff695eb4731dand }
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_file_printf(output, "Cache hits : %d" NL, cachehits);
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_file_printf(output, "Cache size : %d" NL, cachesize);
2a0b626c070fea0a68a071a4160ff695eb4731dand}
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand/*
2a0b626c070fea0a68a071a4160ff695eb4731dand * usage info
2a0b626c070fea0a68a071a4160ff695eb4731dand */
2a0b626c070fea0a68a071a4160ff695eb4731dandstatic void usage(void)
2a0b626c070fea0a68a071a4160ff695eb4731dand{
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_file_printf(errfile,
2a0b626c070fea0a68a071a4160ff695eb4731dand "%s -- Resolve IP-addresses to hostnames in Apache log files." NL
2a0b626c070fea0a68a071a4160ff695eb4731dand "Usage: %s [-s STATFILE] [-c]" NL
2a0b626c070fea0a68a071a4160ff695eb4731dand NL
2a0b626c070fea0a68a071a4160ff695eb4731dand "Options:" NL
2a0b626c070fea0a68a071a4160ff695eb4731dand " -s Record statistics to STATFILE when finished." NL
2a0b626c070fea0a68a071a4160ff695eb4731dand NL
2a0b626c070fea0a68a071a4160ff695eb4731dand " -c Perform double lookups when resolving IP addresses." NL,
2a0b626c070fea0a68a071a4160ff695eb4731dand shortname, shortname);
2a0b626c070fea0a68a071a4160ff695eb4731dand exit(1);
2a0b626c070fea0a68a071a4160ff695eb4731dand}
2a0b626c070fea0a68a071a4160ff695eb4731dand#undef NL
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dandint main(int argc, const char * const argv[])
2a0b626c070fea0a68a071a4160ff695eb4731dand{
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_file_t * outfile;
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_file_t * infile;
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_getopt_t * o;
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_pool_t * pool;
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_pool_t *pline;
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_status_t status;
2a0b626c070fea0a68a071a4160ff695eb4731dand const char * arg;
2a0b626c070fea0a68a071a4160ff695eb4731dand char * stats = NULL;
2a0b626c070fea0a68a071a4160ff695eb4731dand#if APR_MAJOR_VERSION > 1 || (APR_MAJOR_VERSION == 1 && APR_MINOR_VERSION >= 3)
2a0b626c070fea0a68a071a4160ff695eb4731dand char * inbuffer;
2a0b626c070fea0a68a071a4160ff695eb4731dand char * outbuffer;
2a0b626c070fea0a68a071a4160ff695eb4731dand#endif
2a0b626c070fea0a68a071a4160ff695eb4731dand char line[LINE_BUF_SIZE];
2a0b626c070fea0a68a071a4160ff695eb4731dand int doublelookups = 0;
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand if (apr_app_initialize(&argc, &argv, NULL) != APR_SUCCESS) {
2a0b626c070fea0a68a071a4160ff695eb4731dand return 1;
2a0b626c070fea0a68a071a4160ff695eb4731dand }
2a0b626c070fea0a68a071a4160ff695eb4731dand atexit(apr_terminate);
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand if (argc) {
2a0b626c070fea0a68a071a4160ff695eb4731dand shortname = apr_filepath_name_get(argv[0]);
2a0b626c070fea0a68a071a4160ff695eb4731dand }
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand if (apr_pool_create(&pool, NULL) != APR_SUCCESS) {
2a0b626c070fea0a68a071a4160ff695eb4731dand return 1;
2a0b626c070fea0a68a071a4160ff695eb4731dand }
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_file_open_stderr(&errfile, pool);
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_getopt_init(&o, pool, argc, argv);
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand while (1) {
2a0b626c070fea0a68a071a4160ff695eb4731dand char opt;
2a0b626c070fea0a68a071a4160ff695eb4731dand status = apr_getopt(o, "s:c", &opt, &arg);
2a0b626c070fea0a68a071a4160ff695eb4731dand if (status == APR_EOF) {
2a0b626c070fea0a68a071a4160ff695eb4731dand break;
2a0b626c070fea0a68a071a4160ff695eb4731dand }
2a0b626c070fea0a68a071a4160ff695eb4731dand else if (status != APR_SUCCESS) {
2a0b626c070fea0a68a071a4160ff695eb4731dand usage();
2a0b626c070fea0a68a071a4160ff695eb4731dand }
2a0b626c070fea0a68a071a4160ff695eb4731dand else {
2a0b626c070fea0a68a071a4160ff695eb4731dand switch (opt) {
2a0b626c070fea0a68a071a4160ff695eb4731dand case 'c':
2a0b626c070fea0a68a071a4160ff695eb4731dand if (doublelookups) {
2a0b626c070fea0a68a071a4160ff695eb4731dand usage();
2a0b626c070fea0a68a071a4160ff695eb4731dand }
2a0b626c070fea0a68a071a4160ff695eb4731dand doublelookups = 1;
2a0b626c070fea0a68a071a4160ff695eb4731dand break;
2a0b626c070fea0a68a071a4160ff695eb4731dand case 's':
2a0b626c070fea0a68a071a4160ff695eb4731dand if (stats) {
2a0b626c070fea0a68a071a4160ff695eb4731dand usage();
2a0b626c070fea0a68a071a4160ff695eb4731dand }
2a0b626c070fea0a68a071a4160ff695eb4731dand stats = apr_pstrdup(pool, arg);
2a0b626c070fea0a68a071a4160ff695eb4731dand break;
2a0b626c070fea0a68a071a4160ff695eb4731dand } /* switch */
2a0b626c070fea0a68a071a4160ff695eb4731dand } /* else */
2a0b626c070fea0a68a071a4160ff695eb4731dand } /* while */
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_file_open_stdout(&outfile, pool);
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_file_open_stdin(&infile, pool);
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand#if APR_MAJOR_VERSION > 1 || (APR_MAJOR_VERSION == 1 && APR_MINOR_VERSION >= 3)
2a0b626c070fea0a68a071a4160ff695eb4731dand /* Allocate two new 10k file buffers */
2a0b626c070fea0a68a071a4160ff695eb4731dand if ((outbuffer = apr_palloc(pool, WRITE_BUF_SIZE)) == NULL ||
2a0b626c070fea0a68a071a4160ff695eb4731dand (inbuffer = apr_palloc(pool, READ_BUF_SIZE)) == NULL) {
2a0b626c070fea0a68a071a4160ff695eb4731dand return 1;
2a0b626c070fea0a68a071a4160ff695eb4731dand }
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand /* Set the buffers */
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_file_buffer_set(infile, inbuffer, READ_BUF_SIZE);
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_file_buffer_set(outfile, outbuffer, WRITE_BUF_SIZE);
2a0b626c070fea0a68a071a4160ff695eb4731dand#endif
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand cache = apr_hash_make(pool);
2a0b626c070fea0a68a071a4160ff695eb4731dand if(apr_pool_create(&pline, NULL) != APR_SUCCESS){
2a0b626c070fea0a68a071a4160ff695eb4731dand return 1;
2a0b626c070fea0a68a071a4160ff695eb4731dand }
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand while (apr_file_gets(line, sizeof(line), infile) == APR_SUCCESS) {
2a0b626c070fea0a68a071a4160ff695eb4731dand char *hostname;
2a0b626c070fea0a68a071a4160ff695eb4731dand char *space;
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_sockaddr_t *ip;
2a0b626c070fea0a68a071a4160ff695eb4731dand apr_sockaddr_t *ipdouble;
2a0b626c070fea0a68a071a4160ff695eb4731dand char dummy[] = " " APR_EOL_STR;
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand if (line[0] == '\0') {
2a0b626c070fea0a68a071a4160ff695eb4731dand continue;
2a0b626c070fea0a68a071a4160ff695eb4731dand }
2a0b626c070fea0a68a071a4160ff695eb4731dand
2a0b626c070fea0a68a071a4160ff695eb4731dand /* Count our log entries */
2a0b626c070fea0a68a071a4160ff695eb4731dand entries++;
27dcd8d81085fd60aadcd8a9bad35a607b26b758nilgun
2a0b626c070fea0a68a071a4160ff695eb4731dand /* Check if this could even be an IP address */
e609c337f729875bc20e01096c7e610f45356f54nilgun if (!apr_isxdigit(line[0]) && line[0] != ':') {
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung withname++;
727872d18412fc021f03969b8641810d8896820bhumbedooh apr_file_puts(line, outfile);
0d0ba3a410038e179b695446bb149cce6264e0abnd continue;
727872d18412fc021f03969b8641810d8896820bhumbedooh }
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh
0d0ba3a410038e179b695446bb149cce6264e0abnd /* Terminate the line at the next space */
cc7e1025de9ac63bd4db6fe7f71c158b2cf09fe4humbedooh if ((space = strchr(line, ' ')) != NULL) {
727872d18412fc021f03969b8641810d8896820bhumbedooh *space = '\0';
0d0ba3a410038e179b695446bb149cce6264e0abnd }
0d0ba3a410038e179b695446bb149cce6264e0abnd else {
0d0ba3a410038e179b695446bb149cce6264e0abnd space = dummy;
727872d18412fc021f03969b8641810d8896820bhumbedooh }
0d0ba3a410038e179b695446bb149cce6264e0abnd
0d0ba3a410038e179b695446bb149cce6264e0abnd /* See if we have it in our cache */
0d0ba3a410038e179b695446bb149cce6264e0abnd hostname = (char *) apr_hash_get(cache, line, APR_HASH_KEY_STRING);
727872d18412fc021f03969b8641810d8896820bhumbedooh if (hostname) {
0d0ba3a410038e179b695446bb149cce6264e0abnd apr_file_printf(outfile, "%s %s", hostname, space + 1);
0d0ba3a410038e179b695446bb149cce6264e0abnd cachehits++;
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh continue;
5effc8b39fae5cd169d17f342bfc265705840014rbowen }
d229f940abfb2490dee17979e9a5ff31b7012eb5rbowen
0d0ba3a410038e179b695446bb149cce6264e0abnd /* Parse the IP address */
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd status = apr_sockaddr_info_get(&ip, line, APR_UNSPEC, 0, 0, pline);
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd if (status != APR_SUCCESS) {
7fec19672a491661b2fe4b29f685bc7f4efa64d4nd /* Not an IP address */
2a0b626c070fea0a68a071a4160ff695eb4731dand withname++;
*space = ' ';
apr_file_puts(line, outfile);
continue;
}
/* This does not make much sense, but historically "resolves" means
* "parsed as an IP address". It does not mean we actually resolved
* the IP address into a hostname.
*/
resolves++;
/* From here on our we cache each result, even if it was not
* succesful
*/
cachesize++;
/* Try and perform a reverse lookup */
status = apr_getnameinfo(&hostname, ip, 0) != APR_SUCCESS;
if (status || hostname == NULL) {
/* Could not perform a reverse lookup */
*space = ' ';
apr_file_puts(line, outfile);
noreverse++;
/* Add to cache */
*space = '\0';
apr_hash_set(cache, line, APR_HASH_KEY_STRING,
apr_pstrdup(pool, line));
continue;
}
/* Perform a double lookup */
if (doublelookups) {
/* Do a forward lookup on our hostname, and see if that matches our
* original IP address.
*/
status = apr_sockaddr_info_get(&ipdouble, hostname, ip->family, 0,
0, pline);
if (status == APR_SUCCESS ||
memcmp(ipdouble->ipaddr_ptr, ip->ipaddr_ptr, ip->ipaddr_len)) {
/* Double-lookup failed */
*space = ' ';
apr_file_puts(line, outfile);
doublefailed++;
/* Add to cache */
*space = '\0';
apr_hash_set(cache, line, APR_HASH_KEY_STRING,
apr_pstrdup(pool, line));
continue;
}
}
/* Outout the resolved name */
apr_file_printf(outfile, "%s %s", hostname, space + 1);
/* Store it in the cache */
apr_hash_set(cache, line, APR_HASH_KEY_STRING,
apr_pstrdup(pool, hostname));
apr_pool_clear(pline);
}
/* Flush any remaining output */
apr_file_flush(outfile);
if (stats) {
apr_file_t *statsfile;
if (apr_file_open(&statsfile, stats,
APR_FOPEN_WRITE | APR_FOPEN_CREATE | APR_FOPEN_TRUNCATE,
APR_OS_DEFAULT, pool) != APR_SUCCESS) {
apr_file_printf(errfile, "%s: Could not open %s for writing.",
shortname, stats);
return 1;
}
print_statistics(statsfile);
apr_file_close(statsfile);
}
return 0;
}