1 /* ulogd_MAC.c, Version $Revision: 5252 $
3 * ulogd output target for logging to a file
5 * (C) 2000-2001 by Harald Welte <laforge@gnumonks.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2
9 * as published by the Free Software Foundation
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * $Id: ulogd_OPRINT.c 5252 2005-02-14 16:12:49Z laforge $
27 #include <ulogd/ulogd.h>
28 #include <ulogd/conffile.h>
30 #ifndef ULOGD_OPRINT_DEFAULT
31 #define ULOGD_OPRINT_DEFAULT "/var/log/ulogd.pktlog"
34 #define NIPQUAD(addr) \
35 ((unsigned char *)&addr)[0], \
36 ((unsigned char *)&addr)[1], \
37 ((unsigned char *)&addr)[2], \
38 ((unsigned char *)&addr)[3]
40 #define HIPQUAD(addr) \
41 ((unsigned char *)&addr)[3], \
42 ((unsigned char *)&addr)[2], \
43 ((unsigned char *)&addr)[1], \
44 ((unsigned char *)&addr)[0]
46 static FILE *of = NULL;
48 static int _output_print(ulog_iret_t *res)
52 fprintf(of, "===>PACKET BOUNDARY\n");
53 for (ret = res; ret; ret = ret->cur_next) {
54 fprintf(of,"%s=", ret->key);
56 case ULOGD_RET_STRING:
57 fprintf(of, "%s\n", (char *) ret->value.ptr);
63 fprintf(of, "%d\n", ret->value.i32);
66 case ULOGD_RET_UINT16:
67 case ULOGD_RET_UINT32:
68 fprintf(of, "%u\n", ret->value.ui32);
70 case ULOGD_RET_IPADDR:
71 fprintf(of, "%u.%u.%u.%u\n",
72 HIPQUAD(ret->value.ui32));
75 fprintf(of, "<none>");
82 static config_entry_t outf_ce = {
84 .type = CONFIG_TYPE_STRING,
85 .options = CONFIG_OPT_NONE,
86 .u = { .string = ULOGD_OPRINT_DEFAULT }
89 static void sighup_handler_print(int signal)
94 ulogd_log(ULOGD_NOTICE, "PKTLOG: reopening logfile\n");
96 of = fopen(outf_ce.u.string, "a");
98 ulogd_log(ULOGD_FATAL, "can't open PKTLOG: %s\n",
108 static int oprint_init(void)
113 config_parse_file("OPRINT", &outf_ce);
115 of = fopen(outf_ce.u.string, "a");
117 ulogd_log(ULOGD_FATAL, "can't open PKTLOG: %s\n",
125 static void oprint_fini(void)
133 static ulog_output_t oprint_op = {
135 .output = &_output_print,
136 .signal = &sighup_handler_print,
137 .init = &oprint_init,
138 .fini = &oprint_fini,
143 register_output(&oprint_op);