Question: echo server main routine: int main ( int argc, char * * argv ) { int listenfd, connfd, port, clientlen; struct sockaddr _ in clientaddr;

echo server main routine: int main(int argc, char **argv){
int listenfd, connfd, port, clientlen;
struct sockaddr_in clientaddr;
struct hostent *hp;
char *haddrp;
port = atoi(argv[1]); /* the server listens on a port passed
on the command line */
listenfd = open_listenfd(port);
while (1){
clientlen = sizeof(clientaddr);
connfd = Accept(listenfd,(SA *)&clientaddr, &clientlen);
hp = Gethostbyaddr((const char *)&clientaddr.sin_addr.s_addr,
sizeof(clientaddr.sin_addr.s_addr), AF_INET);
addrp = inet_ntoa(clientaddr.sin_addr);
printf("server connected to %s (%s)
", hp->h_name, haddrp);
echo(connfd);
Close(connfd);
}
} trace each line, does this server accepts multiple clients? and how do we fork so the server accepts multiple clients and creates socket file descriptor for each?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!