Vidyalelo
Computer Science · Q278

Linux

Engineering and GATE · Computer Science · question 278

Q278

What is the problem with this server program? #include #include #include #include #include int main() int fd_server, fd_client, len; struct sockaddr_in add_server; fd_server = socket(AF_INET,SOCK_STREAM,0); if (fd_server == -1) perror("fd_sock"); exit(1); add_server.sin_family = AF_INET; add_server.sin_port = htons(4001); add_server.sin_addr.s_addr = inet_addr("122.23.1.1"); len = sizeof(add_server); if( bind(fd_server,(struct sockaddr*)&add_server,len) != 0) perror("bind"); if(listen(fd_server,5) != 0) perror("listen"); fd_client = accept(fd_server,(struct sockaddr*)&add_server,&len); if(fd_client == -1) perror("accept"); return 0;

A.
it can not accept the request of any client
Answer
B.
it will give the segmentation fault
C.
there is no problem with this program
D.
none of the mentioned

Answer: Option A

Solution

Answer: Option A
No explanation is given for this question Let's Discuss on Board