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 #define NETDISSECT_REWORKED
22 #include <tcpdump-stdinc.h>
24 #include "interface.h"
27 static const char tstr
[] = "[|syslog]";
30 * tokenlists and #defines taken from Ethereal - Network traffic analyzer
31 * by Gerald Combs <gerald@ethereal.com>
34 #define SYSLOG_SEVERITY_MASK 0x0007 /* 0000 0000 0000 0111 */
35 #define SYSLOG_FACILITY_MASK 0x03f8 /* 0000 0011 1111 1000 */
36 #define SYSLOG_MAX_DIGITS 3 /* The maximum number if priority digits to read in. */
38 static const struct tok syslog_severity_values
[] = {
50 static const struct tok syslog_facility_values
[] = {
79 syslog_print(netdissect_options
*ndo
,
80 register const u_char
*pptr
, register u_int len
)
84 uint16_t facility
,severity
;
86 /* extract decimal figures that are
87 * encapsulated within < > tags
88 * based on this decimal figure extract the
89 * severity and facility values
93 if (*(pptr
+msg_off
) == '<') {
95 ND_TCHECK2(*(pptr
+ msg_off
), 1);
96 while ( *(pptr
+msg_off
) >= '0' &&
97 *(pptr
+msg_off
) <= '9' &&
98 msg_off
<= SYSLOG_MAX_DIGITS
) {
99 pri
= pri
* 10 + (*(pptr
+msg_off
) - '0');
101 ND_TCHECK2(*(pptr
+ msg_off
), 1);
103 if (*(pptr
+msg_off
) != '>') {
104 ND_PRINT((ndo
, "%s", tstr
));
109 ND_PRINT((ndo
, "%s", tstr
));
113 facility
= (pri
& SYSLOG_FACILITY_MASK
) >> 3;
114 severity
= pri
& SYSLOG_SEVERITY_MASK
;
116 if (ndo
->ndo_vflag
< 1 )
118 ND_PRINT((ndo
, "SYSLOG %s.%s, length: %u",
119 tok2str(syslog_facility_values
, "unknown (%u)", facility
),
120 tok2str(syslog_severity_values
, "unknown (%u)", severity
),
125 ND_PRINT((ndo
, "SYSLOG, length: %u\n\tFacility %s (%u), Severity %s (%u)\n\tMsg: ",
127 tok2str(syslog_facility_values
, "unknown (%u)", facility
),
129 tok2str(syslog_severity_values
, "unknown (%u)", severity
),
132 /* print the syslog text in verbose mode */
133 for (; msg_off
< len
; msg_off
++) {
134 ND_TCHECK2(*(pptr
+ msg_off
), 1);
135 safeputchar(ndo
, *(pptr
+ msg_off
));
138 if (ndo
->ndo_vflag
> 1)
139 print_unknown_data(ndo
, pptr
, "\n\t", len
);
144 ND_PRINT((ndo
, "%s", tstr
));