10. Refer to the code snippet below and answer the following questions: (a) To w
ID: 3732731 • Letter: 1
Question
10. Refer to the code snippet below and answer the following questions: (a) To what host IP address and what port the program attempts to connect? What line(s) itn the code contain this infomation? b) What transport protocol is used? What linels) in the code indicate this? (c) ls there any checking performed in this snippet induding underlying transport and network protocols) to ensure that the other end has accepted the connection and is receiving data? Explain why d) How many packets are exchanged between the computer running the program and the re- mote host if the function call near the end of the snippet (send(sfd, data, len, 0)) is successful? memset(&hints;, 0, sizeof (struct addrinfo)); hints.ai familyAF INET hints.ai.socktype SOCKDGRAM; hints. a i-protocol = IPPROTO-UDP; sgetaddrinfo(" at5030-eng2453server.lakeheadu.ca" 4 "40233" &hints; , &result;) 7 if (s - 0) ( fprintf(st d err, ”getaddrinfo :.9bs ", gai-strerror(s)); exit (EXIT FAILURE); socket (result-ai family, result->ai.socktype, result-ai protocol); fprintf (stderr "Failed to-create-socket") 10 sfd 12 if (sfd- -1) [ 13 14 15 16 17 | l en = strlen (message} + 1; '/* +1 for terminating uff byte */ 18 19 20 21 exit (EXIT FAILURE); messageAAAAAAaaaaa aaaaaaa aaaaaaaa aa aaaa aa aaa aa aaaaaaaa."; for iD; a i-addr, result-> ai-addrlen) != fprintf (stderr " Error sending packet) len 23 else printf ("Packet sentn"); 25 26freeaddrinfo (result); 27 shutdown (sfd, SHUT RDWR)Explanation / Answer
a) The program connects to the host "at5030-eng2453server.lakeheadu.ca" and port is 40233
The following line contain this information
s=getaddrinfo("at5030-eng2453server.lakeheadu.ca","40233",&hints,&result)
b) UDP is used in the given program.
The following line contain this information:
hints.ai_socktype=SOCK_DGRAM
hints.ai_protocol=IPPROTO_UDP
c)Yes, checking is performed to ensure that other end has accepted connection and is receiving data
Lines: 11-15 in the given code
If checking is not performed, no connection would be made to the remote host and packets would be lost.
d)For every succesful execution of send() function one packet of data is exchanged.
Since, for loop runs three times, so in total 3 packets of data is exchanged in the program.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.