/* ---------------------------------- whoisclient code ---------------------------------- */ #include #include #include #include #include #define USEPORT 16000 #define USEPORT2 16001 main(argc, argv) int argc; char *argv[]; { int s; int len,i; int temp; struct sockaddr_in sa,isa; struct hostent *hp; struct servent *sp; char buf[1000]; char *myname; char *host; char *user; myname = argv[0]; if (argc != 2) { fprintf (stderr, "Usage: %s host \n", myname); exit(1); } host = argv[1]; if((hp = gethostbyname(host)) == NULL) { fprintf(stderr, "%s: %s: no such host?\n", myname, host); exit(1); } bcopy((char *)hp->h_addr, (char *)&sa.sin_addr, hp->h_length); sa.sin_family = hp->h_addrtype; sa.sin_port = htons(USEPORT2); if ((s = socket(hp->h_addrtype, SOCK_DGRAM, 0)) < 0) { perror("socket failed"); exit(1); } isa.sin_family = AF_INET ; isa.sin_addr.s_addr = INADDR_ANY ; isa.sin_port = htons(USEPORT); if (bind(s, &isa, sizeof (isa)) < 0) { perror ("BIND FAILED"); exit (1); } i = sizeof(sa); temp = 1; while ((len = recvfrom(s, buf, 1000, 0,&sa,&i)) > 0){ write (1, buf, len); if(temp) { printf("\n \n \n"); temp = 0; } else { printf("\n\n\n\n\n\n"); temp = 1; } } close(s); exit(0); }