Answered step by step
Verified Expert Solution
Link Copied!

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,

image text in transcribed

(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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Evidence Based Audit In General Practice

Authors: Richard Baker, Robin C. Fraser MD FRCGP, Mayur Lakhani MRCP MRCGP DCH

1st Edition

075063104X, 978-0750631044

More Books

Students also viewed these Accounting questions