#include #include #include #include #include #include #include #include int main() { int sd, sd_current; struct sockaddr_in sin; struct sockaddr_in pin; /* get an internet domain socket */ if ((sd = socket(AF_INET, SOCK_STREAM, 0)) != -1) { /* complete the socket structure */ memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_addr.s_addr = INADDR_ANY; sin.sin_port = htons(23); /* bind the socket to the port number */ if (bind(sd, (struct sockaddr *) &sin, sizeof(sin)) != -1) { /* show that we are willing to listen */ if (listen(sd, SOMAXCONN) != -1) { /* wait for a client to talk to us */ socklen_t addrlen = sizeof(pin); if ((sd_current = accept(sd, (struct sockaddr *) &pin, &addrlen)) != -1) { for (;;) { /* get a message from the client */ char dir[10]; int len; len=recv(sd_current, dir, sizeof(dir), 0); if (len == -1) { break; } /* acknowledge the message, reply w/ the file names */ if (send(sd_current, dir, len, 0) != len) { break; } } /* close up both sockets */ close(sd_current); } } } close(sd); } return 0; }