X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/001fc8411f90713c3495a1f3fcf8c67dbd3afa1b..6ec714988caac3bf9fedc766ae51a2248896ec80:/print-syslog.c diff --git a/print-syslog.c b/print-syslog.c index 3685d620..901c6f3a 100644 --- a/print-syslog.c +++ b/print-syslog.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998-2004 Hannes Gredler + * Copyright (c) 1998-2004 Hannes Gredler * The TCPDUMP project * * Redistribution and use in source and binary forms, with or without @@ -14,25 +14,20 @@ * FOR A PARTICULAR PURPOSE. */ -#ifndef lint -static const char rcsid[] _U_ = - "@(#) $Header: /tcpdump/master/tcpdump/print-syslog.c,v 1.1 2004-10-29 11:42:53 hannes Exp $"; -#endif +/* \summary: Syslog protocol printer */ #ifdef HAVE_CONFIG_H #include "config.h" #endif -#include - -#include -#include +#include -#include "interface.h" +#include "netdissect.h" #include "extract.h" -#include "addrtoname.h" -/* +static const char tstr[] = "[|syslog]"; + +/* * tokenlists and #defines taken from Ethereal - Network traffic analyzer * by Gerald Combs */ @@ -82,11 +77,12 @@ static const struct tok syslog_facility_values[] = { }; void -syslog_print(register const u_char *pptr, register u_int len) +syslog_print(netdissect_options *ndo, + const u_char *pptr, u_int len) { - u_int16_t msg_off = 0; - u_int16_t pri = 0; - u_int16_t facility,severity; + uint16_t msg_off = 0; + uint16_t pri = 0; + uint16_t facility,severity; /* extract decimal figures that are * encapsulated within < > tags @@ -94,70 +90,57 @@ syslog_print(register const u_char *pptr, register u_int len) * severity and facility values */ - if (!TTEST2(*pptr, 1)) - goto trunc; - - if (*(pptr+msg_off) == '<') { + ND_TCHECK_1(pptr); + if (EXTRACT_U_1(pptr + msg_off) == '<') { msg_off++; - - if (!TTEST2(*(pptr+msg_off), 1)) - goto trunc; - - while ( *(pptr+msg_off) >= '0' && - *(pptr+msg_off) <= '9' && - msg_off <= SYSLOG_MAX_DIGITS) { - - if (!TTEST2(*(pptr+msg_off), 1)) - goto trunc; - - pri = pri * 10 + (*(pptr+msg_off) - '0'); - msg_off++; - - if (!TTEST2(*(pptr+msg_off), 1)) - goto trunc; - - if (*(pptr+msg_off) == '>') + ND_TCHECK_1(pptr + msg_off); + while (msg_off <= SYSLOG_MAX_DIGITS && + EXTRACT_U_1(pptr + msg_off) >= '0' && + EXTRACT_U_1(pptr + msg_off) <= '9') { + pri = pri * 10 + (EXTRACT_U_1(pptr + msg_off) - '0'); msg_off++; + ND_TCHECK_1(pptr + msg_off); } + if (EXTRACT_U_1(pptr + msg_off) != '>') { + ND_PRINT((ndo, "%s", tstr)); + return; + } + msg_off++; } else { - printf("[|syslog]"); + ND_PRINT((ndo, "%s", tstr)); return; } facility = (pri & SYSLOG_FACILITY_MASK) >> 3; severity = pri & SYSLOG_SEVERITY_MASK; - - if (vflag < 1 ) + if (ndo->ndo_vflag < 1 ) { - printf("SYSLOG %s.%s, length: %u", + ND_PRINT((ndo, "SYSLOG %s.%s, length: %u", tok2str(syslog_facility_values, "unknown (%u)", facility), tok2str(syslog_severity_values, "unknown (%u)", severity), - len); + len)); return; } - - printf("SYSLOG, length: %u\n\tFacility %s (%u), Severity %s (%u)\n\tMsg: ", + + ND_PRINT((ndo, "SYSLOG, length: %u\n\tFacility %s (%u), Severity %s (%u)\n\tMsg: ", len, tok2str(syslog_facility_values, "unknown (%u)", facility), facility, tok2str(syslog_severity_values, "unknown (%u)", severity), - severity); + severity)); /* print the syslog text in verbose mode */ for (; msg_off < len; msg_off++) { - if (!TTEST2(*(pptr+msg_off), 1)) - goto trunc; - safeputchar(*(pptr+msg_off)); + ND_TCHECK_1(pptr + msg_off); + safeputchar(ndo, EXTRACT_U_1(pptr + msg_off)); } - if (vflag > 1) { - if(!print_unknown_data(pptr,"\n\t",len)) - return; - } - + if (ndo->ndo_vflag > 1) + print_unknown_data(ndo, pptr, "\n\t", len); + return; trunc: - printf("[|syslog]"); + ND_PRINT((ndo, "%s", tstr)); }