CN Lab Manual
CN Lab Manual
EXPERIMENT-1
Aim: Study of Network devices in detail and connect the computers in Local Area Network.
1. **Router:**
- A router is a networking device that connects multiple networks together, such as LANs and the
Internet.
- In a LAN, the router serves as the gateway to the Internet and handles the distribution of internet
traffic to connected devices.
2. **Switch:**
- It operates at the data link layer (Layer 2) of the OSI model and uses MAC addresses to forward
data packets between devices on the same network.
- Switches offer dedicated bandwidth to each connected device, improving network performance
compared to older hub-based networks.
3. **Hub:**
- A hub is an older networking device that operates similarly to a switch but lacks intelligence.
- It operates at the physical layer (Layer 1) and simply broadcasts data to all connected devices,
leading to inefficient use of network bandwidth.
- An access point is a device that enables wireless devices to connect to a wired network.
- It acts as a bridge between wired and wireless networks, providing Wi-Fi connectivity to devices
like laptops, smartphones, and tablets.
1
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
- It provides the necessary physical interface (Ethernet port for wired connections or Wi-Fi antenna
for wireless connections) to communicate with other devices on the network.
6. **Modem:**
- A modem stands for modulator-demodulator. It converts digital signals from a computer into
analog signals suitable for transmission over analog communication channels (like telephone lines).
- On the receiving end, it converts incoming analog signals back into digital signals for the computer
to understand.
- Modems are commonly used to provide internet connectivity over DSL (Digital Subscriber Line) or
dial-up connections.
Now, let's connect the computers in a Local Area Network using a combination of wired and wireless
connections:
1. **Wired Connection:**
- For a wired LAN, you would need a switch to connect multiple computers and devices together.
- Each computer would require a Network Interface Card (NIC) with an Ethernet port.
- Connect each computer's Ethernet port to one of the switch ports using an Ethernet cable.
- If you need to provide internet access, connect the router's Ethernet port to one of the switch ports
as well.
2. **Wireless Connection:**
- To add wireless connectivity to the LAN, you'll need an Access Point (AP).
- Configure the AP to provide Wi-Fi connectivity with a specific SSID (Wi-Fi network name) and
security settings (WPA2, WPA3, etc.).
- Laptops, smartphones, and other wireless devices can now connect to the LAN by joining the
configured Wi-Fi network.
By combining wired and wireless connections, you can create a LAN that accommodates both types of
devices, providing seamless connectivity and access to shared resources like printers and files.
2
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
EXPERIMENT-2.(a)
AIM: Implement the data link layer framing methods such as and bit stuffing.
SOURCE CODE:
#include<stdio.h>
#include<string.h>
void main()
int a[20],b[30],i,j,k,count,n;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
while(i<n)
if(a[i]==1)
b[j]=a[i];
if(count==5)
j++;
3
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
b[j]=0;
i=k;
}}
else
b[j]=a[i];
i++;
j++;
for(i=0;i<j;i++)
printf("%d",b[i]);
OUTPUT:
4
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
EXPERIMENT-2.(b)
AIM: Implement the data link layer framing methods such as character, character stuffing.
SOURCE CODE:
#include<stdio.h>
#include<string.h>
#include<process.h>
void main()
int i=0,j=0,n,pos;
char a[20],b[50],ch;
printf("enter string\n");
scanf("%s",&a);
n=strlen(a);
printf("enter position\n");
scanf("%d",&pos);
if(pos>n)
scanf("%d",&pos);
ch=getche();
b[0]='d';
b[1]='l';
b[2]='e';
5
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
b[3]='s';
b[4]='t';
b[5]='x';
j=6;
while(i<n)
if(i==pos-1)
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]=ch;
b[j+4]='d';
b[j+5]='l';
b[j+6]='e';
j=j+7;
b[j]='d';
b[j+1]='l';
b[j+2]='e';
j=j+3;
b[j]=a[i];
6
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
i++;
j++;
b[j]='d';
b[j+1]='l';
b[j+2]='e';
b[j+3]='e';
b[j+4]='t';
b[j+5]='x';
b[j+6]='\0';
printf("%s",b);
OUTPUT:
enter string
MLRITM
enter position
dlestxMdldleLRITMdleetx
7
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
EXPERIMENT-3
Aim: . Write a Program to implement data link layer farming method checksum.
SOURCE CODE:
#include <stdio.h>
checksum += data_frame[i];
int main()
8
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
printf("\n");
return 0;
OUTPUT:
9
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
EXPERIMENT-4
Aim: Write a program for Hamming Code generation for error detection and correction.
SOURCE CODE:
#include <stdio.h>
int r = 1;
r++;
return r;
int r = calculate_num_parity_bits(data_size);
int j = 0;
hamming[i - 1] = 0;
} else
10
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
hamming[i - 1] = data[j];
j++;
hamming[parity_bit_pos] = parity;
printf("%d", hamming[i]);
printf("\n");
11
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
int main() {
int r = calculate_num_parity_bits(data_size);
int hamming[hamming_size];
print_hamming_code(hamming, hamming_size);
return 0;
OUTPUT:
12
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
EXPERIMENT NO: 5
AIM: Implement on a data set of characters the three CRC polynomials – CRC 12, CRC 16 and CRC CCIP.
SOURCE CODE:
#include<stdio.h>
int gen[4],genl,frl,rem[4];
void main()
int i,j,fr[8],dupfr[11],recfr[11],tlen,flag;
frl=8; genl=4;
printf("enter frame:");
for(i=0;i<frl;i++)
scanf("%d",&fr[i]);
dupfr[i]=fr[i];
printf("enter generator:");
for(i=0;i<genl;i++)
scanf("%d",&gen[i]);
tlen=frl+genl-1;
for(i=frl;i<tlen;i++)
dupfr[i]=0;
remainder(dupfr);
13
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
for(i=0;i<frl;i++)
recfr[i]=fr[i];
for(i=frl,j=1;j<genl;i++,j++)
recfr[i]=rem[j];
remainder(recfr);
flag=0;
for(i=0;i<4;i++)
if(rem[i]!=0)
flag++;
if(flag==0)
else
remainder(int fr[])
14
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
int k,k1,i,j;
for(k=0;k<frl;k++)
if(fr[k]==1)
k1=k;
for(i=0,j=k;i<genl;i++,j++)
rem[i]=fr[j]^gen[i];
for(i=0;i<genl;i++)
fr[k1]=rem[i];
k1++;
OUTPUT:
enter frame:MLRITM
15
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
EXPERIMENT-6
Source Code:
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
#define WINDOW_SIZE 4
void sender()
int next_seq_num = 0;
int base = 0;
16
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
if (is_successful_transmission(transmission_probability))
next_seq_num++;
} else {
base = next_seq_num;
void receiver() {
int expected_seq_num = 0;
if (is_successful_transmission(acknowledgment_probability))
expected_seq_num++;
17
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
} else {
int main() {
srand(time(NULL));
sender();
receiver();
return 0;
OUTPUT:
Sending packet 0
Sending packet 1
Sending packet 2
Sending packet 3
Sending packet 4
Sending packet 5
Sending packet 6
18
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
Sending packet 7
Sending packet 8
Sending packet 9
Received packet 0
Received packet 1
Received packet 2
Received packet 3
Received packet 4
Received packet 5
Received packet 6
Received packet 7
Received packet 8
Received packet 9
19
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
EXPERIMENT-7
Aim: Write a Program to implement Sliding window protocol for Selective repeat.
SOURCE CODE:
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <time.h>
#define WINDOW_SIZE 4
void sender()
int next_seq_num = 0;
int base = 0;
20
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
next_seq_num++;
if (is_successful_transmission(transmission_probability))
received_ack[i] = 1;
while (received_ack[base])
base++;
void receiver()
int expected_seq_num = 0;
21
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
if (is_successful_transmission(acknowledgment_probability))
expected_seq_num++;
int main() {
srand(time(NULL));
sender();
receiver();
return 0;
OUTPUT:
Sending packet 0
Sending packet 1
22
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
Sending packet 2
Sending packet 3
Sending packet 4
Sending packet 5
Sending packet 6
Sending packet 7
Sending packet 8
Sending packet 9
Received packet 0
Received packet 1
Received packet 2
23
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
Received packet 3
Received packet 4
Received packet 5
Received packet 6
Received packet 7
Received packet 8
Received packet 9
24
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
EXPERIMENT-8
SOUCE CODE:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char send_buffer[100];
char recv_buffer[100];
int send_index = 0;
int recv_index = 0;
void send_packet();
void receive_packet();
int main()
while (1)
send_packet();
receive_packet();
return 0;
void send_packet()
25
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
send_index++;
void receive_packet()
char recv_byte;
recv_byte = getchar();
recv_buffer[recv_index] = recv_byte;
recv_index++;
OUTPUT:
Sending byte 0
Received byte A
Sending byte 0
Received byte B
Sending byte 0
Received byte C
Sending byte 0
Received byte D
Sending byte 0
...
26
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
EXPERIMENT-9
Am: Write a program for congestion control using leaky bucket algorithm.
SOURCE CODE:
#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#define BUCKET_SIZE 10
#define OUT_RATE 3
int main()
int bucket_level = 0;
int packet_counter = 0;
send_packet(packet_counter);
packet_counter++;
27
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
else
usleep(1000000 / OUT_RATE);
if (bucket_level > 0)
bucket_level--;
return 0;
OUTPUT:
Sending packet 0
Sending packet 1
Sending packet 2
Sending packet 3
Sending packet 4
28
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
Sending packet 5
Sending packet 6
Sending packet 7
Sending packet 8
Sending packet 9
Sending packet 10
Sending packet 11
Sending packet 12
Sending packet 13
Sending packet 14
Sending packet 15
Sending packet 16
Sending packet 17
Sending packet 18
Sending packet 19
29
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
EXPERIMENT-10
AIM: Write a Program to implement Dijkstra‘s algorithm to compute the Shortest path through a graph.
SOURCE CODE:
#include<stdio.h>
void main()
int path[5][5],i,j,min,a[5][5],p,st=1,ed=5,stp,edp,t[5],index;
for(i=1;i<=5;i++)
for(j=1;j<=5;j++)
scanf("%d",&a[i][j]);
scanf("%d",&p);
for(i=1;i<=p;i++)
30
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
for(j=1;j<=5;j++)
scanf("%d",&path[i][j]);
for(i=1;i<=p;i++)
t[i]=0;
stp=st;
for(j=1;j<=5;j++)
edp=path[i][j+1];
t[i]=t[i]+a[stp][edp];
if(edp==ed)
break;
else
stp=edp;
min=t[st];index=st;
for(i=1;i<=p;i++)
if(min>t[i])
min=t[i];
index=i;
31
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
for(i=1;i<=5;i++)
printf("--> %d",path[index][i]);
if(path[index][i]==ed)
break;
OUTPUT:
12345
12345
12345
12345
12345
12345
12345
minimum cost 14
32
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
EXPERIMENT NO: 11
AIM: Obtain Routing table at each node using distance vector routing algorithm for a given subnet.
SOURCE CODE:
#include<stdio.h>
struct node
unsigned dist[20];
unsigned from[20];
}rt[10];
int main()
int dmat[20][20];
int n,i,j,k,count=0;
scanf("%d",&n);
33
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&dmat[i][j]);
dmat[i][i]=0;
rt[i].dist[j]=dmat[i][j];
rt[i].from[j]=j;
do
count=0;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
for(k=0;k<n;k++)
if(rt[i].dist[j]>dmat[i][k]+rt[k].dist[j])
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];
rt[i].from[j]=k;
count++;
}while(count!=0);
for(i=0;i<n;i++)
for(j=0;j<n;j++)
34
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
printf("\n");
OUTPUT:
12
12
35
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
EXPERIMENT NO: 12
SOURCE CODE:
#include<stdio.h>
int p,q,u,v,n;
int min=99,mincost=0;
int t[50][2],i,j;
int parent[50],edge[50][50];
main()
clrscr();
scanf("%d",&n);
for(i=0;i<n;i++)
printf("%c\t",65+i);
parent[i]=-1;
printf("\n");
for(i=0;i<n;i++)
printf("%c",65+i);
for(j=0;j<n;j++)
scanf("%d",&edge[i][j]);
}for(i=0;i<n;i++)
36
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
for(j=0;j<n;j++)
if(edge[i][j]!=99)
if(min>edge[i][j])
min=edge[i][j];
u=i;
v=j;
p=find(u);
q=find(v);
if(p!=q)
t[i][0]=u;
t[i][1]=v;
mincost=mincost+edge[u][v];
sunion(p,q);
}else{
t[i][0]=-1;
t[i][1]=-1;
min=99;
for(i=0;i<n;i++)
37
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
edge[t[i][0]][t[i][1]]);
printf("\n");
}}
sunion(int l,int m)
parent[l]=m;
find(int l)
if(parent[l]>0)
l=parent[l];
return l;
OUTPUT:
ABC
A1 2 3 4
B1 2 3 4
C4 5 6 7
Minimum cost is 3
CA
38
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
EXPERIMENT-13
SOURCE CODE:
#include <stdio.h>
#include <pcap.h>
#define MAX_PACKETS_TO_CAPTURE 10
void packet_handler(u_char *user_data, const struct pcap_pkthdr *pkthdr, const u_char *packet)
int main()
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t *handle;
if (handle == NULL)
return 1;
39
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
if (packet == NULL)
return 1;
pcap_close(handle);
return 0;
OUTPUT:
40
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
Source Code:
#include <stdio.h>
#include <stdlib.h>
int main()
printf("Starting Wireshark...\n");
system("wireshark");
return 0;
OUTPUT:
Starting Wireshark...
41
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
SOURCE CODE:
#include <stdio.h>
#include <stdlib.h>
int main()
char filename[256];
scanf("%255s", filename);
char command[512];
system(command);
return 0;
OUTPUT:
42
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
SOURCE CODE:
#include <stdio.h>
#include <stdlib.h>
int main() {
char filter[256];
printf("Enter the Wireshark filter (e.g., 'ip', 'tcp port 80'): ");
char command[512];
system(command);
return 0;
OUTPUT:
Enter the Wireshark filter (e.g., 'ip', 'tcp port 80'): [user input]
43
CN LAB MANUAL CSE DEPARTMENT B.TECH III CSE
EXPERIMENT-15
SOURCE CODE:
#include <stdio.h>
#include <stdlib.h>
int main() {
char target[256];
scanf("%255s", target);
char command[512];
system(command);
return 0;
OUTPUT:
Enter the target IP address or hostname: [user input]
44