Introduction
Introduction Statistics Contact Development Disclaimer Help
Adding reverse lookup to log entries. Thanks to James Penketh <tamber@furryheli…
git clone git://bitreich.org/geomyidae/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfri…
Log
Files
Refs
Tags
README
LICENSE
---
commit a0495a999191b84a00f2586b7089c99947d0de93
parent cb73df5b7e3746edcb70fd57b462161efec5385a
Author: Christoph Lohmann <[email protected]>
Date: Sun, 27 Feb 2011 12:32:54 +0100
Adding reverse lookup to log entries. Thanks to James Penketh
<[email protected]>!
Diffstat:
M ind.c | 25 +++++++++++++++++++++++++
M ind.h | 1 +
M main.c | 13 ++++++-------
3 files changed, 32 insertions(+), 7 deletions(-)
---
diff --git a/ind.c b/ind.c
@@ -10,6 +10,10 @@
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
+#include <netdb.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
#include "ind.h"
#include "handlr.h"
@@ -285,3 +289,24 @@ smprintf(char *fmt, ...)
return ret;
}
+char *
+reverselookup(char *host)
+{
+ struct in_addr hoststr;
+ struct hostent *client;
+ char *rethost;
+
+ rethost = NULL;
+
+ if(inet_pton(AF_INET, host, &hoststr)) {
+ client = gethostbyaddr(&hoststr, sizeof(hoststr), AF_INET);
+ if(client != NULL)
+ rethost = strdup(client->h_name);
+ }
+
+ if(rethost == NULL)
+ rethost = strdup(host);
+
+ return rethost;
+}
+
diff --git a/ind.h b/ind.h
@@ -43,6 +43,7 @@ void tprintf(int fd, char *fmt, ...);
int initlogging(char *logf);
void stoplogging(int fd);
char *smprintf(char *fmt, ...);
+char *reverselookup(char *host);
#endif
diff --git a/main.c b/main.c
@@ -19,6 +19,7 @@
#include <time.h>
#include <pwd.h>
#include <grp.h>
+
#include "ind.h"
#include "handlr.h"
#include "arg.h"
@@ -102,17 +103,19 @@ logentry(char *host, char *port, char *qry, char *status)
{
time_t tim;
struct tm *ptr;
- char timstr[128];
+ char timstr[128], *ahost;
if(glfd >= 0) {
tim = time(0);
ptr = localtime(&tim);
+ ahost = reverselookup(host);
strftime(timstr, sizeof(timstr), "%a %b %d %H:%M:%S %Z %Y",
ptr);
tprintf(glfd, "[%s|%s:%s] %s (%s)\n",
- timstr, host, port, qry, status);
+ timstr, ahost, port, qry, status);
+ free(ahost);
}
return;
@@ -364,11 +367,7 @@ main(int argc, char *argv[])
return 1;
}
- if(dofork) {
- signal(SIGINT, SIG_IGN);
- signal(SIGQUIT, SIG_IGN);
- }
- signal(SIGCHLD, hndlsigchld);
+ initsignals();
cltlen = sizeof(clt);
while(running) {
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.