#include #include #include "socketfun.h" main(int argc, char **argv) { char *hn; int port, sock, fd; void doit(int fd); if (argc != 3) { fprintf(stderr, "usage: serve1 hostname port\n"); exit(1); } hn = argv[1]; port = atoi(argv[2]); if (port < 5000) { fprintf(stderr, "usage: serve1 hostname port\n"); fprintf(stderr, " port must be > 5000\n"); exit(1); } sock = serve_socket(hn, port); for ( ; ; ) { fd = accept_connection(sock); printf("received a client connection on %d\n", fd); if (fork() == 0) { doit(fd); /* process the request */ } else { close(fd); } } } /****************************/ /* * doit ( int fd ) * ***************************/ void doit( int fd) { dup2(fd, 0); dup2(fd, 1); execlp("/blugreen/homes/plank/bin/SUN4/pty", "pty", "-ne", "/usr/games/arithmetic", 0); exit(1); }