Sunteți pe pagina 1din 83

SIMULATION OF ARP AND RARP

Ex.No: 1
Date:
AIM:
To write a c program for simulation of ARP, RARP client and server.
ALGORITHM:
Server:
1. Start
2. Create a shared memory segment and get its id using shmget() ;
3. Create a shared memory pointer and attach it to the shared memory using shmat().
4. A table containing machine address and its equivalent IP address is created and it is shared in
the shared memory segment.
5. Display contents of shared memory using its pointer.
6. Detach pointer from the shared memory using shmdt().
7. Stop.
Client:
1. Start.
2. Create the shared memory pointer which refers to the same memory segment that server has
created using shmget() .
3. Create options to find ARP, RARP and exit.
4. If ARP is requested, then compare the given IP address in the shared memory segment and
print the machine address.
5. If RARP is requested, then compare the given machine address in the ARP table and display
the equivalent IP address.
6. Repeat step 4 and 5 depending upon the user's choice.
7. Exit.
1

FLOW CHART:

PROGRAM:

PROGRAM EXECUTION

LIST OF ERRORS OBSERVED

RESULT:
Thus the ARP, RARP client and server program was written and output was executed
successfully.
8

BIT STUFFING
Ex.No: 2
Date:
AIM:
To write a c program for bit stuffing.
ALGORITHM:
1. Start the program.
2. Include all the header files.
3. Declare two files pointers for opening the input file in read mode and the output in write
mode.
4. Read the content of an input file.
5. If the bit is 1, then check for four consecutive 1s.
6. If so then stuff a bit 0 at that position (i.e. after five consecutive 1s)
7.Open the output file in write mode and print the stuffed string.
8. Stop the program.

FLOW CHART:

10

PROGRAM:

11

12

13

14

PROGRAM EXECUTION

LIST OF ERRORS OBSERVED

15

RESULT:
Thus the bit stuffing program was executed and output was verified.

16

IMPLEMENTATION OF CRC
Ex.No: 3
Date:
AIM:
To write a c program for implementing CRC.
ALGORITHM:
1. Start.
2. Get the number of data bits.
3. Get the size of generator.
4. Get the number of generator.
5. Display the generator matrix.
6. Perform CRC by using generator bits as a divisor and data bits as a dividend.
7. If the first bit of data is zero, then XOR with zero.
8. Otherwise XOR the data bit with generator bits.
9. Repeat step 7 & 8 until getting the reminder, the reminder is CRC.
10. Append the CRC bit with the data bits.
11. Stop

17

FLOW CHART:

18

PROGRAM:

19

20

PROGRAM EXECUTION

LIST OF ERRORS OBSERVED

21

RESULT:
Thus the CRC program was executed and output was verified.
22

SIMULATION OF SLIDING-WINDOW PROTOCOL


Ex.No: 4
Date:
AIM:
To write a program to implement sliding window protocol to avoid congestion and to ensure
reliable data transfer.
ALGORITHM:
1. Sender keeps track of outstanding frames and updates the variables and window as
acknowledgements arrive.
2. Receiver sliding window waits for a specific frame to arrive in a specific order , and frame
arriving out of order is discarded and needs to be resent.
3. Commence transmission
a. deal with damaged or lost frame.
b. deal with damaged or lost acknowledgement.
c. deal with delayed acknowledgement.
4. Update sender window size.

23

FLOW CHART:

24

PROGRAM:

25

26

27

28

PROGRAM EXECUTION

LIST OF ERRORS OBSERVED

29

RESULT:
Thus the sliding window program was executed and output was verified.

30

SIMULATION OF BGP / OSPF ROUTING PROTOCOL


Ex.No: 5
Date:
AIM:
To write a c program for simulation of BGP/OSPF routing protocol.
ALGORITHM:
1 .Start.
2. Read the no. of nodes.
3. Read the distance between one node to the other for every node.
4. Assign the distance from a node to itself as zero.
5. Find the shortest path from the given node to other node and assign the same as distance.
6. Print the distance from one node to every other node in form of a matrix.
7. Stop.

31

FLOW CHART:

32

PROGRAM:

33

34

35

36

PROGRAM EXECUTION

LIST OF ERRORS OBSERVED

37

RESULT:
Thus the simulation of BGP / OSPF routing protocol was implemented and executed
successfully.

38

CLIENT SERVER APPLICATION FOR CHAT


