Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

10. (6 pts) Refer to the code snippet below and answer the following questions: (a) To what host IP address and what port the program

image text in transcribed

10. (6 pts) 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; man socket '') */ memset(& hints, 0, sizeof(struct addrinfo)); hints. ai family = AF.INET; /* Allow IPv4 only (see hints.ai.socktype = SOCK DGRAM; hints.ai.flags = 0; hints. ai-protocol = IPPROTO UDP; 8 = 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->ai_next) { sfd = socket (rp->ai-family, rp->ai.socktype. if (sfd = -1) continue; if (connect(sfd , rp->ai.addr, rp->ai.addrlen) != -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); 10. (6 pts) 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; man socket '') */ memset(& hints, 0, sizeof(struct addrinfo)); hints. ai family = AF.INET; /* Allow IPv4 only (see hints.ai.socktype = SOCK DGRAM; hints.ai.flags = 0; hints. ai-protocol = IPPROTO UDP; 8 = 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->ai_next) { sfd = socket (rp->ai-family, rp->ai.socktype. if (sfd = -1) continue; if (connect(sfd , rp->ai.addr, rp->ai.addrlen) != -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)

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

SQL Database Programming

Authors: Chris Fehily

1st Edition

1937842312, 978-1937842314

More Books

Students also viewed these Databases questions

Question

Knowledge of process documentation (process flow charting)

Answered: 1 week ago