Question: The Assignment 2 code is here and I need it to be enhanced to send this TCP header: / Server program : /****************************************************************************/ /** Socket

The Assignment 2 code is here and I need it to be enhanced to send this TCP header:
/ Server program :
/****************************************************************************/ /** Socket Programming...Server */ /** TCP/IP */ /****************************************************************************/
#include
# define SIZE 1025
int main(void) { int listenfd = 0 ; //To store socket descriptor value.. int connfd = 0; //To store accept descriptor value.. char *str; struct sockaddr_in serv_addr; //structure deined in "" //struct sockaddr_storage serverStorage; socklen_t addr_size, client_addr_size; char sendBuff[SIZE]; //Buffer to store messages.... int limit;
str = (char *) malloc (sizeof (char)* SIZE); //To read Input...
listenfd = socket(AF_INET, SOCK_STREAM, 0); //Here TCP...
printf(" Server initiated successfully.. ");
/** Initializing 'serv_addr' & 'sendBuff' value to '0'..*/
memset(&serv_addr, '0', sizeof(serv_addr)); //Clearing Buffer... memset(sendBuff, '0', sizeof(sendBuff)); //Clearing Buffer...
serv_addr.sin_family = AF_INET; serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); serv_addr.sin_port = htons(5006); int len; len = sizeof(serv_addr); bind(listenfd, (struct sockaddr*)&serv_addr,sizeof(serv_addr));
if (listen (listenfd, 10) == -1) { printf("Failed to listen "); //Incomplete Queue Full... return -1; }
printf(" Waiting for the client to connect.. ");
connfd = accept(listenfd, (struct sockaddr*)NULL ,NULL); //connfd - descriptor printf(" Client connected to the server.. "); /* Open the file that we wish to transfer */ FILE *fp = fopen("sample.html","rb"); if(fp==NULL) { printf("File opern error"); return 1; }
/* Read data from file and send it */ while(1) { /* First read file in chunks of 256 bytes */ unsigned char buff[256]={0}; int nread = fread(buff,1,256,fp);
/* If read was success, send data. */ if(nread > 0) { printf("Sending file to the client.. "); printf("To no.of bytes sent : %d ", nread); if(sendto(connfd,sendBuff,nread,0,(struct sockaddr *)&serv_addr,len)
====================================
/ Client program :
/****************************************************************************/ /** Socket Programming...Client */ /** TCP/IP */ /****************************************************************************/
#include
#define SIZE 1025 int main(void) { int sockfd = 0,n = 0; //To store socket descriptor value.. char recvBuff[SIZE]; //Buffer to store received messages struct sockaddr_in serv_addr; //structure deined in "" int bytesReceived = 0;
while (!sockfd) {
memset(recvBuff, '0' ,sizeof(recvBuff)); //Clearing Buffer... if ( (sockfd = socket( AF_INET, SOCK_STREAM, 0))
serv_addr.sin_family = AF_INET; //connect with diff machine.. serv_addr.sin_port = htons(5006); serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
if(connect(sockfd,(struct sockaddr *)&serv_addr, sizeof(serv_addr)) 0) { printf("To no.of bytes received : %d ",bytesReceived); fwrite(recvBuff, 1,bytesReceived,fp); printf (" File received successfully..!! "); }
if(bytesReceived PROGRAM 3: (8 points) This is an enhancement to the Programming Assignment 2 in C. (not C++) Write a simple HTTP client and a separate HTTP server application in C using the POSIX socket libraries. As soon as the client connects, the client will send 20 bytes of the TCP header simulating the 3-way handshake, the server should respond to it and finally the client completes the handshake. . You must use the POSIX socket functions DO NOT implement the server handling multiple requests at the same time (multi-threading) Implement reasonable output messages that show the raw bytes of the header plus each header field in human readable format - e.g.etc port numbers should be integers, You will need the following fields in the "fake" TCP header: 1. Source TCP port number - Use a C function call to get this 2. Destination TCP port number - The real port you are connecting to 3. Sequence number -Create a random Initial Sequence Number 4. Acknowledgment number - You should use the appropriate value 5. TCP data offset - Make it all zeros for now Reserved data - Make it all zeros for now 7. Control flags flags should be set correctly for the 3-way handshake 8. Window size - Use a reasonable default value e.g. 17520 bytes 9. TCP checksum - Make it all ffffs for now 10. Urgent pointer - Make it all zeros PROGRAM 3: (8 points) This is an enhancement to the Programming Assignment 2 in C. (not C++) Write a simple HTTP client and a separate HTTP server application in C using the POSIX socket libraries. As soon as the client connects, the client will send 20 bytes of the TCP header simulating the 3-way handshake, the server should respond to it and finally the client completes the handshake. . You must use the POSIX socket functions DO NOT implement the server handling multiple requests at the same time (multi-threading) Implement reasonable output messages that show the raw bytes of the header plus each header field in human readable format - e.g.etc port numbers should be integers, You will need the following fields in the "fake" TCP header: 1. Source TCP port number - Use a C function call to get this 2. Destination TCP port number - The real port you are connecting to 3. Sequence number -Create a random Initial Sequence Number 4. Acknowledgment number - You should use the appropriate value 5. TCP data offset - Make it all zeros for now Reserved data - Make it all zeros for now 7. Control flags flags should be set correctly for the 3-way handshake 8. Window size - Use a reasonable default value e.g. 17520 bytes 9. TCP checksum - Make it all ffffs for now 10. Urgent pointer - Make it all zeros
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
