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
#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
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
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