PROGRAM: 1
Aim: To implement the data link layer framing method such as
Character stuffing and Bit stuffing.
Character Stuffing:
Source Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char frame[50],temp[50]="DLESTX";
int i,j=6;
clrscr();
printf(" Enter input character ");
gets(frame);
strcat(temp,frame);
for(i=0;frame[i]!='\0';i++)
{
if((frame[i]=='D'&&frame[i+1]=='L'&&frame[i+2]=
='E')||(frame[i]==" "))
{
strcat(temp,"DLE");
j=j+3;
}
temp[j++]=frame[i];
}
strcat(temp,"DLEETX");
printf("\n The stuffed frame is : \n\t");
puts(temp);}
Output:
Enter input character FDGHDLE
The stuffed frame is:
DLESTXFDGHDLEDLEDLEETX
CN&OS LAB MANUAL
Bit Stuffing:
Source Code:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i;
int frame[20],temp[30],n,j=0,count=0;
clrscr();
printf("\n Enter the length of the input frame:");
scanf("%d",&n);
printf("\n Enter the bit frame\n\t");
for(i=0;i<n;i++)
scanf("%d",&frame[i]);
CN&OS LAB MANUAL
for(i=0;i<n;i++)
{
if(frame[i]==1)
count++;
else
count=0;
temp[j++]=frame[i];
if(count==5)
{
temp[j++]=0;
count=0;
}
}
printf("\n Stuffed frame is \n");
for(i=0;i<j;i++)
printf("%d",temp[i]);}
Output:
Enter the length of the input frame:7
Enter the bit frame
1
1
1
1
1
1
1
Stuffed frame is
11111011
CN&OS LAB MANUAL