From fa6bede3962a4729808db2c46c91b95285bf3eec Mon Sep 17 00:00:00 2001 From: Ian C Date: Wed, 6 Apr 2016 15:10:32 +0000 Subject: Updated some files with changes that were lost during the backup accident. --- serv.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'serv.c') diff --git a/serv.c b/serv.c index e7bbcac..093cc12 100644 --- a/serv.c +++ b/serv.c @@ -12,6 +12,8 @@ #include #include +#define DUMP_WIDTH 16 + static const char *name; static int Socket(int p) @@ -46,6 +48,48 @@ static int Socket(int p) return sock_fd; } +static void Dump(const char *p, int len) +{ + char asc[DUMP_WIDTH + 1] = {0}; + unsigned int off = 0; + int col = 0; + + while (len > 0) + { + unsigned char c = *p; + + if (col == 0) + { + printf("%4.4x:", off); + } + + printf(" %2.2x", (unsigned int)c); + + asc[col++] = isprint(c) ? c : '.'; + + if (col == DUMP_WIDTH) + { + printf(" %s\n", asc); + memset(asc, 0, sizeof asc); + col = 0; + } + + off++; + p++; + len--; + } + + if (col > 0) + { + while (col++ < DUMP_WIDTH) + { + printf(" **"); + } + + printf(" %s\n", asc); + } +} + int main(int argc, char *argv[]) { struct sockaddr_in addr; @@ -98,7 +142,8 @@ int main(int argc, char *argv[]) while((len=read(connect_fd,buff,1024))>0) { buff[len]=0; - printf("%s: recieved '%s'\n",name,buff); + printf("%s: recieved\n",name); + Dump(buff, len); } if (len == -1) -- cgit v1.2.3