0% found this document useful (0 votes)
36 views6 pages

RARP MAC to IP Address Resolution Guide

The document outlines the implementation of a Reverse Address Resolution Protocol (RARP) using UDP sockets in Java. It details the steps for both server and client code, including creating sockets, handling requests, and sending responses based on MAC address lookups. The server responds with the corresponding IP address or an error message if the MAC address is not found.

Uploaded by

sudhakars106
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views6 pages

RARP MAC to IP Address Resolution Guide

The document outlines the implementation of a Reverse Address Resolution Protocol (RARP) using UDP sockets in Java. It details the steps for both server and client code, including creating sockets, handling requests, and sending responses based on MAC address lookups. The server responds with the corresponding IP address or an error message if the MAC address is not found.

Uploaded by

sudhakars106
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

The program was successfully executed and demonstrated how RARP resolves MAC address

to IP address using UDP sockets.

[Link] - Step by Step

Step 1: Import libraries

java

CopyEdit

import [Link].*;

import [Link].*;

We need:

• [Link].* for networking classes (DatagramSocket, DatagramPacket, InetAddress)

• [Link].* in case we need input/output (mainly for completeness)

Step 2: Create a DatagramSocket

java

CopyEdit

DatagramSocket server = new DatagramSocket(1309);

• Creates a UDP socket on port 1309

• Server uses this port to listen for incoming datagrams from clients

Step 3: Loop to handle incoming requests

java

CopyEdit

while (true) {

...

• Keeps server running continuously to handle multiple client requests

Step 4: Prepare to receive data


java

CopyEdit

byte[] receivebyte = new byte[1024];

DatagramPacket receiver = new DatagramPacket(receivebyte, [Link]);

[Link](receiver);

• Creates a DatagramPacket to receive data

• [Link](receiver) waits until data arrives

Step 5: Extract MAC address from the received datagram

java

CopyEdit

String s = new String([Link]()).trim();

• Converts byte data to a String

• trim() removes extra whitespace or padding

Step 6: Prepare for response

java

CopyEdit

InetAddress addr = [Link]();

int port = [Link]();

• Gets client's IP address and port number to send response back

Step 7: Lookup the IP address

java

CopyEdit

String ip[] = {"[Link]", "[Link]"};

String mac[] = {"[Link]", "[Link]"};

boolean found = false;


for (int i = 0; i < [Link]; i++) {

if ([Link](mac[i])) {

byte[] sendbyte = ip[i].getBytes();

DatagramPacket sender = new DatagramPacket(sendbyte, [Link], addr, port);

[Link](sender);

found = true;

break;

• Has a static IP–MAC table

• Loops through to see if received MAC matches any known MAC

• If found, converts IP to bytes, creates a DatagramPacket and sends it back to client

Step 8: Handle "MAC not found"

java

CopyEdit

if (!found) {

String errorMessage = "MAC address not found.";

byte[] sendbyte = [Link]();

DatagramPacket sender = new DatagramPacket(sendbyte, [Link], addr, port);

[Link](sender);

• If no matching MAC is found, server sends an error message back

Step 9: Repeat

• Server stays in the loop, ready for next client request


[Link] - Step by Step

Step 1: Import libraries

java

CopyEdit

import [Link].*;

import [Link].*;

• Needed for networking and reading input

Step 2: Create a DatagramSocket

java

CopyEdit

DatagramSocket client = new DatagramSocket();

• Client socket used to send and receive datagrams

Step 3: Define server address

java

CopyEdit

InetAddress addr = [Link]("[Link]");

• Localhost address (since server runs on same machine)

Step 4: Read MAC address from user

java

CopyEdit

BufferedReader in = new BufferedReader(new InputStreamReader([Link]));

[Link]("Enter the Physical address (MAC):");

String str = [Link]();

• Prompts user to type a MAC address

• Reads it as a string
Step 5: Send MAC address to server

java

CopyEdit

byte[] sendbyte = [Link]();

DatagramPacket sender = new DatagramPacket(sendbyte, [Link], addr, 1309);

[Link](sender);

• Converts string to bytes

• Creates datagram packet with server’s address and port 1309

• Sends it to the server

Step 6: Receive response (IP address)

java

CopyEdit

byte[] receivebyte = new byte[1024];

DatagramPacket receiver = new DatagramPacket(receivebyte, [Link]);

[Link](receiver);

String s = new String([Link]()).trim();

• Waits for response from server

• Converts received data back to string

Step 7: Display IP address or error message

java

CopyEdit

[Link]("The Logical Address is(IP): " + s);

• Shows the IP address returned by server or shows error message if MAC not found

Step 8: Close socket


java

CopyEdit

[Link]();

• Frees up resources and closes the client socket

Summary

• The Client takes a MAC address and asks the Server for its IP.

• The Server searches its table and sends the corresponding IP back (or error
message).

If you'd like,
I can combine this explanation + code into a Word .docx or PDF too!
Just say:
“Yes, make docx” or “Yes, make pdf” — and I’ll prepare it for you!

Ask ChatGPT

You said:

pdf

ChatGPT said:

It seems like I can’t do more advanced data analysis right now. Please try again later.

If you'd like, I can write out the step-by-step explanation content here in text format so you
can easily copy-paste it into Word or any editor to create the PDF yourself.
Would you like me to do that?

You might also like