1 /* ulogd_LOCAL.c, Version 0.3
3 * ulogd interpreter plugin for: - local time of packet
4 * - hostname of localhost
6 * (C) 2001-2002 by Florent AIDE <faide@alphacent.com>
7 * with the help of Moez MKADMI <moez.mka@voila.fr>
8 * shamelessly ripped from Harald Welte
10 * 2002 extended by Martin Kaehmer <teg@mompl.org>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2
14 * as published by the Free Software Foundation
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 #include <ulogd/ulogd.h>
35 #define DEBUGP(x) ulogd_log(ULOGD_DEBUG, x)
37 #define DEBUGP(format, args...)
41 static char hostname[255];
43 static ulog_iret_t *_interp_local(ulog_interpreter_t *ip,
44 ulog_packet_msg_t *pkt)
47 ulog_iret_t *ret = ip->result;
50 gettimeofday(&tv, NULL);
53 ret[0].value.ui32 = (unsigned long) tv.tv_sec;
54 ret[0].flags |= ULOGD_RETF_VALID;
56 ret[1].value.ptr = hostname;
57 ret[1].flags |= ULOGD_RETF_VALID;
62 static ulog_iret_t local_rets[] = {
63 { .type = ULOGD_RET_UINT32,
64 .flags = ULOGD_RETF_NONE,
67 { .type = ULOGD_RET_STRING,
68 .flags = ULOGD_RETF_NONE,
69 .key = "local.hostname",
73 static ulog_interpreter_t local_ip[] = {
74 { NULL, "local", 0, &_interp_local, 2, local_rets },
75 { NULL, "", 0, NULL, 0, NULL },
78 static void _local_reg_ip(void)
80 ulog_interpreter_t *ip = local_ip;
81 ulog_interpreter_t *p;
83 for (p = ip; p->interp; p++)
84 register_interpreter(p);
91 if (gethostname(hostname, sizeof(hostname)) < 0) {
92 ulogd_log(ULOGD_FATAL, "can't gethostname(): %s\n",
96 /* strip off everything after first '.' */
97 if ((tmp = strchr(hostname, '.')))