diff options
Diffstat (limited to 'serv.c')
-rw-r--r-- | serv.c | 21 |
1 files changed, 16 insertions, 5 deletions
@@ -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) |