Ex.No: 6
Date:
AIM:
To write a C program to create a client server application for chat
ALGORITHM:
Server:
Step 1: Start
Step 2: create a socket with address family AF_INET, type SOCK_STREAM and default
protocol.
Step 3: Initialize the socket and set its attributes assign any port number as desired.
Step 4: Bind the server to the socket using bind() function.
Step 5: Establish the listen queue using the listen function.
Step 6: Wait for client program on request, establish a connection using accept function.
Step 7: Repeat steps 8-10 until the server sends bye.
Step 8: Read the message from the client using read() function and display the message.
Step 9: If the client message is bye go to step 11.
Step 10: Accept the server message and write it to client using write() function.
Step 11: close the connection.
Step 12: Go to step 6.
39

Client:
Step 1: Start.
Step 2: Create a socket with address family AF_INET type SOCK_STERAM and default
protocol.
Step 3: Initialize the socket and set it attributes set the required port number.
Step 4: Connect to the server using connect() function to initialize the request.
Step 5: Repeat steps 6-8 until server sends bye.
Step 6: Accept the client message and write it to the server using write function.
Step 7: If the client message is bye go to step 9.
Step 8: Read the message from the server using read() function. Display the message.
Step 9: Stop.
FLOW CHART:

40

41

PROGRAM:

42

43

44

PROGRAM EXECUTION

LIST OF ERRORS OBSERVED

45

RESULT:
Thus the client server application for chat was implemented and executed successfully.
46

IMPLEMENTATION OF DNS SERVER


Ex.No: 7
Date:
AIM:
To write a c program for creating a DNS server
ALGORITHM:
Server:
1.
2.
3.
4.
5.
6.

Get the port number from the command line argument.


Clear the buffer using bzero function.
Establish the socket connection.
Read the host name from the buffer.
Open the DNS.txt file and check whether the hostname matches with the entries.
Exit the server connection.

Client:
1. Get the host name and port number from the user through command line argument.
2. Check the number , it must be 2. If not prompt an error msg.
3. Open the socket connection.
4. Clear the buffer using bzero function.
5. Check if the write operation was successfully or not if not print the error msg.
6. Exit the client connection.

47

FLOW CHART:

48

PROGRAM:

49

50

51

52

PROGRAM EXECUTION

LIST OF ERRORS OBSERVED

53

RESULT:
Thus the implementation of DNS server using C program was executed successfully.
54

DOWNLOADING FILE FROM HTTP SERVER


Ex.No: 8
Date:
AIM:
To write a C program for downloading file from http server.
ALGORITHM:
1.
2.
3.
4.
5.

Start.
Create n number of .txt file separately for n number of domain.
In each and every .txt file the content of that domain is entered.
Create a file pointer in c program using FILE *f1.
Get the domain name from user and string comparison is done with respect to domain
name.
6. If the input domain name matches with the string then open a file in a read mode using
fopen().
7. Print the corresponding content of that file.
8. Stop.
FLOW CHART:

55

56

PROGRAM:

57

58

59

60

PROGRAM EXECUTION

LIST OF ERRORS OBSERVED

61

RESULT:
Thus the C p;rogram for downloading file form http server was implemented and executed
successfully.

62

FILE TRANSFER USING TCP SOCKET


Ex.No: 9
Date:
AIM:
To create a TCP socket between two computers and enable file transfer between them
ALGORITHM:
Server:
1. Start.
2. create a socket with address family AF_INET, type SOCK_STERAM and default
protocol.
3. Initialize the socket and set its attributes assign any port number as desired.
4. Bind the server to socket using bind function.
5. wait for the client request on request establish a connection using accept() function.
6. Read the source and destination files names from the client.
7. Open the source and destination files.
8. Read one line of source file and send it to client.
9. Receive the line back from the client.
10. Repeat steps 8 & 9 until the end of the source file.
11. close the source and destination files.
12. close the connection and go to step5.
13. Stop
Client:
1. Start
2. Create a socket with address family AF_INET type SOCK_STREAM and default
protocol. Initialize the socket and set its attribute set required port no.
63

3. Connect to server using connect() function to initiate the request.


4. Send the source and destination file names to server.
5. Receive the string from the server and print it at the console.
6. Send the string to the server.
7. Repeat step 5 & 6 until the server terminates and connection.
8. Stop.
FLOW CHART:

64

PROGRAM:

65

66

67

68

PROGRAM EXECUTION

LIST OF ERRORS OBSERVED

69

RESULT:
Thus the file transfer between two computers using tcp socket was implemented and
output was executed successfully.
70

FILE TRANSFER USING RS232C


Ex.No: 10
Date:
AIM:
To write a C program for file transfer using RS232C
ALGORITHM:
Server:
1. Start.
2. Open the file recvfile.txt in write mode.
3. Receive the port number and establish socket connection.
4. Listen to clients request using system call listen() .
5. While the message size is not zero, receive the client message and write it in to a file.
6. Close the socket connection.
7. Stop.

