summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoern Engel <joern@logfs.org>2012-01-17 10:55:18 -0800
committerJoern Engel <joern@logfs.org>2012-01-17 10:55:18 -0800
commite815d5623985abab7c23f77c43f0e0a3e93b489d (patch)
tree4c69be1eb00cb05f2f36f97f4cd724c1bfd532e4
parent36b9d7badd1158bb00be1afe2d6ce9b6ad27adde (diff)
downloadcancd-e815d5623985abab7c23f77c43f0e0a3e93b489d.tar.gz
Normalize and shorten filenamesv0.2.0
Turns TESTHOST07.bla.com into testhost07. Signed-off-by: Joern Engel <joern@logfs.org>
-rw-r--r--cancd.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/cancd.c b/cancd.c
index 639303c..8416d5a 100644
--- a/cancd.c
+++ b/cancd.c
@@ -27,6 +27,7 @@
#include <arpa/inet.h>
#include <assert.h>
+#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
@@ -678,7 +679,8 @@ static void dns_visitor(void *_sip, long unused, u32 ip, size_t unused2)
{
struct source_ip *sip = _sip;
struct hostent *he;
- const char *old, *new;
+ const char *old;
+ char *new, *c;
he = gethostbyaddr(&ip, 4, AF_INET);
if (!he)
@@ -686,6 +688,14 @@ static void dns_visitor(void *_sip, long unused, u32 ip, size_t unused2)
new = strdup(he->h_name);
if (!new)
return;
+ for (c = new; c; c++) {
+ /* normalize and shorten name */
+ *c = tolower(*c);
+ if (*c == '.') {
+ *c = 0;
+ break;
+ }
+ }
old = sip->filename;
sip->filename = new;
free((void *)old);