X-Git-Url: https://git.tcpdump.org/tcpdump/blobdiff_plain/9fe73b290d70525e1cae59bb55087ef81baf08e8..HEAD:/print-resp.c diff --git a/print-resp.c b/print-resp.c index c5d67be4..1cefbacc 100644 --- a/print-resp.c +++ b/print-resp.c @@ -29,9 +29,7 @@ /* \summary: REdis Serialization Protocol (RESP) printer */ -#ifdef HAVE_CONFIG_H #include -#endif #include "netdissect-stdinc.h" #include "netdissect.h" @@ -183,6 +181,9 @@ static int resp_get_length(netdissect_options *, const u_char *, int, const u_ch * TEST_RET_LEN * If ret_len is < 0, jump to the trunc tag which returns (-1) * and 'bubbles up' to printing tstr. Otherwise, return ret_len. + * + * Note that using this macro with a semicolon at the end emits a warning from + * Sun C about an unreachable statement (the semicolon is the statement). */ #define TEST_RET_LEN(rl) \ if (rl < 0) { goto trunc; } else { return rl; } @@ -204,19 +205,17 @@ static int resp_get_length(netdissect_options *, const u_char *, int, const u_ch ND_PRINT(" \""); \ if (nd_printn(_ndo, _bp, _len, _ndo->ndo_snapend)) \ goto trunc; \ - fn_print_char(_ndo, '"'); + ND_PRINT("\""); void resp_print(netdissect_options *ndo, const u_char *bp, u_int length) { - int ret_len = 0, length_cur = length; + int ret_len = 0; ndo->ndo_protocol = "resp"; - if(!bp || length == 0) - return; ND_PRINT(": RESP"); - while (length_cur > 0) { + while (length != 0) { /* * This block supports redis pipelining. * For example, multiple operations can be pipelined within the same string: @@ -226,10 +225,10 @@ resp_print(netdissect_options *ndo, const u_char *bp, u_int length) * In order to handle this case, we must try and parse 'bp' until * 'length' bytes have been processed or we reach a trunc condition. */ - ret_len = resp_parse(ndo, bp, length_cur); + ret_len = resp_parse(ndo, bp, length); TEST_RET_LEN_NORETURN(ret_len); bp += ret_len; - length_cur -= ret_len; + length -= ret_len; } return; @@ -262,7 +261,7 @@ resp_parse(netdissect_options *ndo, const u_char *bp, int length) * including invalid packet errors; that's what we want, as * we have to give up on further parsing in that case. */ - TEST_RET_LEN(ret_len); + TEST_RET_LEN(ret_len) // without a semicolon trunc: return (-1); @@ -308,11 +307,11 @@ resp_print_string_error_integer(netdissect_options *ndo, const u_char *bp, int l * preceding the \r\n. That includes the opcode, so don't print * that. */ - len = ND_BYTES_BETWEEN(bp_ptr, bp); + len = ND_BYTES_BETWEEN(bp, bp_ptr); RESP_PRINT_SEGMENT(ndo, bp, len); ret_len = 1 /**/ + len /**/ + 2 /**/; - TEST_RET_LEN(ret_len); + TEST_RET_LEN(ret_len) // without a semicolon trunc: return (-1); @@ -433,7 +432,7 @@ resp_print_inline(netdissect_options *ndo, const u_char *bp, int length) { * Found it; bp_ptr points to the \r or \n, so bp_ptr - bp is the * Length of the line text that precedes it. Print it. */ - len = ND_BYTES_BETWEEN(bp_ptr, bp); + len = ND_BYTES_BETWEEN(bp, bp_ptr); RESP_PRINT_SEGMENT(ndo, bp, len); /*