The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1998-2004 Hannes Gredler <hannes@tcpdump.org> |
| 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 | #ifndef lint |
| 18 | static const char rcsid[] _U_ = |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 19 | "@(#) $Header: /tcpdump/master/tcpdump/print-syslog.c,v 1.1 2004-10-29 11:42:53 hannes Exp $"; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 20 | #endif |
| 21 | |
| 22 | #ifdef HAVE_CONFIG_H |
| 23 | #include "config.h" |
| 24 | #endif |
| 25 | |
| 26 | #include <tcpdump-stdinc.h> |
| 27 | |
| 28 | #include <stdio.h> |
| 29 | #include <stdlib.h> |
| 30 | |
| 31 | #include "interface.h" |
| 32 | #include "extract.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 33 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 34 | /* |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 35 | * tokenlists and #defines taken from Ethereal - Network traffic analyzer |
| 36 | * by Gerald Combs <gerald@ethereal.com> |
| 37 | */ |
| 38 | |
| 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. */ |
| 42 | |
| 43 | static const struct tok syslog_severity_values[] = { |
| 44 | { 0, "emergency" }, |
| 45 | { 1, "alert" }, |
| 46 | { 2, "critical" }, |
| 47 | { 3, "error" }, |
| 48 | { 4, "warning" }, |
| 49 | { 5, "notice" }, |
| 50 | { 6, "info" }, |
| 51 | { 7, "debug" }, |
| 52 | { 0, NULL }, |
| 53 | }; |
| 54 | |
| 55 | static const struct tok syslog_facility_values[] = { |
| 56 | { 0, "kernel" }, |
| 57 | { 1, "user" }, |
| 58 | { 2, "mail" }, |
| 59 | { 3, "daemon" }, |
| 60 | { 4, "auth" }, |
| 61 | { 5, "syslog" }, |
| 62 | { 6, "lpr" }, |
| 63 | { 7, "news" }, |
| 64 | { 8, "uucp" }, |
| 65 | { 9, "cron" }, |
| 66 | { 10, "authpriv" }, |
| 67 | { 11, "ftp" }, |
| 68 | { 12, "ntp" }, |
| 69 | { 13, "security" }, |
| 70 | { 14, "console" }, |
| 71 | { 15, "cron" }, |
| 72 | { 16, "local0" }, |
| 73 | { 17, "local1" }, |
| 74 | { 18, "local2" }, |
| 75 | { 19, "local3" }, |
| 76 | { 20, "local4" }, |
| 77 | { 21, "local5" }, |
| 78 | { 22, "local6" }, |
| 79 | { 23, "local7" }, |
| 80 | { 0, NULL }, |
| 81 | }; |
| 82 | |
| 83 | void |
| 84 | syslog_print(register const u_char *pptr, register u_int len) |
| 85 | { |
| 86 | u_int16_t msg_off = 0; |
| 87 | u_int16_t pri = 0; |
| 88 | u_int16_t facility,severity; |
| 89 | |
| 90 | /* extract decimal figures that are |
| 91 | * encapsulated within < > tags |
| 92 | * based on this decimal figure extract the |
| 93 | * severity and facility values |
| 94 | */ |
| 95 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 96 | TCHECK2(*pptr, 1); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 97 | if (*(pptr+msg_off) == '<') { |
| 98 | msg_off++; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 99 | TCHECK2(*(pptr+msg_off), 1); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 100 | while ( *(pptr+msg_off) >= '0' && |
| 101 | *(pptr+msg_off) <= '9' && |
| 102 | msg_off <= SYSLOG_MAX_DIGITS) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 103 | pri = pri * 10 + (*(pptr+msg_off) - '0'); |
| 104 | msg_off++; |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 105 | TCHECK2(*(pptr+msg_off), 1); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 106 | } |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 107 | if (*(pptr+msg_off) != '>') { |
| 108 | printf("[|syslog]"); |
| 109 | return; |
| 110 | } |
| 111 | msg_off++; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 112 | } else { |
| 113 | printf("[|syslog]"); |
| 114 | return; |
| 115 | } |
| 116 | |
| 117 | facility = (pri & SYSLOG_FACILITY_MASK) >> 3; |
| 118 | severity = pri & SYSLOG_SEVERITY_MASK; |
| 119 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 120 | if (vflag < 1 ) |
| 121 | { |
| 122 | printf("SYSLOG %s.%s, length: %u", |
| 123 | tok2str(syslog_facility_values, "unknown (%u)", facility), |
| 124 | tok2str(syslog_severity_values, "unknown (%u)", severity), |
| 125 | len); |
| 126 | return; |
| 127 | } |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 128 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 129 | printf("SYSLOG, length: %u\n\tFacility %s (%u), Severity %s (%u)\n\tMsg: ", |
| 130 | len, |
| 131 | tok2str(syslog_facility_values, "unknown (%u)", facility), |
| 132 | facility, |
| 133 | tok2str(syslog_severity_values, "unknown (%u)", severity), |
| 134 | severity); |
| 135 | |
| 136 | /* print the syslog text in verbose mode */ |
| 137 | for (; msg_off < len; msg_off++) { |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 138 | TCHECK2(*(pptr+msg_off), 1); |
| 139 | safeputchar(*(pptr+msg_off)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 140 | } |
| 141 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 142 | if (vflag > 1) |
| 143 | print_unknown_data(pptr,"\n\t",len); |
| 144 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 145 | return; |
| 146 | |
| 147 | trunc: |
| 148 | printf("[|syslog]"); |
| 149 | } |