Skip to main content

Simulation of ARP/RARP

Here is the core simulation of the ARP(Address Resolution Protocol) and RARP(Reverse Address
Resolution Protocol) ARP used to map the ip address with the corresponding MAC address and
RARP do that in reverse. it maps the MAC with the ip.

#include "stdio.h"
#include "string.h"
int main() {
    char table[3][2][40];
    char ipin[10],macin[30];
    int i,j,found;
    strcpy(table[0][0],"127.0.0.1");
    strcpy(table[0][1],"44:dd:22:11:33");
    strcpy(table[1][0],"10.1.1.8");
    strcpy(table[1][1],"33:aa:fe:4e:2d");
    strcpy(table[2][0],"10.1.8.5");
    strcpy(table[2][1],"23:a3:5d:33:9d");
    
    printf("IP address\t MAC address\n");
    for(i=0;i<3;i++) {
    printf("%s\t %s\n",table[i][0],table[i][1]);
    }

    printf("simulating ARP\n\n");
    printf("enter the IP address\n");
    scanf("%s",&ipin);
    for(i=0;i<3;i++) {
    if(strcmp(ipin,table[i][0])==0) {
        printf("%s mac id is %s\n\n",ipin,table[i][1]);
        found=1;
    }
    }
    if(found!=1) {
    printf("mac not found\n\n");
    }

    printf("simulating RARP\n\n"); 
    printf("enter the MAC address\n");
    scanf("%s",&macin);
    for(i=0;i<3;i++) {
    if(strcmp(macin,table[i][1])==0) {
        printf("%s ip is %s\n",macin,table[i][0]);
        found=1;
    }
    }
    if(found!=1) {
    printf("ip not found\n");
    }

    return 0;
}

Comments

Popular posts from this blog

ARP/RARP full simulation program

server.c #include "stdio.h" #include "stdlib.h" #include "string.h" #include "sys/types.h" #include "sys/socket.h" #include "arpa/inet.h" #include "netinet/in.h" #define SA struct sockaddr struct IPmac { char ip[100]; char mac[100]; }; int main() { int sockfd,len,i; struct sockaddr_in servaddr; char buff[30],temp[30],ip[30],mac[30];

Configure opendns in ubuntu 12.04

Today i have changed my dns server name to opendns. which is alternative to default dns and it provide more secure, faster browsing experience. What is opendns? OpenDNS is the leading provider of Internet security and DNS services Industry leading malware and botnet protection Award winning Web filtering Faster, reliable, more secure DNS Ultra-reliable, globally distributed cloud network Simple, Smart, Easy How to configure opendns in ubuntu 12.04: open terminal and type sudo nano /etc/resolv.conf enter your password and change these lines   nameserver 208.67.222.222  nameserver 208.67.220.220 to use google public dns use 8.8.8.8, 8.8.4.4 instead of 208.67.222.222, 208.67.220.220 simple isn't..! now see your facebook load faster than before. opendns comes with parental control, so never worry about unwanted websites, and your childrens are safe now. to check your dns changed successfully goto welcome.opendns.com

Given a string, reverse only vowels in it; leaving rest of the string as it is

/* Given a string, reverse only vowels in it; leaving rest of the string as it is. Input : abcdef Output : ebcdaf */ import java.io.*; import java.util.*; public class VowelReverse { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String str = sc.next(); String vowels = ""; String ans = ""; int arr[] = new int[str.length()]; for(int i=0;i<str.length();i++) { if(str.charAt(i)=='a' || str.charAt(i)=='e' || str.charAt(i)=='i' || str.charAt(i)=='o' || str.charAt(i)=='u') { vowels+=str.charAt(i); arr[i]=1; } } String revVowels = new StringBuffer(vowels).reverse().toString(); int j=0; for(int i=0;i<str.length();i++) { if(arr[i]!=1) { ans+=str.charAt(i); } else { ans+=revVowels.charAt(j); j++; } } System.out.println(ans); } }