From 695b72c4ebdbf8f61284bb195ebf978f45ac1da9 Mon Sep 17 00:00:00 2001 From: Ian C Date: Mon, 9 Jan 2023 12:06:34 +0000 Subject: Updated serv for a switch to just ASCII dump the comms. --- serv.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'serv.c') diff --git a/serv.c b/serv.c index 3fb88ac..f800df6 100644 --- a/serv.c +++ b/serv.c @@ -96,20 +96,23 @@ static void Dump(const char *p, int len) int main(int argc, char *argv[]) { struct sockaddr_in addr; - char buff[1024]; + char buff[1025]; int len; socklen_t addrlen; int sock_fd; int connect_fd; + int ascii = 0; name=argv[0]; - if (argc!=2) + if (argc<2) { - fprintf(stderr,"%s: usage %s port\n", name, name); + fprintf(stderr,"%s: usage %s port [-a]\n", name, name); exit(1); } + ascii = (argc == 3 && strcmp(argv[2], "-a") == 0); + sock_fd = Socket((short)atoi(argv[1])); printf("%s: socket bound\n",name); @@ -145,8 +148,16 @@ int main(int argc, char *argv[]) while((len=read(connect_fd,buff,1024))>0) { buff[len]=0; - printf("%s: recieved\n",name); - Dump(buff, len); + + if (ascii) + { + printf("%s", buff); + } + else + { + printf("%s: recieved\n",name); + Dump(buff, len); + } } if (len == -1) -- cgit v1.2.3