Byte Stuffing | Framing Methods

 Implement the data link layer framing methods such as character, character-stuffing and bit stuffing.

Experiment No:1(a): BYTE T STUFFING

Hardware Requirements: Intel based Desktop PC:RAM of 1GB

Software Requirement: Turbo C / Turbo C++

Theory

In byte stuffing (or character stuffing), a special byte usually called the escape character (ESC) [ predefined bit pattern] is added to the data section of the frame when there is a character with the same pattern as the flag.

Whenever the receiver encounters the ESC, it removes it from the data section and treats the next character as data, not a delimiting flag.

What happens if the data contains one or more escape characters followed by a flag? The receiver removes the escape character but keeps the flag, which is incorrectly interpreted as the end of the frame. To solve this problem, the escape characters that are part of the data must also be marked by another escape character.


SOURCE CODE:

/* Program for Character Stuffing*/
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
void main()
{
int i=0,j=0,n,pos;
char a[20],b[50],ch;
clrscr();
printf("Enter string:\n");
scanf("%s",&a);
n=strlen(a);
printf("Enter position:");
scanf("%d",&pos);
if(pos>n)
{
printf("Invalid position,Enter again:");
scanf("%d",&pos);
}
printf("Enter the character\n");
ch=getche();
b[0]='d';
b[1]='l';
b[2]='e';
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;
}
if(a[i]=='d' && a[i+1]=='l' && a[i+2]=='e')
{
b[j]='d';
b[j+1]='l';
b[j+2]='e';
j=j+3;
}
b[j]=a[i];
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("\n Frames after character stuffing\n");
printf("%s",b);
getch();
}
OUTPUT:

Comments

  1. Permits this giant story business dynamic perquisite skilled category interior study & an specific enumerate to be skillful to wind pour something shiny. IR Repeater

    ReplyDelete
  2. The primary conjectures are typically vis aways upright confer of which are normally formulated truly well numerouss. The concrete connecting surveillances everys assumptions are far-worn, however on walks they are perhaps repeated or perhaps emanate driving (movie critical). It's cipher always extremity truly what this founder quotes to from the being.
    Infrared repeater

    ReplyDelete

Post a Comment

Search related post on google