4 * Copyright (c) 1998-2004 Hannes Gredler <hannes@tcpdump.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that: (1) source code
9 * distributions retain the above copyright notice and this paragraph
10 * in its entirety, and (2) distributions including binary code include
11 * the above copyright notice and this paragraph in its entirety in
12 * the documentation or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
14 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
15 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
16 * FOR A PARTICULAR PURPOSE.
19 #include <sys/cdefs.h>
22 static const char rcsid
[] _U_
=
23 "@(#) Header: /tcpdump/master/tcpdump/print-syslog.c,v 1.1 2004/10/29 11:42:53 hannes Exp";
25 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
33 #include <tcpdump-stdinc.h>
38 #include "interface.h"
40 #include "addrtoname.h"
43 * tokenlists and #defines taken from Ethereal - Network traffic analyzer
44 * by Gerald Combs <gerald@ethereal.com>
47 #define SYSLOG_SEVERITY_MASK 0x0007 /* 0000 0000 0000 0111 */
48 #define SYSLOG_FACILITY_MASK 0x03f8 /* 0000 0011 1111 1000 */
49 #define SYSLOG_MAX_DIGITS 3 /* The maximum number if priority digits to read in. */
51 static const struct tok syslog_severity_values
[] = {
63 static const struct tok syslog_facility_values
[] = {
92 syslog_print(register const u_char
*pptr
, register u_int len
)
94 u_int16_t msg_off
= 0;
96 u_int16_t facility
,severity
;
98 /* extract decimal figures that are
99 * encapsulated within < > tags
100 * based on this decimal figure extract the
101 * severity and facility values
104 if (!TTEST2(*pptr
, 1))
107 if (*(pptr
+msg_off
) == '<') {
110 if (!TTEST2(*(pptr
+msg_off
), 1))
113 while ( *(pptr
+msg_off
) >= '0' &&
114 *(pptr
+msg_off
) <= '9' &&
115 msg_off
<= SYSLOG_MAX_DIGITS
) {
117 if (!TTEST2(*(pptr
+msg_off
), 1))
120 pri
= pri
* 10 + (*(pptr
+msg_off
) - '0');
123 if (!TTEST2(*(pptr
+msg_off
), 1))
126 if (*(pptr
+msg_off
) == '>')
134 facility
= (pri
& SYSLOG_FACILITY_MASK
) >> 3;
135 severity
= pri
& SYSLOG_SEVERITY_MASK
;
140 printf("SYSLOG %s.%s, length: %u",
141 tok2str(syslog_facility_values
, "unknown (%u)", facility
),
142 tok2str(syslog_severity_values
, "unknown (%u)", severity
),
147 printf("SYSLOG, length: %u\n\tFacility %s (%u), Severity %s (%u)\n\tMsg: ",
149 tok2str(syslog_facility_values
, "unknown (%u)", facility
),
151 tok2str(syslog_severity_values
, "unknown (%u)", severity
),
154 /* print the syslog text in verbose mode */
155 for (; msg_off
< len
; msg_off
++) {
156 if (!TTEST2(*(pptr
+msg_off
), 1))
158 safeputchar(*(pptr
+msg_off
));
162 if(!print_unknown_data(pptr
,"\n\t",len
))