You are on page 1of 3

EX-NO:

AIM:
To implement an RARP( Reverse Address Resolution Protocol) program to communicate
between client and server to convert IP to MAC .
PROCEDURE:
The Reverse address resolution protocol (RARP) is a protocol used by the Internet Protocol
(IP) [RFC826], specifically IPv4, to map IP network addresses to the hardware addresses
used by a data link protocol. The protocol operates below the network layer as a part of the
interface between the OSI network and OSI link layer.
The important terms associated with RARP are :
1. RARP Cache: After resolving MAC address, the RARP sends it to the source where it
stores in a table for future reference. The subsequent communications can use the MAC
address from the table
2. RARP Cache Timeout: It indicates the time for which the MAC address in the RARP
cache can reside
3. RARP request: This is nothing but broadcasting a packet over the network to validate
whether we came across destination MAC address or not.
RARP request packet contains:
1. The physical address of the sender.
2. The IP address of the sender.
3. The physical address of the receiver is 0s.
4. The IP address of the receiver
Note, that the RARP packet is encapsulated directly into data link frame.
4. RARP response/reply: It is the MAC address response that the source receives from
the destination which aids in further communication of the data.

ALGORITHM:
Initialize the string of ip addresses
For every ip address, assign an ethernet address
 : To Perform RARP, enter the ip address
 : The equivalent ethernet address is displayedStep
 : If the ethernet address is not found, then 'not found' message is displayeS
 : To Perform RRARP, enter the ethernet address
 : The equivalent ip address is displayed
 : If the ip address is not found, then 'not found' message is displayed
 : Provide option to perform both RARP and RRARP
 :Choose Exit option to terminate the program
PROGRAM:
Client:
import java.io.*;
import java.net.*;
import java.util.*;
class Clientrarp
{
public static void main(String args[])
{
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
Socket clsct=new Socket("127.0.0.1",139);
DataInputStream din=new DataInputStream(clsct.getInputStream());
DataOutputStream dout=new DataOutputStream(clsct.getOutputStream());
System.out.println("Enter the Physical Addres (MAC):");
String str1=in.readLine();
dout.writeBytes(str1+'\n');
String str=din.readLine();
System.out.println("The Logical address is(IP): "+str);
clsct.close();
}catch (Exception e)
{
System.out.println(e);
}
}
}
Server:
import java.io.*;
import java.net.*;
import java.util.*;
class Serverrarp
{
public static void main(String args[])
{
try
{ ServerSocket obj=new ServerSocket(139);
Socket obj1=obj.accept();
while(true)
{
DataInputStream din=new DataInputStream(obj1.getInputStream());
DataOutputStream dout=new
DataOutputStream(obj1.getOutputStream());
String str=din.readLine();
String ip[]={"165.165.80.80","165.165.79.1"};
String mac[]={"6A:08:AA:C2","8A:BC:E3:FA"};
for(int i=0;i<mac.length;i++)
{ if(str.equals(mac[i]))
{dout.writeBytes(ip[i]+'\n');
break;
}}
obj.close();}

}
catch(Exception e)
{
System.out.println(e);
}
}
}

OUTPUT:
Output:
E:\networks>java Serverrarp
E:\networks>java Clientrarp
Enter the Physical Address (MAC):
6A:08:AA:C2
The is Logical address(IP): 165.165.80.80

RESULT:
Thus the above RARP has been implemented and executed successfully.

You might also like