Answered step by step
Verified Expert Solution
Question
1 Approved Answer
(6 marks). Consider the following TCP server program. int main(int argc, char argv ) { int listenfd, connfd; pid_t childpid; socklen_t clilen; struct sockaddr_in cliaddr,
(6 marks). Consider the following TCP server program. int main(int argc, char argv ) \{ int listenfd, connfd; pid_t childpid; socklen_t clilen; struct sockaddr_in cliaddr, servaddr; listenfd = Socket(AF_INET, SOCK_STREAM, 0); bzero(\&servaddr, sizeof(servaddr)); servaddr.sin_family =AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port htons(SERV_PORT ); Bind(listenfd, (SA *) \&servaddr, sizeof(servaddr)); Listen(listenfd, LISTENQ); for (;;){ connfd = Accept(listenfd, NULL, NULL); if (( childpid = Fork 0)==0){/ child process / Close(listenfd); / close listening socket */ str_echo(connfd); / process the request */ exit(0) 3 Close(connfd); / parent closes connected socket / 3 \} Explain how to modify the program to print the client's hostname and port number. YOU DO NOT NEED TO WRITE THE CODE FOR YOUR SOLUTION. However, you must explicitly state the functions/system calls and how to use them to print the hostname. (6 marks). Consider the following TCP server program. int main(int argc, char argv ) \{ int listenfd, connfd; pid_t childpid; socklen_t clilen; struct sockaddr_in cliaddr, servaddr; listenfd = Socket(AF_INET, SOCK_STREAM, 0); bzero(\&servaddr, sizeof(servaddr)); servaddr.sin_family =AF_INET; servaddr.sin_addr.s_addr = htonl(INADDR_ANY); servaddr.sin_port htons(SERV_PORT ); Bind(listenfd, (SA *) \&servaddr, sizeof(servaddr)); Listen(listenfd, LISTENQ); for (;;){ connfd = Accept(listenfd, NULL, NULL); if (( childpid = Fork 0)==0){/ child process / Close(listenfd); / close listening socket */ str_echo(connfd); / process the request */ exit(0) 3 Close(connfd); / parent closes connected socket / 3 \} Explain how to modify the program to print the client's hostname and port number. YOU DO NOT NEED TO WRITE THE CODE FOR YOUR SOLUTION. However, you must explicitly state the functions/system calls and how to use them to print the hostname
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started