msgdumpbuf.c (1174B)
1 /************************************************************************* 2 * This file is part of Crosroads 1.23, a load balancer and fail over 3 * utility for TCP. Copyright (c) Karel Kubat, distributed under GPL. 4 * Visit http://crossroads.e-tunity.com for information. 5 *************************************************************************/ 6 #include "crossroads.h" 7 8 void msgdumpbuf (unsigned char const *buf, int buflen) { 9 char 10 hexbuf[80] = { 0 }, 11 disp[17] = { 0 }, 12 tmp[5]; 13 int i, j, n = 0; 14 15 if (! flag_verbose) 16 return; 17 18 for (i = 0; i < buflen; i++) { 19 if (! n) 20 snprintf (hexbuf, 80, "%8.8x ", i); 21 22 snprintf (tmp, 5, " %2.2x", buf[i]); 23 strlcat (hexbuf, tmp, 80); 24 25 disp[n] = isprint (buf[i]) ? buf[i] : '.'; 26 disp[n + 1] = 0; 27 28 if (++n == 16) { 29 strlcat (hexbuf, " ", 80); 30 strlcat (hexbuf, disp, 80); 31 msg ("Message hexdump: %s", hexbuf); 32 n = 0; 33 disp[0] = 0; 34 hexbuf[0] = 0; 35 } 36 } 37 38 if (n < 16 - 1) { 39 for (j = n; j < 16; j++) 40 strlcat (hexbuf, " ", 80); 41 strlcat (hexbuf, " ", 80); 42 strlcat (hexbuf, disp, 80); 43 msg ("Message hex end: %s", hexbuf); 44 } 45 else 46 msg ("Message hex ends"); 47 } 48