Aim To know the logical address of a host when its physical address is known using RARP protocol.
Algorithm Target/Server 1. 2. 3. 4. 5. 6.
Create a server socket. Accept client connection. Read MAC address from the client request Check its configuration file and compare with its physical address. If there is a match, send the host logical address. Stop
Client 1. 2. 3. 4. 5. 6.
Create a socket. Send physical address to the target machine Receive target's response If it is a IP address then display it and go to step 6 Display "Host not found" Stop
Result Thus using RARP protocol, IP address is obtained.
http://cseannauniv.blogspot.com
Vijai Anand
CS2307 – Network Lab
Socket Programming
Program //RARP Server -- rarpserver.java import java.io.*; import java.net.*; class rarpserver { public static void main(String args[])throws IOException { try { ServerSocket soc = new ServerSocket(2500); System.out.println("Server started"); Socket client = null; client = soc.accept(); String str; PrintStream ps = new PrintStream(client.getOutputStream()); BufferedReader br = new BufferedReader(new InputStreamReader(client.getInputStream())); Runtime r = Runtime.getRuntime(); Process p = r.exec("ifconfig eth0"); BufferedReader pin = new BufferedReader(new InputStreamReader(p.getInputStream())); String ipaddr = ""; String haddr = br.readLine(); int flag = 0; while((str = pin.readLine())!=null) { System.out.println(str); if ((str.indexOf(haddr)) != -1) { flag = 1; } else if((str.indexOf("inet addr")) != -1) { int pos = str.indexOf("inet addr:") + 10; int offset = pos + 13; ipaddr = str.substring(pos,offset); } } if (flag == 1) ps.println(ipaddr); ps.close(); br.close(); pin.close(); client.close(); soc.close();
6. Stop. Client. 1. Create a socket. 2. Send physical address to the target machine. 3. Receive target's response. 4. If it is a IP address then display it and go to step 6 ... Program. //RARP Server -- rarpserver.java import java.io.*; import java.net.*; class rarpserver. { public static void main(String args[])throws IOException. { try.