]> The Tcpdump Group git mirrors - tcpdump/blob - print-syslog.c
Revert partially the commit 21b1273
[tcpdump] / print-syslog.c
1 /*
2 * Copyright (c) 1998-2004 Hannes Gredler <hannes@gredler.at>
3 * The TCPDUMP project
4 *
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.
15 */
16
17 /* \summary: Syslog protocol printer */
18
19 #ifdef HAVE_CONFIG_H
20 #include <config.h>
21 #endif
22
23 #include "netdissect-stdinc.h"
24
25 #include "netdissect.h"
26 #include "extract.h"
27
28
29 /*
30 * tokenlists and #defines taken from Ethereal - Network traffic analyzer
31 * by Gerald Combs <gerald@ethereal.com>
32 */
33
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 of priority digits to read in. */
37
38 static const struct tok syslog_severity_values[] = {
39 { 0, "emergency" },
40 { 1, "alert" },
41 { 2, "critical" },
42 { 3, "error" },
43 { 4, "warning" },
44 { 5, "notice" },
45 { 6, "info" },
46 { 7, "debug" },
47 { 0, NULL },
48 };
49
50 static const struct tok syslog_facility_values[] = {
51 { 0, "kernel" },
52 { 1, "user" },
53 { 2, "mail" },
54 { 3, "daemon" },
55 { 4, "auth" },
56 { 5, "syslog" },
57 { 6, "lpr" },
58 { 7, "news" },
59 { 8, "uucp" },
60 { 9, "cron" },
61 { 10, "authpriv" },
62 { 11, "ftp" },
63 { 12, "ntp" },
64 { 13, "security" },
65 { 14, "console" },
66 { 15, "cron" },
67 { 16, "local0" },
68 { 17, "local1" },
69 { 18, "local2" },
70 { 19, "local3" },
71 { 20, "local4" },
72 { 21, "local5" },
73 { 22, "local6" },
74 { 23, "local7" },
75 { 0, NULL },
76 };
77
78 void
79 syslog_print(netdissect_options *ndo,
80 const u_char *pptr, u_int len)
81 {
82 uint16_t msg_off = 0;
83 uint16_t pri = 0;
84 uint16_t facility,severity;
85
86 ndo->ndo_protocol = "syslog";
87 /* extract decimal figures that are
88 * encapsulated within < > tags
89 * based on this decimal figure extract the
90 * severity and facility values
91 */
92
93 if (GET_U_1(pptr) == '<') {
94 msg_off++;
95 while (msg_off <= SYSLOG_MAX_DIGITS &&
96 GET_U_1(pptr + msg_off) >= '0' &&
97 GET_U_1(pptr + msg_off) <= '9') {
98 pri = pri * 10 + (GET_U_1(pptr + msg_off) - '0');
99 msg_off++;
100 }
101 if (GET_U_1(pptr + msg_off) != '>') {
102 nd_print_trunc(ndo);
103 return;
104 }
105 msg_off++;
106 } else {
107 nd_print_trunc(ndo);
108 return;
109 }
110
111 facility = (pri & SYSLOG_FACILITY_MASK) >> 3;
112 severity = pri & SYSLOG_SEVERITY_MASK;
113
114 if (ndo->ndo_vflag < 1 )
115 {
116 ND_PRINT("SYSLOG %s.%s, length: %u",
117 tok2str(syslog_facility_values, "unknown (%u)", facility),
118 tok2str(syslog_severity_values, "unknown (%u)", severity),
119 len);
120 return;
121 }
122
123 ND_PRINT("SYSLOG, length: %u\n\tFacility %s (%u), Severity %s (%u)\n\tMsg: ",
124 len,
125 tok2str(syslog_facility_values, "unknown (%u)", facility),
126 facility,
127 tok2str(syslog_severity_values, "unknown (%u)", severity),
128 severity);
129
130 /* print the syslog text in verbose mode */
131 for (; msg_off < len; msg_off++) {
132 fn_print_char(ndo, GET_U_1(pptr + msg_off));
133 }
134
135 if (ndo->ndo_vflag > 1)
136 print_unknown_data(ndo, pptr, "\n\t", len);
137 }