Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Refer to Figure 1 (A snipped of code) and the following list of terms: MAXLINE, IPPROTO_UDP, &servAddr, SOCK _STREAM , clntSock, inet_pton, AF_INET, sock, sin_port,
Refer to Figure 1 (A snipped of code) and the following list of terms:
MAXLINE, IPPROTO_UDP, &servAddr, SOCK _STREAM , clntSock, inet_pton, AF_INET, sock, sin_port, IPPROTO_TCP.
a)Using line numbers, identify which XXXX value can be replaced with which term from the above list.
b)State whether this is a client or server application justifying your answer.
c)If this snippet of code is derived from a Daytime application, identify the socket primitive that would be called after line 27.
2 | ...IGNORE ALL PRIOR LINES. |
3 | |
4 | char *servIP - argv[1] ; |
5 | in_port_t servPort = atoi(argv[2]); |
6 | |
7 | int sock = socket(AF_INET, SOCK_STREAM, XXXX); |
8 | if (sock < 0) |
9 | DieWithSystemMessage(socket() failed") ; |
10 | |
11 | struct sockaddr_in servAddr; |
12 | memset(XXXX, 0, sizeof(servAddr)); |
13 | servAddr.sin_family = XXXX; |
14 | |
15 | int rtnVal = XXXX(AF_INET,servIP,&servAddr.sin_addr.s_addr); |
16 | |
17 | if (rtnVal == 0) |
18 | DieWithUserMessage("Failed", "invalid address string"); |
19 | else if (rtnVal < 0) |
20 | DieWithSystemMessage("inet_pton() failed"); |
21 | |
22 | servAddr.XXXX = htons(servPort); |
23 | |
24 | if(connect(XXXX,(struct sockaddr *)&servAddr,sizeof(servAddr))<0) |
25 | DieWithSystemMessage("connect() failed"); |
26 | |
27 | ...IGNORE ALL SUBSEQUENT LINES. |
Figure 1: Asnippet of code.
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