diff options
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) |