Question: ****NO ADDITIONAL CODE NEEDED. JUST NEED CONCISE EXPLANATIONS WHERE IT SAYS COMMENT HERE**** #include /* for printf() and fprintf() */ #include /* for socket(), connect(),

****NO ADDITIONAL CODE NEEDED. JUST NEED CONCISE EXPLANATIONS WHERE IT SAYS "COMMENT HERE"****

#include /* for printf() and fprintf() */ #include /* for socket(), connect(), send(), and recv() */ #include /* for sockaddr_in and inet_addr() */ #include /* for atoi() and exit() */ #include /* for memset() */ #include /* for close() */

#define RCVBUFSIZE 32 /* Size of receive buffer */

void DieWithError(char *errorMessage); /* Error handling function */

int main(int argc, char *argv[]) { int sock; /* Socket descriptor */ struct sockaddr_in echoServAddr; /* Echo server address */ unsigned short echoServPort; /* Echo server port */ char *servIP; /* Server IP address (dotted quad) */ char *echoString; /* String to send to echo server */ char echoBuffer[RCVBUFSIZE]; /* Buffer for echo string */ unsigned int echoStringLen; /* Length of string to echo */ int bytesRcvd, totalBytesRcvd; /* Bytes read in single recv() and total bytes read */

if ((argc < 3) || (argc > 4)) { fprintf(stderr, "Usage: %s [] ", argv[0]); exit(1); }

servIP = argv[1]; echoString = argv[2];

if (argc == 4) echoServPort = atoi(argv[3]); /* Comment here */ else echoServPort = 7;

/* Comment here */ if ((sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) DieWithError("socket() failed");

/* Comment here */ memset(&echoServAddr, 0, sizeof(echoServAddr)); /* Comment here */ echoServAddr.sin_family = AF_INET; /* Comment here */ echoServAddr.sin_addr.s_addr = inet_addr(servIP); /* Comment here */ echoServAddr.sin_port = htons(echoServPort); /* Comment here */

/* Comment here */ if (connect(sock, (struct sockaddr *) &echoServAddr, sizeof(echoServAddr)) < 0) DieWithError("connect() failed");

echoStringLen = strlen(echoString);

/* Comment here */ if (send(sock, echoString, echoStringLen, 0) != echoStringLen) DieWithError("send() sent a different number of bytes than expected");

totalBytesRcvd = 0; printf("Received: "); while (totalBytesRcvd < echoStringLen) { /* Comment here */ if ((bytesRcvd = recv(sock, echoBuffer, RCVBUFSIZE - 1, 0)) <= 0) DieWithError("recv() failed or connection closed prematurely"); totalBytesRcvd += bytesRcvd; echoBuffer[bytesRcvd] = '\0'; printf("%s", echoBuffer); }

printf(" "); /* Print a final linefeed */

close(sock); exit(0); }

void DieWithError(char *errorMessage) { perror(errorMessage); exit(1); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!