2 * Copyright (c) 1998-2004 Hannes Gredler <hannes@tcpdump.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code
7 * distributions retain the above copyright notice and this paragraph
8 * in its entirety, and (2) distributions including binary code include
9 * the above copyright notice and this paragraph in its entirety in
10 * the documentation or other materials provided with the distribution.
11 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
12 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
13 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 * FOR A PARTICULAR PURPOSE.
17 #include <sys/cdefs.h>
19 __RCSID("$NetBSD: print-syslog.c,v 1.5 2014/11/20 03:05:03 christos Exp $");
22 #define NETDISSECT_REWORKED
27 #include <tcpdump-stdinc.h>
29 #include "interface.h"
32 static const char tstr
[] = "[|syslog]";
35 * tokenlists and #defines taken from Ethereal - Network traffic analyzer
36 * by Gerald Combs <gerald@ethereal.com>
39 #define SYSLOG_SEVERITY_MASK 0x0007 /* 0000 0000 0000 0111 */
40 #define SYSLOG_FACILITY_MASK 0x03f8 /* 0000 0011 1111 1000 */
41 #define SYSLOG_MAX_DIGITS 3 /* The maximum number if priority digits to read in. */
43 static const struct tok syslog_severity_values
[] = {
55 static const struct tok syslog_facility_values
[] = {
84 syslog_print(netdissect_options
*ndo
,
85 register const u_char
*pptr
, register u_int len
)
89 uint16_t facility
,severity
;
91 /* extract decimal figures that are
92 * encapsulated within < > tags
93 * based on this decimal figure extract the
94 * severity and facility values
98 if (*(pptr
+msg_off
) == '<') {
100 ND_TCHECK2(*(pptr
+ msg_off
), 1);
101 while ( *(pptr
+msg_off
) >= '0' &&
102 *(pptr
+msg_off
) <= '9' &&
103 msg_off
<= SYSLOG_MAX_DIGITS
) {
104 pri
= pri
* 10 + (*(pptr
+msg_off
) - '0');
106 ND_TCHECK2(*(pptr
+ msg_off
), 1);
108 if (*(pptr
+msg_off
) != '>') {
109 ND_PRINT((ndo
, "%s", tstr
));
114 ND_PRINT((ndo
, "%s", tstr
));
118 facility
= (pri
& SYSLOG_FACILITY_MASK
) >> 3;
119 severity
= pri
& SYSLOG_SEVERITY_MASK
;
121 if (ndo
->ndo_vflag
< 1 )
123 ND_PRINT((ndo
, "SYSLOG %s.%s, length: %u",
124 tok2str(syslog_facility_values
, "unknown (%u)", facility
),
125 tok2str(syslog_severity_values
, "unknown (%u)", severity
),
130 ND_PRINT((ndo
, "SYSLOG, length: %u\n\tFacility %s (%u), Severity %s (%u)\n\tMsg: ",
132 tok2str(syslog_facility_values
, "unknown (%u)", facility
),
134 tok2str(syslog_severity_values
, "unknown (%u)", severity
),
137 /* print the syslog text in verbose mode */
138 for (; msg_off
< len
; msg_off
++) {
139 ND_TCHECK2(*(pptr
+ msg_off
), 1);
140 safeputchar(ndo
, *(pptr
+ msg_off
));
143 if (ndo
->ndo_vflag
> 1)
144 print_unknown_data(ndo
, pptr
, "\n\t", len
);
149 ND_PRINT((ndo
, "%s", tstr
));