]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
added date and hostname printing to be more syslog-alike
authorlaforge <laforge>
Sun, 25 Mar 2001 18:25:01 +0000 (18:25 +0000)
committerlaforge <laforge>
Sun, 25 Mar 2001 18:25:01 +0000 (18:25 +0000)
extensions/ulogd_LOGEMU.c

index 40b02fe045ac1cf8bd1bd9b2d12282efdfb8d82d..c9b1ac5d6ac65dadb9dbedbbed3ada5790cecbc0 100644 (file)
@@ -1,4 +1,4 @@
-/* ulogd_LOGEMU.c, Version $Revision: 1.2 $
+/* ulogd_LOGEMU.c, Version $Revision: 1.3 $
  *
  * ulogd output target for syslog logging emulation
  *
@@ -8,13 +8,16 @@
  * (C) 2000 by Harald Welte <laforge@gnumonks.org>
  * This software is released under the terms of GNU GPL
  *
- * $Id: ulogd_LOGEMU.c,v 1.2 2000/11/20 11:43:22 laforge Exp $
+ * $Id: ulogd_LOGEMU.c,v 1.3 2001/02/04 13:39:31 laforge Exp $
  *
  */
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <string.h>
+#include <time.h>
+#include <sys/time.h>
 #include <netinet/ip.h>
 #include <netinet/ip_icmp.h>
 #include "ulogd.h"
@@ -32,6 +35,8 @@
 
 static FILE *of = NULL;
 
+static char hostname[255];
+
 struct intr_id {
        char* name;
        unsigned int id;                
@@ -79,8 +84,29 @@ static struct intr_id intr_ids[INTR_IDS] = {
 
 int _output_logemu(ulog_iret_t *res)
 {
-       fprintf(of, "%sIN=%s OUT=%s ", 
-               (char *) GET_VALUE(0).ptr, 
+       char *timestr;
+       char *tmp;
+       time_t now;
+
+       /* get time */
+       time(&now);
+       timestr = ctime(&now) + 4;
+
+       /* truncate time */
+       if (tmp = strchr(timestr, '\n'))
+               *tmp = '\0';
+
+       /* truncate hostname */
+       if (tmp = strchr(hostname, '.'))
+               *tmp = '\0';
+
+       /* print time and hostname */
+       fprintf(of, "%.15s %s", timestr, hostname);
+
+       if (*(char *) GET_VALUE(0).ptr)
+               fprintf(of, " %s", (char *) GET_VALUE(0).ptr);
+
+       fprintf(of," IN=%s OUT=%s ", 
                (char *) GET_VALUE(1).ptr, 
                (char *) GET_VALUE(2).ptr);
 
@@ -220,12 +246,19 @@ static void _logemu_reg_op(void)
 static config_entry_t syslogf_ce = { NULL, "syslogfile", CONFIG_TYPE_STRING, 
                                  CONFIG_OPT_NONE, 0,
                                  { string: ULOGD_LOGEMU_DEFAULT } };
+
 void _init(void)
 {
        /* FIXME: error handling */
        config_register_key(&syslogf_ce);
        config_parse_file(0);
 
+       if (gethostname(hostname, sizeof(hostname)) < 0) {
+               ulogd_log(ULOGD_FATAL, "can't gethostname(): %s\n",
+                         strerror(errno));
+               exit(2);
+       }
+
 #ifdef DEBUG_LOGEMU
        of = stdout;
 #else