Question

Write a C program that can transparently authenticate all IP packets from/to specified IP address with...

Write a C program that can transparently authenticate all IP packets from/to specified IP address with given key.

program.c such that program (e.g., program 192.124.5.5 secret) will intercept packets

  • for any outgoing packet to the specified , transparently change the original payload X (the bytes after the IP header) by concatenating the original payload X with 16 bytes of md5(X|key), and adjust the IP header accordingly (e.g., increase the packet total length, re-calculate the checksum) so that the outgoing packet will have payloadX|md5(X|key)to

  • for any incoming packet from specified , check the packet payload for the md5 authentication with the given . Specifically, divide the packet payload (those bytes after the IP header) as two parts X, Y where Y is the last 16 bytes of the packet payload and X is the rest. If ( md5(X|key) == Y), change the payload of the incoming packet from X|Y to X, and adjust the IP header accordingly (e.g., decrease the packet total length, re-calculate the checksum) so that the incoming packet will be restored to its original form without keyed md5 authentication before sent to the receiving process. Otherwise, print out error message of failed authentication and drop the incoming packet.

Once you have developed such program, you need to run two instances of VM1 &  VM2  and to  make  VM1 &  VM2  have two  different  IP addresses  (e.g.,  ip1, ip2). They should be able to ping to each other. On VM1, set up appropriate ipfw rules to divert incoming/outgoing  traffic from/to   VM2   to <divert   port>.  Similarly,  on   VM2,   set  up appropriate ipfw rules to divert incoming/outgoing traffic from/to VM1 to <divert port>

Please include output of the code of experiments:

a) At VM1, run ./program secretKey

At VM2, run./ip_authAll secretKey

ping from VM1 to VM2
ping from VM2 to VM1

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C Program to display hostname and IP address

There are many ways to find Hostname and IP address of a local machine. Here is a simple method to find hostname and IP address using C program.

We will be using the following functions :-

gethostname() : The gethostname function retrieves the standard host name for the local computer.

gethostbyname() : The gethostbyname function retrieves host information corresponding to a host name from a host database.

inet_ntoa() : The inet_ntoa function converts an (Ipv4) Internet network address into an ASCII string in Internet standard dotted-decimal format.

// C program to display hostname
// and IP address
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

// Returns hostname for the local computer
void checkHostName(int hostname)
{
   if (hostname == -1)
   {
       perror("gethostname");
       exit(1);
   }
}

// Returns host information corresponding to host name
void checkHostEntry(struct hostent * hostentry)
{
   if (hostentry == NULL)
   {
       perror("gethostbyname");
       exit(1);
   }
}

// Converts space-delimited IPv4 addresses
// to dotted-decimal format
void checkIPbuffer(char *IPbuffer)
{
   if (NULL == IPbuffer)
   {
       perror("inet_ntoa");
       exit(1);
   }
}

// Driver code
int main()
{
   char hostbuffer[256];
   char *IPbuffer;
   struct hostent *host_entry;
   int hostname;

   // To retrieve hostname
   hostname = gethostname(hostbuffer, sizeof(hostbuffer));
   checkHostName(hostname);

   // To retrieve host information
   host_entry = gethostbyname(hostbuffer);
   checkHostEntry(host_entry);

   // To convert an Internet network
   // address into ASCII string
   IPbuffer = inet_ntoa(*((struct in_addr*)
                       host_entry->h_addr_list[0]));

   printf("Hostname: %s\n", hostbuffer);
   printf("Host IP: %s", IPbuffer);

   return 0;
}

Add a comment
Know the answer?
Add Answer to:
Write a C program that can transparently authenticate all IP packets from/to specified IP address with...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. To which of the following subnets does IP address 225.3.2.22 belong? 225.3.2.0/24 225.3.2.22/24 225.2.3.0/24 225.0.0.0/24...

    1. To which of the following subnets does IP address 225.3.2.22 belong? 225.3.2.0/24 225.3.2.22/24 225.2.3.0/24 225.0.0.0/24 none of the above Question 2 On which of the following devices does the transport layer NOT run? laptop router cellphone A, B and C none of the above Question 3 What is the source address contained in the discover message sent by a host that is wanting to obtain an IP address? 255.255.255.255 0.0.0.0 the IP address of the server the last IP...

  • 1. Let’s consider the network shown in Figure 1 where Snort is deployed. 1.1: In Figure...

    1. Let’s consider the network shown in Figure 1 where Snort is deployed. 1.1: In Figure 1, why is Snort deployed in the DMZ instead of the Internal Network? (9 points) 1.2: In Figure 1, say True or False to the following statement: “Snort can see both incoming packets from the left firewall and outgoing packets from the right firewall”. (5 points) 1.3: In Figure 1, assume a packet P matches the following Snort rule when the packet is analyzed...

  • . each of the following, write ONE of the letters AB to indicate your answer If...

    . each of the following, write ONE of the letters AB to indicate your answer If the receiver R of an ARP packet p sent by S does not have S's binding in its cache, which is a true? A. Only I B. Only II C. Only III D.Only I and II E. Only I and III F. Only II and GIII and I IR caches S's binding if p is a broadcast and R is the target II. R...

  • Using python 3 to create the UDP Ping Clien and server. Using UDP sockets, you will...

    Using python 3 to create the UDP Ping Clien and server. Using UDP sockets, you will write a client and server program that enables the client to determine the round-trip time (RTT) to the server. To determine the RTT delay, the client records the time on sending a ping request to the server, and then records the time on receiving a ping response from the server. The difference in the two times is the RTT. The ping message contains 2...

  • Write a C++ program that reads in 6 elements from the keyboard and stores them in...

    Write a C++ program that reads in 6 elements from the keyboard and stores them in an array x[6]. It should then create a second array y[6] that contains the elements from x in reverse order and with the s Tsecond - Tsmallest shown below. A sample run should look like: rocted ITrom it (e.g., Jlast first Tsmallest Vsecond last , etc). The program should finally print out both arrays to screen, in the format Enter 6 array elements: 4...

  • PART A 21 MARKS SHORT ANSWER QUESTIONS Answer ALL questions from this part. Write your answers...

    PART A 21 MARKS SHORT ANSWER QUESTIONS Answer ALL questions from this part. Write your answers in the Examination Answer Booklet. Each question is worth 1.5 marks (14 x 1.5 = 21 marks). Question 1 An organisation has been granted a block of addresses with the mask /22. If the organisation creates 8 equal-sized subnets, how many addresses (including the special addresses) are available in each subnet? Show your calculations. Question 2 Give an example of a valid classful address...

  • Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839....

    Write the following program in C++. Review structures, pointers and dynamic memory allocation from CSIT 839. Also, review pointers and dynamic memory allocation posted here under Pages. For sorting, you can refer to the textbook for Co Sci 839 or google "C++ sort functions". I've also included under files, a sample C++ source file named sort_binsearch.cpp which gives an example of both sorting and binary search. The Bubble sort is the simplest. For binary search too, you can refer to...

  • I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I...

    I NEED HELP WITH DEBUGGING A C PROGRAM! PLEASE HEAR ME OUT AND READ THIS. I just have to explain a lot so you understand how the program should work. In C programming, write a simple program to take a text file as input and encrypt/decrypt it by reading the text bit by bit, and swap the bits if it is specified by the first line of the text file to do so (will explain below, and please let me...

  • This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation...

    This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT