#include /* printf */ #include /* exit , calloc */ #include /* write */ #include /* accept, inet_ntoa, recv */ #include /* inet_ntoa */ #include /* inet_ntoa */ #include /* pthread_create */ #include "tcp_util.h" /* This server accepts two connections and creates logic link betwen them. The virtual link is concurrently managed to handle the flows in both directions. usage: relayTCPserver */ int main(int argc, char * argv[]) { int s[2], len; int * nc; struct sockaddr_in name; pthread_t threadID; if (argc!=3) { printf("Usage: %s ", argv[0]); exit(-1); } /* Create the socket. */ s[0] = createTCPserverSocket(atoi(argv[1])); s[1] = createTCPserverSocket(atoi(argv[2])); while(1) { nc = calloc (2, sizeof(int)); /* Accept a connection. */ nc[0] = accept(s[0], (struct sockaddr *) &name, &len); printf("Connection from : %s\n",inet_ntoa(name.sin_addr)); nc[1] = accept(s[1], (struct sockaddr *) &name, &len); printf("Connection from : %s\n",inet_ntoa(name.sin_addr)); pthread_create(&threadID, NULL, TCPRelay, nc); /* pthread_join(threadID, NULL);*/ } close(s[0]); close(s[1]); exit(0); }