Client:
1. Start.
2. Pass server address and file name as command line arguments.
3. Open the file and establish connection using socket().
4. Using memset(), get the size of client address.
5. Connect to server using connect()system call.
6. While not end of file, print the contents into the file.
7. Close the socket connection.
8. Stop.

71

FLOW CHART:

72

PROGRAM:

73

74

75

76

PROGRAM EXECUTION

LIST OF ERRORS OBSERVED

77

RESULT:
Thus the C program for file transfer using RS232C was implemented and executed
successfully.
78

APPENDIX
SAMPLE OUTPUT:
1. SIMULATION OF ARP AND RARP
The ARP table is
a.b.c.d 1.2.3.4
e.f.g.h 5.6.7.8
i.j.k.l 9.1.2.3
1.ARP
2.RARP
3.EXIT
Enter your choice: 1
Enter ip address: 1.2.3.4
mac addr is a.b.c.d
Enter your choice:2
Enter mac address: e.f.g.h
ip addr is 5.6.7.8
2. BIT STUFFING
Enter the choice
1.Stuff
2.Destuff
3.Exit
1
Enter the data..10111111010
10111111010
Enter the choice
1.Stuff
2.Destuff
3.Exit
2
Enter the data 10111111010

79

The unstuffed data is 10111111010


Enter the choice
1.Stuff
2.Destuff
3.Exit
3. IMPLEMENTATION OF CRC
Enter no. of data bits:8
Enter data:1 0 1 0 0 0 0 1
Enter size of generator:4
Enter generator:1 0 0 1
The generator matrix:1001
The appended matrix is:10100001000
The CRC is :111
10100001111
4. SIMULATION OF SLIDING-WINDOW PROTOCOL
Enter the message: saveetha university
ENTER THE WINDOW SIZE:3
WINDOWS
sav
vee
eth
au
uni
ive
ers
rsi
ity
y

MESSAGE
sa
ve
eth
a
un
iv
e
rs
it
y

ACK
2
4
7
9
11
13
14
16
18
19

80

5. SIMULATION OF BGP / OSPF ROUTING PROTOCOL


Enter the number of nodes: 3
Enter the distance between the host 1 1:2
Enter the distance between the host 1 2:4
Enter the distance between the host 1 3:6
Enter the distance between the host 2 1:8
Enter the distance between the host 2 2:10
Enter the distance between the host 2 3:3
Enter the distance between the host 3 1:5
Enter the distance between the host 3 2:7
Enter the distance between the host 3 3:9
2
8
5

4 6
10 3
7 9

The output matrix is:


0 4 6
8 0 3
5 7 0
6. CLIENT SERVER APPLICATION FOR CHAT
Server side:
[cseb58@localhost cseb58]$ cc chatserver.c
[cseb58@localhost cseb58]$ ./a.out
conx open!
Client :hai server!
cliebt : bye
Client side:
[cseb58@localhost cseb58]$ cc chatclient.c
[cseb58@localhost cseb58]$ ./a.out 127.0.0.1 1858
connected
server:hai
server:see you

81

7. IMPLEMENTATION OF DNS SERVER

Input File:
Dns.txt
Yahoo 192.10.11.124
www.gmail.com 209.34.56.123
Output :
[cseb17@localhost cseb 17]$ ./a.out 5677

host name is www.gmail.com


ip address is 209.34.56.123
[cseb17@localhost cseb 17]$ ./a.out localhost 5677

Enter the host name :www.gmail.com


Ip address is : 209.34.56.123
8. DOWNLOADING FILE FROM HTTP SERVER
Enter the domain name:
www.google.com
Welcome to google
INPUT FILE:
/* google301.txt*/
Welcome to google
9. FILE TRANSFER USING TCP SOCKET
Server Side:
[cseb17@localhost cseb 17]$ cc server.c
[cseb17@localhost cseb 17]$.a/out
Client requesting
Received: new.c
Stored in : saveetha.c
Client side:[cseb17@localhost cseb 17]$cc client.c
[cseb17@localhost cseb 17]$./a.out 127.0.0.1 6142 new.c.saveetha.c
connected...sending filename new.c
hai how are you?
82

10. FILE TRANSFER USING RS232C


Server Side:

cc rsser.c
./a.out 8222
Server waiting for client on port 8222
File received and socket closed
cat> recvfile.txt
this is rs232 program
Client Side:
cc rscli.c
./a.out 197.168.2.100 rsinput.txt 8222
The rsinput.txt send over RS232
cat > rsinput.txt
this is rs232 program

83

S-ar putea să vă placă și