diff options
author | Ian C <ianc@noddybox.co.uk> | 2016-04-06 15:10:32 +0000 |
---|---|---|
committer | Ian C <ianc@noddybox.co.uk> | 2016-04-06 15:10:32 +0000 |
commit | fa6bede3962a4729808db2c46c91b95285bf3eec (patch) | |
tree | daf1d3a26e32eaa424fbcfef469d1169240f2d4f /serv.c | |
parent | c5036cd3bca4ab8aa9b7314a6fee826a6b1444f6 (diff) |
Updated some files with changes that were lost during the backup accident.
Diffstat (limited to 'serv.c')
-rw-r--r-- | serv.c | 47 |
1 files changed, 46 insertions, 1 deletions
@@ -12,6 +12,8 @@ #include <netinet/tcp.h> #include <netdb.h> +#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) |