Answered step by step
Verified Expert Solution
Question
1 Approved Answer
/* Simple udp server THIS IS UPD server*/ #include //printf #include //memset #include //exit(0); #include #include #define BUFLEN 512 //Max length of buffer #define PORT
/* Simple udp server THIS IS UPD server*/ #include//printf #include //memset #include //exit(0); #include #include #define BUFLEN 512 //Max length of buffer #define PORT 8888 //The port on which to listen for incoming data void die(char *s) { perror(s); exit(1); } int main(void) { struct sockaddr_in si_me, si_other; int s, i, slen = sizeof(si_other) , recv_len; char buf[BUFLEN]; //create a UDP socket if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { die("socket"); } // zero out the structure memset((char *) &si_me, 0, sizeof(si_me)); si_me.sin_family = AF_INET; si_me.sin_port = htons(PORT); si_me.sin_addr.s_addr = htonl(INADDR_ANY); //bind socket to port if( bind(s , (struct sockaddr*)&si_me, sizeof(si_me) ) == -1) { die("bind"); } //keep listening for data while(1) { printf("Waiting for data..."); fflush(stdout); //try to receive some data, this is a blocking call if ((recv_len = recvfrom(s, buf, BUFLEN, 0, (struct sockaddr *) &si_other, &slen)) == -1) { die("recvfrom()"); } //print details of the client/peer and the data received printf("Received packet from %s:%d ", inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port)); printf("Data: %s " , buf); /ow reply the client with the same data if (sendto(s, buf, recv_len, 0, (struct sockaddr*) &si_other, slen) == -1) { die("sendto()"); } } close(s); return 0; }
/* THIS IS UDP client Simple udp client */ #includeCCode: Our objective in this lab is to introduce security measures that will prevent the messages from being read by someone monitoring the communication channel. To introduce a measure of security, you will implement a simple substitution cipher to "encrypt" the message before it is transmitted. On the receiving end, the inverse process will be used to retrieve the original message. Specifically, modify your TCP server and client software to encrypt and decrypt messages. For a substitution cipher, one letter is substituted for another. For example, if the message contains an A, then the cipher text would represent that as another letter, such as W. To make the problem manageable, you can mit the input character set to only use upper case letters, which are represented as 65 to 90 in the ASCII format. Your messages will not have any special characters or numbers. You will need check whether an in put character is a space character, w hic h is represented as decimal 32. (You can choose whether or not you want to transpose the space character.) You will also have to check for line feed, carriage return and null characters. These will be transmitted with no changes. Your screenshots should show the original message and the cipher code that is transmitted. On the receiving end, show the received cipher code and the deciphered message. If possible, include an abbreviated Wireshark capture that shows the encrypted message being transmitted//printf #include //memset #include //exit(0); #include #include #define SERVER "127.0.0.1" #define BUFLEN 512 //Max length of buffer #define PORT 8888 //The port on which to send data void die(char *s) { perror(s); exit(1); } int main(void) { struct sockaddr_in si_other; int s, i, slen=sizeof(si_other); char buf[BUFLEN]; char message[BUFLEN]; if ( (s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { die("socket"); } memset((char *) &si_other, 0, sizeof(si_other)); si_other.sin_family = AF_INET; si_other.sin_port = htons(PORT); if (inet_aton(SERVER , &si_other.sin_addr) == 0) { fprintf(stderr, "inet_aton() failed "); exit(1); } while(1) { printf("Enter message : "); gets(message); //send the message if (sendto(s, message, strlen(message) , 0 , (struct sockaddr *) &si_other, slen)==-1) { die("sendto()"); } //receive a reply and print it //clear the buffer by filling null, it might have previously received data memset(buf,'\0', BUFLEN); //try to receive some data, this is a blocking call if (recvfrom(s, buf, BUFLEN, 0, (struct sockaddr *) &si_other, &slen) == -1) { die("recvfrom()"); } puts(buf); } close(s); return 0; }
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