Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Refer to the code snippet below and answer the following questions: (a) To what

ID: 3864386 • Letter: R

Question

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? (b) What transport protocol is used? (c) Is there any checking performed in this snippet (including 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 remote host if the function call near the end of the snippet (send(sfd, data, len, 0)) is successful? int main() { struct addrinfo hints; struct addrinfo *result , *rp; int sfd, s, j; size, t len; ssize, t nread; char *data; struct sockaddr_storage peer_addr; socklen_t peer_addr_len; memset (&hints;, 0, sizeof(struct addrinfo)); hints.ai_family = AF_INET; /* Allow IPv4 only (see man socket) */ hints.ai_socktype = SOCKDGRAM; hints.ai_flags = 0; hints.ai_protocol = IPPROTO_UDP; s = getaddrinfo(localhost, 2432, &hints;, &result;); if (s ! = 0) { fprintf(stderr, getaddrinfo : %s , gai_strerror (s)); exit (EXIT_FAILURE); } /* getaddrinfo() returns a list of address structures. Try each address until we successfully connect(2). If socket(2) (or connect (2) fails, we (close the socket and) try the next address. */ for (rp = result; rp ! = NULL; rp = rp rightarrow ai_next) { sfd = socket (rp rightarrow ai_family, rp rightarrow) ai_socktype, rp rightarrow ai_protocol); if (sfd = 1) continue; if (connect (sfd, rp rightarrow ai_addr, rp rightarrow ai_address) ! = 1) break; close (sfd); } if (rp = NULL) { /* No address succeeded */ fprintf (stderr, *Could_not_connect *); exit (EXIT_FAILURE); } freeaddrinfo ( result ); data = Port_number_is:_34893; len = strlen (data) + 1; if (send (sfd, data, len, 0) ! = len) { fprintf (stderr, partial/failed_write ); exit (EXIT_FAILURE); } /* Remaining code omitted */

Explanation / Answer

A) Host IP address: local host(To find local host address type "ipconfig/all" in your command prompt and search for IPV4 address)

Port: 34893

B) Transport protocol used: UDP transport protocol(standard transport layer protocol for datagram in IP networks)

C) connect function is used to check the connection status between local and remote computers

sfd is the socket descriptor returned by socket function

ai.addr is the pointer to struct socket address that contains destination IP address or port.

addrlen is set to sizeof( struct sockaddr).

Connect returns zero is connection is successful.

Socket function check whether any socket is connected or not. It returns -1 on error.

D) The number of data packets in UDP depends on the strlen(data) that is string length of data to be transmitted.