summaryrefslogtreecommitdiffstats
path: root/ulogd/extensions
diff options
context:
space:
mode:
authorlaforge <laforge>2001-03-25 18:25:01 +0000
committerlaforge <laforge>2001-03-25 18:25:01 +0000
commit81a1b833e26433fdb75f15d0e9f9a76eed241d07 (patch)
treecbe6ca2bc66a04d2bcf5e163273ef73c393228a4 /ulogd/extensions
parentcb8bf7c89268acfa0e568364e00ea4d836310fb4 (diff)
added date and hostname printing to be more syslog-alike
Diffstat (limited to 'ulogd/extensions')
-rw-r--r--ulogd/extensions/ulogd_LOGEMU.c41
1 files changed, 37 insertions, 4 deletions
diff --git a/ulogd/extensions/ulogd_LOGEMU.c b/ulogd/extensions/ulogd_LOGEMU.c
index 40b02fe..c9b1ac5 100644
--- a/ulogd/extensions/ulogd_LOGEMU.c
+++ b/ulogd/extensions/ulogd_LOGEMU.c
@@ -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