ADDRESS CONVERSION FOR LOGICAL ADDRESS INTO PHYSICAL ADDRESS

Server program

#include <stdio.h>
#include <sys/types.h>
#include <sys/shm.h>
int main()
{
int shmid;  int a,i;
char *ptr,*shmptr;
shmid=shmget(1200,10,IPC_CREAT|0666);
shmptr=shmat(shmid,NULL,0); //attaching a ptr to shm area
ptr=shmptr;
for(i=0;i<3;i++)
{
puts("\n Enter the MAC:");
scanf("%s",ptr);
a=strlen(ptr);
ptr[a]=' ';
puts("\n Enter the IP:");
ptr=ptr+a+1;
scanf("%s",ptr);
a=strlen(ptr);
ptr[a]='\n';
ptr=ptr+a+1;
}
ptr[strlen(ptr)]='\0';
printf("\n THE ARP TABLE AT SERVER SIDE=\n %s",shmptr);
shmdt(shmptr);   //detach
return 0;
}









Client program

#include <stdio.h>
#include <sys/types.h>
#include <sys/shm.h>
int main()
{
int shmid;  int a;
char *ptr,*shmptr;
char ip[20],mac[20],ptr2[20];
shmid=shmget(1200,10,0666);
shmptr=shmat(shmid,NULL,0);
puts("THE ARP TABLE IS:");
printf("%s",shmptr);
printf("\n 1.ARP 2.RARP 3.EXIT\n");
scanf("%d",&a);
switch(a)
{
case 1:
puts("\n Enter the IP address:");
scanf("%s",ip);
ptr=strstr(shmptr,ip);
ptr-=8;
sscanf(ptr,"%s %*s",ptr2);
printf("\n MAC address:%s",ptr2);
break;
case 2:
puts("\n Enter the MAC address:");
scanf("%s",mac);
ptr=strstr(shmptr,mac);
sscanf(ptr,"%*s %s",ptr2);
printf("%s",ptr2);
break;
case 3:
exit(1);
}
}








OUTPUT

SERVER

[11ca013@mcalinux network]$ cc 10logarpser.c
 [11ca013@mcalinux network]$ ./a.out

 Enter the MAC:www.google.com
 Enter the IP:192.1.1.1
 Enter the MAC:www.yahoo.com
 Enter the IP:192.1.1.2
 Enter the MAC:www.zoho.com
 Enter the IP:192.1.1.3

 THE ARP TABLE AT SERVER SIDE=
 www.google.com 192.1.1.1
www.yahoo.com 192.1.1.2
www.zoho.com 192.1.1.3

CLIENT

 [11ca013@mcalinux network]$ cc 10logarpcli.c
THE ARP TABLE IS:
www.google.com 192.1.1.1
www.yahoo.com 192.1.1.2
www.zoho.com 192.1.1.3
 1.ARP 2.RARP 3.EXIT
2
 Enter the MAC address:

 Ip address is : 192.1.1.1

0 Response to "ADDRESS CONVERSION FOR LOGICAL ADDRESS INTO PHYSICAL ADDRESS"

Post a Comment



Your IP Address is:

Browser: