You are on page 1of 13

Exno:4 DOMAIN NAME SYSTEM AIM: To write a C program to develop a DNS client server to resolve the given hostname.

ALGORITHM: 1. Create a new file. Enter the domain name and address in that file. 2. To establish the connection between client and server. 3. Compile and execute the program. 4. Enter the domain name as input. 5. The IP address corresponding to the domain name is display on the screen 6. Enter the IP address on the screen. 7. The domain name corresponding to the IP address is display on the screen. 8. Stop the program. Program : #include<stdio.h> #include<stdlib.h> #include<errno.h> #include<netdb.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> int main(int argc,char *argv[1]) { struct hostent *hen; if(argc!=2) { fprintf(stderr,"Enter the hostname \n"); exit(1); } hen=gethostbyname(argv[1]); printf(host name is%s,hen); if(hen==NULL) { fprintf(stderr,"Host not found \n"); } printf("Hostname is %s \n",hen->h_name); printf("IP address is %s \n",inet_ntoa(*((struct in_addr *)hen->h_addr))); } RESULT: Thus the above program udp performance using domain name server was executed and successfully

EX NO: 05 IMPLEMENTATION OF SLIDING WINDOW PROTOCOL AIM: To write a C program to perform sliding window. ALGORITHM: Start the program Get the frame size from the user To create the frame based on the user request. To send frames to server from the client side. If your frames reach the server it will send ACK signal to client otherwise it will send NACK signal to client.6. Stop the program PROGRAM: #include<stdio.h> #include<conio.h> void main() { char sender[50],receiver[50]; int i,winsize;clrscr(); printf("\n ENTER THE WINDOWS SIZE : "); scanf("%d",&winsize); printf("\n SENDER WINDOW IS EXPANDED TO STORE MESSAGE OR WINDOW \n"); printf("\n ENTER THE DATA TO BE SENT: "); fflush(stdin); gets(sender); for(i=0;i<winsize;i++) receiver[i]=sender[i]; receiver[i]=NULL; printf("\n MESSAGE SEND BY THE SENDER:\n"); puts(sender); printf("\n WINDOW SIZE OF RECEIVER IS EXPANDED\n"); printf("\n ACKNOWLEDGEMENT FROM RECEIVER \n"); for(i=0;i<winsize;i++); printf("\n ACK:%d",i); printf("\n MESSAGE RECEIVED BY RECEIVER IS : "); puts(receiver); printf("\n WINDOW SIZE OF RECEIVER IS SHRINKED \n"); getch(); }

EX NO:6 ADDRESS RESOLUTION PROTOCOL AIM: To get the MAC or Physical address of the system using Address Resolution Protocol. ALGORITHM: 1. Include necessary header files. 2. Initialize the arpreq structure initially to zero 3. Get the IPAddress of the system as command line argument. 4. Check whether the given IPAddress is valid. 5. Copy the IPAddress from sockaddr_in structure to arpreq structure using miscopy ()system call. 6. Create a socket of type SOCK_DGRAM. 7. Calculate the MAC address for the given IPAddress using ioctl() system call. 8. Display the IPAddress and MAC address in the standard output. PROGRAM: #include<unistd.h> #include<sys/types.h> #include<sys/socket.h> #include<netinet/in.h> #include<net/if_arp.h> #include<stdlib.h> #include<stdio.h> #include<netdb.h> #include<sys/ioctl.h> #include<arpa/inet.h> int main(int argc,char *argv[]) { int sd;unsigned char *ptr; struct arpreq myarp={{0}}; struct sockaddr_in sin={0}; sin.sin_family=AF_INET; if(inet_aton(argv[1],&sin.sin_addr)==0) { printf("IP address Entered%s is not valid\n",argv[1]); exit(0); } memcpy(&myarp.arp_pa,&sin,sizeof(myarp.arp_pa)); strcpy(myarp.arp_dev,"eth0"); sd=socket(AF_INET,SOCK_DGRAM,0); if(ioctl(sd,SIOCGARP,&myarp)==1) { printf("No entry in ARP cache for%s",argv[1]); exit(0); }

ptr=&myarp.arp_ha.sa_data[0]; printf ("MAC address for%s",argv[1]); printf("%x%x%x%x%x%x\n",*ptr,*(ptr+1),*(ptr+2),*(ptr+3),*(ptr+4),*(ptr+5)); return(0); } RESULT: Thus the MAC address was generated for IP address using ARP protocol. EX NO:7 IMPLEMENTING ROUTING PROTOCOLS AIM: To simulate the Implementing Routing Protocols using border gateway protocol (BGP) ALGORITHM: 1. Read the no. of nodes n 2. Read the cost matrix for the path from each node to another node 3. Initialize SOURCE to 1 and include 1 4. Compute D of a node which is the distance from source to that corresponding node. 5. Repeat step 6 to step 8 for n-l nodes. 6. Choose the node that has not been included whose distance is minimum and include that node. 7. For every other node not included compare the distance directly from the source with the distance to reach the node using the newly included node 8. Take the minimum value as the new distance.9. Print all the nodes with shortest path cost from source node PROGRAM : #include <stdio.h> #include<conio.h> int main() { int n;int i,j,k; int a[10][10],b[10][10]; printf("\n Enter the number of nodes:"); scanf("%d",&n); for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("\n Enter the distance between the host %d - %d:",i+1,j+1); scanf("%d",&a[i][j]); } } for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%d\t",a[i][j]);

} printf("\n"); } for(k=0;k<n;k++) { for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(a[i][j]>a[i][k]+a[k][j]) { a[i][j]=a[i][k]+a[k][j]; } } } } for(i=0;i<n;i++) { for(j=0;j<n;j++) { b[i][j]=a[i][j]; if(i==j) { b[i][j]=0; } } } printf("\n The output matrix:\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { printf("%d\t",b[i][j]); } printf("\n"); } getch(); } OUTPUT: [univ10 @ www univ10]$ cc bgp.c[univ10 @ www univ10]$ ./a.out Enter the number of nodes:4 Enter the distance between the host 1 - 1:5 Enter the distance between the host 1 - 2:9 Enter the distance between the host 1 - 3:6

Enter the distance between the host 1 - 4:4 Enter the distance between the host 2 - 1:2 Enter the distance between the host 2 - 2:1 Enter the distance between the host 2 - 3:8 Enter the distance between the host 2 - 4:3 Enter the distance between the host 3 - 1:6 Enter the distance between the host 3 - 2:1 Enter the distance between the host 3 - 3:4 Enter the distance between the host 3 - 4:2 Enter the distance between the host 4 - 1:5 Enter the distance between the host 4 - 2:1 Enter the distance between the host 4 - 3:8 Enter the distance between the host 4 - 4:2 5964 2183 6142 5182 The output matrix: 0564 2083 3102 3180 RESULT: Thus the above program to simulate the Implementing Routing Protocols using border gateway protocol was executed and successfully

EX NO:8 OPEN SHORTEST PATH FIRST ROUTING PROTOCOL AIM: To simulate the OPEN SHORTEST PATH FIRST routing protocol based on the cost assigned to the path. ALGORITHM: 1. Read the no. of nodes n 2. Read the cost matrix for the path from each node to another node. 3. Initialize SOURCE to 1 and include 1 4. Compute D of a node which is the distance from source to that corresponding node. 5. Repeat step 6 to step 8 for n-l nodes. 6. Choose the node that has not been included whose distance is minimum and include that node. 7. For every other node not included compare the distance directly from the source with the distance to reach the node using the newly included node 8. Take the minimum value as the new distance. 9. Print all the nodes with shortest path cost from source node

PROGRAM: #iinclude<stdio.h> #include<string.h> int main() { int count,src_router,i,j,k,w,v,min; int cost_matrix[100][100],dist[100],last[100]; int flag[100]; printf("\n Enter the no of routers"); scanf("%d",&count); printf("\n Enter the cost matrix values:"); for(i=0;i<count;i++) { for(j=0;j<count;j++) { printf("\n%d->%d:",i,j); scanf("%d",&cost_matrix[i][j]); if(cost_matrix[i][j]<0) cost_matrix[i][j]=1000; } } printf("\n Enter the source router:"); scanf("%d",&src_router); for(v=0;v<count;v++) { flag[v]=0; last[v]=src_router; dist[v]=cost_matrix[src_router][v]; } flag[src_router]=1; for(i=0;i<count;i++) { min=1000; for(w=0;w<count;w++) { if(!flag[w]) if(dist[w]<min) { v=w;min=dist[w]; } }flag[v]=1; for(w=0;w<count;w++) {

if(!flag[w]) if(min+cost_matrix[v][w]<dist[w]) { dist[w]=min+cost_matrix[v][w]; last[w]=v; } } } for(i=0;i<count;i++) { printf("\n%d==>%d:Path taken:%d",src_router,i,i); w=i;while(w!=src_router) { printf("\n<--%d",last[w]);w=last[w]; } printf("\n Shortest path cost:%d",dist[i]); } } OUTPUT: [ME04@TELNET ~]$ cc open.c [ME04@TELNET ~]$ ./a.out Enter the no of routers 4 Enter the cost matrix values 0->0:1 0->1:4 0->2:6 0->3:8 1->0:4 1->1:6 1->2:5 1->3:9 2->0:1 2->1:3 2->2:2 2->3:0 3->0:4 3->1:2 3->2:6 3->3:8 Enter the source router:3 3==>0: Path taken:0 <--3 Shortest path cost:4 3==>1:Path taken:1 <--3

Shortest path cost:2 3==>2:Path taken:2 <--3 Shortest path cost:6 3==>3:Path taken:3 Shortest path cost:8 RESULT: Thus the above program to simulate the Implementing Routing Protocols using open shortest path first (OSPF) was executed and successfully

PROGRAMS USING RAW SOCKETS (LIKE PACKET CAPTURING AND FILTERING) AIM : To implement programs using raw sockets (like packet capturing and filtering) ALGORITHM : 1. Start the program and to include the necessary header files 2. To define the packet length 3. To declare the IP header structure using TCPheader 4. Using simple checksum process to check the process 5. Using TCP \IP communication protocol to execute the program 6. And using TCP\IP communication to enter the Source IP and port number and Target IP address and port number. 7. The Raw socket () is created and accept the Socket ( ) and Send to ( ), ACK 8. Stop the program

Program import java.io.*; import java.net.*; class pingg { public static void main(String args[]) { BufferedReader in=null; try { Runtime r=Runtime.getRuntime(); Process p=r.exec("ping 192.168.121.200");

if(p==null) { System.out.println("Could not accept"); } in=new BufferedReader(new InputStreamReader(p.getInputStream())); String line; while((line=in.readLine())!=null) { if(line.startsWith("Reply")) { System.out.println("There is reply"); } else if(line.startsWith("Request")) { System.out.println("There is no reply"); } else if(line.startsWith("Destination")) { System.out.println("Destination host unreachable"); } } in.close(); } catch(IOException io) { System.err.println(io.toString()); } } } Output: C:\J2SDK1~1.2_0\bin>edit pingg.java C:\J2SDK1~1.2_0\bin>javac pingg.java C:\J2SDK1~1.2_0\bin>java pingg 192.168.121.200 There is reply There is reply There is reply There is reply

RESULT : Thus the Above programs using raw sockets TCP \IP (like packet capturing and filtering) was executed and successfully

EX NO: 4 PROGRAMS USING RPC / RMI Aim: To write a program using Remote invocation method - RPC Algorithm: 1. Create an interface. (in this case, the interface is myRMIInterface.java). 2. Create a class that implements the interface. (in this case, myRMIImpl.java). 3. Create a server that creates an instance of this class 4. Create a client that connects to the server object using Naming.lookup() 5. Compile these classes. 6. Run the RMI interface compiler on the .class file of the implementation class (in this case, you'd say "rmic myRMIImpl"). 7. Start the RMI registry (on Windows NT/95, say "start rmiregistry"). 8. Start the server class ("start java myRMIServer"). 9. Run the client program ("java myRMIClient").

Program: AddClient.java: import java.rmi.*; public class AddClient { public static void main(String args[]) { try { String addServerURL="rmi://"+args[0]+"/AddServer";

AddServerIntf addServerIntf=(AddServerIntf)Naming.lookup(addServerURL); System.out.println("The first number is : "+args[1]); double d1=Double.valueOf(args[1]).doubleValue(); System.out.println("The second number is : "+args[2]); double d2=Double.valueOf(args[2]).doubleValue(); System.out.println("The sum is : "+addServerIntf.add(d1,d2)); } catch(Exception e) { System.out.println("Exception : "+e); }}} AddServer.Java: import java.net.*; import java.rmi.*; public class AddServer { public static void main(String args[]) { try { AddServerImpl addServerImpl=new AddServerImpl(); Naming.rebind("AddServer",addServerImpl); } catch(Exception e) { System.out.println("Exception : "+e); }}} AddServerImpl: import java.rmi.*; import java.rmi.server.*; public class AddServerImpl extends UnicastRemoteObject implements AddServerIntf { public AddServerImpl() throws RemoteException {} public double add(double d1,double d2)throws RemoteException { return d1+d2; }} AddServerIntf.java:

import java.rmi.*; public interface AddServerIntf extends Remote { double add(double d1,double d2)throws RemoteException; } Output: Server side: C:\j2sdk1.4.2_09\bin>javac AddClient.java C:\j2sdk1.4.2_09\bin>javac AddServer.java C:\j2sdk1.4.2_09\bin>javac AddServerImpl.java C:\j2sdk1.4.2_09\bin>javac AddServerIntf.java C:\j2sdk1.4.2_09\bin>rmic AddServerImpl C:\j2sdk1.4.2_09\bin>start rmiregistry C:\j2sdk1.4.2_09\bin>java AddServer Client side: C:\J2SDK1~1.2_0\bin>java AddClient 192.168.121.200 10 2 The first number is : 10 The second number is : 2 The sum is : 12.0

RESULT: Thus the Above program RMI was executed and sucessfully

You might also like