Normalize and shorten filenames
Turns TESTHOST07.bla.com into testhost07.
Signed-off-by: Joern Engel <joern@logfs.org>
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 @@
{
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 @@
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);