#IPv6 patch by Arkadiusz Mi¶kiewicz <misiek@pld.org.pl> for webalizer >= 2.01-10
#
#Ported to Red Hat Linux/Fedora Core by Robert Scheck
#
--- webalizer-2.01-10/dns_resolv.c 2004-05-25 01:21:50.000000000 +0200
+++ webalizer-2.01-10/dns_resolv.c.ipv6 2004-05-25 01:35:12.000000000 +0200
@@ -61,6 +61,11 @@
#include <sys/types.h>
#endif
+/* ensure getaddrinfo/getnameinfo */
+#ifndef _NETDB_H
+#include <netdb.h>
+#endif
+
/* some systems need this */
#ifdef HAVE_MATH_H
#include <math.h>
@@ -266,9 +271,16 @@
strcpy(tmp_buf, buffer); /* save buffer in case of error */
if(parse_record(buffer)) /* parse the record */
{
- if((log_rec.addr.s_addr = inet_addr(log_rec.hostname)) != INADDR_NONE)
+ struct addrinfo hints, *ares;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_NUMERICHOST;
+ if (0 == getaddrinfo(log_rec.hostname, "0", &hints, &ares))
{
DBT q, r;
+ memcpy(&log_rec.addr, ares->ai_addr, ares->ai_addrlen);
+ freeaddrinfo(ares);
q.data = log_rec.hostname;
q.size = strlen(log_rec.hostname);
@@ -414,12 +426,10 @@
{
int size;
- struct hostent *res_ent;
-
close(child[i].inpipe[0]);
close(child[i].outpipe[1]);
- /* get struct in_addr here */
+ /* get struct sockaddr_storage here */
while((size = read(child[i].outpipe[0], child_buf, MAXHOST)))
{
if(size < 0)
@@ -429,37 +439,40 @@
}
else
{
+ char hbuf[NI_MAXHOST];
+
if(debug_mode)
printf("Child got work: %lx(%d)\n",
- *((unsigned long *)child_buf), size);
+ *(unsigned long *)((struct sockaddr*)child_buf)->sa_data, size);
- if((res_ent = gethostbyaddr(child_buf, size, AF_INET)))
+ if(0 == getnameinfo((struct sockaddr*)child_buf, sizeof(struct sockaddr_storage),
+ hbuf, sizeof(hbuf), NULL, 0, NI_NAMEREQD))
{
/* must be at least 4 chars */
- if (strlen(res_ent->h_name)>3)
+ if (strlen(hbuf)>3)
{
if(debug_mode)
- printf("Child got %s for %lx(%d), %d bytes\n",
- res_ent->h_name,
- *((unsigned long *)child_buf),
- size,strlen(res_ent->h_name));
+ printf("Child got %s for %x(%d), %d bytes\n",
+ hbuf,
+ *(unsigned long *)((struct sockaddr *)child_buf)->sa_data,
+ size,strlen(hbuf));
/* If long hostname, take max domain name part */
- if ((size = strlen(res_ent->h_name)) > MAXHOST-2)
- strcpy(child_buf,(res_ent->h_name+(size-MAXHOST+1)));
- else strcpy(child_buf, res_ent->h_name);
+ if ((size = strlen(hbuf)) > MAXHOST-2)
+ strcpy(child_buf,(hbuf+(size-MAXHOST+1)));
+ else strcpy(child_buf, hbuf);
size = strlen(child_buf);
}
else
{
if (debug_mode)
- printf("gethostbyaddr returned bad h_name!\n");
+ printf("getnameinfor returned bad hbuf!\n");
}
}
else
{
if(debug_mode)
- printf("gethostbyaddr returned NULL! (%d)\n",h_errno);
+ printf("getnameinfo didn't return any usable information!\n");
}
if (write(child[i].inpipe[1], child_buf, size) == -1)
@@ -538,8 +551,8 @@
if(trav) /* something to resolve */
{
- if (write(child[i].outpipe[1], &(trav->addr.s_addr),
- sizeof(trav->addr.s_addr)) != -1)
+ if (write(child[i].outpipe[1], &trav->addr,
+ sizeof(trav->addr)) != -1)
{
/* We will watch this child */
child[i].cur = trav;
@@ -547,10 +560,9 @@
max_fd = MAX(max_fd, child[i].inpipe[0]);
if(debug_mode)
- printf("Giving %s (%lx) to Child %d for resolving\n",
+ printf("Giving %s (%x) to Child %d for resolving\n",
child[i].cur->string,
- (unsigned long)child[i].cur->addr.s_addr, i);
-
+ *(unsigned long *)((struct sockaddr *)&child[i].cur->addr)->sa_data, i);
trav = trav->llist;
}
else /* write error */
@@ -640,8 +652,8 @@
default:
{
dns_buf[size] = '\0';
- if(memcmp(dns_buf, &(child[i].cur->addr.s_addr),
- sizeof(child[i].cur->addr.s_addr)))
+ if(memcmp(dns_buf, &(child[i].cur->addr),
+ sizeof(child[i].cur->addr)))
{
if(debug_mode)
printf("Got a result (%d): %s -> %s\n",
--- webalizer-2.01-10/hashtab.c 2001-06-15 10:34:24.000000000 +0200
+++ webalizer-2.01-10/hashtab.c.ipv6 2004-05-25 01:36:24.000000000 +0200
@@ -976,7 +976,7 @@
/* PUT_DNODE - insert/update dns host node */
/*********************************************/
-int put_dnode(char *str, struct in_addr *addr, DNODEPTR *htab)
+int put_dnode(char *str, struct sockaddr_storage *addr, DNODEPTR *htab)
{
DNODEPTR cptr,nptr;
@@ -988,8 +988,8 @@
/* not hashed */
if ( (nptr=new_dnode(str)) != NULL)
{
- if (addr) memcpy(&nptr->addr, addr, sizeof(struct in_addr));
- else memset(&nptr->addr, 0, sizeof(struct in_addr));
+ if (addr) memcpy(&nptr->addr, addr, sizeof(struct sockaddr_storage));
+ else memset(&nptr->addr, 0, sizeof(struct sockaddr_storage));
nptr->next = NULL;
htab[hash(str)] = nptr;
}
@@ -1005,8 +1005,8 @@
/* not found... */
if ( (nptr = new_dnode(str)) != NULL)
{
- if (addr) memcpy(&nptr->addr, addr, sizeof(struct in_addr));
- else memset(&nptr->addr, 0, sizeof(struct in_addr));
+ if (addr) memcpy(&nptr->addr, addr, sizeof(struct sockaddr_storage));
+ else memset(&nptr->addr, 0, sizeof(struct sockaddr_storage));
nptr->next = htab[hash(str)];
htab[hash(str)]=nptr;
}
--- webalizer-2.01-10/hashtab.h 2000-09-29 05:50:30.000000000 +0200
+++ webalizer-2.01-10/hashtab.h.ipv6 2004-05-25 01:37:26.000000000 +0200
@@ -18,7 +18,7 @@
#ifdef USE_DNS
struct dnode { char *string; /* DNS node hash table struct */
- struct in_addr addr;
+ struct sockaddr_storage addr;
struct dnode *llist;
struct dnode *next; };
#endif
@@ -87,7 +87,7 @@
extern int put_snode(char *, u_long, SNODEPTR *);
#ifdef USE_DNS
-extern int put_dnode(char *, struct in_addr *, DNODEPTR *);
+extern int put_dnode(char *, struct sockaddr_storage *, DNODEPTR *);
extern void del_dlist(DNODEPTR *);
#endif
--- webalizer-2.01-10/parser.c 2001-06-15 10:34:24.000000000 +0200
+++ webalizer-2.01-10/parser.c.ipv6 2004-05-25 01:37:56.000000000 +0200
@@ -114,7 +114,7 @@
log_rec.ident[0]=0;
*/
#ifdef USE_DNS
- memset(&log_rec.addr,0,sizeof(struct in_addr));
+ memset(&log_rec.addr,0,sizeof(struct sockaddr_storage));
#endif
/* call appropriate handler */
--- webalizer-2.01-10/webalizer.c 2004-05-25 01:21:50.000000000 +0200
+++ webalizer-2.01-10/webalizer.c.ipv6 2004-05-25 01:39:31.000000000 +0200
@@ -63,6 +63,7 @@
#ifdef USE_DNS
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <netdb.h>
#ifdef HAVE_DB_185_H
#include <db_185.h>
@@ -991,8 +992,15 @@
/* Resolve IP address if needed */
if (dns_db)
{
- if (inet_addr(log_rec.hostname) != INADDR_NONE)
- resolve_dns(&log_rec);
+ struct addrinfo hints, *ares;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_STREAM;
+ hints.ai_flags = AI_NUMERICHOST;
+ if (0 == getaddrinfo(log_rec.hostname, "0", &hints, &ares)) {
+ freeaddrinfo(ares);
+ resolve_dns(&log_rec);
+ }
}
#endif
--- webalizer-2.01-10/webalizer.h 2001-02-10 01:58:18.000000000 +0100
+++ webalizer-2.01-10/webalizer.h.ipv6 2004-05-25 01:40:09.000000000 +0200
@@ -143,7 +143,7 @@
int resp_code; /* response code */
u_long xfer_size; /* xfer size in bytes */
#ifdef USE_DNS
- struct in_addr addr; /* IP address structure */
+ struct sockaddr_storage addr; /* IP address structure */
#endif /* USE_DNS */
char refer[MAXREF]; /* referrer */
char agent[MAXAGENT]; /* user agent (browser) */