Techknow Study

DLL framing method by character stuffing.

10:40:00 PM vikas 0 Comments Category :



WAP in C/C++ to implement DLL framing method by character stuffing.

THEORY & CONCEPT-:

• Also referred to as character stuffing.

 • ASCII characters are used as framing delimiters
(e.g. DLE STX and DLE ETX)

• The problem occurs when these character patterns occur within the “transparent” data.


Solution: sender stuffs an extra DLE into the data  stream just before each occurrence of an “accidental” DLE in the data stream.

The data link layer on the receiving end unstuffs the DLE before giving the data to the network



IMPLEMENTATION IN C/C++-:
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{  char flag='F',p='*',esc='E';
    char string[100],ch;
    int l,i,j=1;
    FILE *fp;
    clrscr();
    fp=fopen("flames","w");
    printf("please enter the string");
    gets(string);
    l=strlen(string);
    printf("%c %c",flag,string[0]);
    putc(flag,fp);
    putc(string[0],fp);
    for(i=1;i<l;i++)
    {   if(j==6)
          {
              printf("%c\n%c",flag,flag);
              putc(flag,fp);
              putc(flag,fp);
              j=0;
                    }
           if(string[i]=='*'||string[i]=='F'||string[i]=='E')
           {
                   printf("%c",esc);
              putc(esc,fp);
              j++;
           }
           if(j!=6)
           {
    printf("%c",string[i]);
              putc(string[i],fp);
              j++;
           }
    }
           for(i=j;i<6;i++)
                    {
                   printf("%c",p);
              putc(p,fp);
}
           printf("F");
           fclose(fp);
           printf("do u want to read file (Y/N):");
           ch=getche();
           if(ch=='y'||ch=='Y')
           {
           return;
           }
           j=0;
           printf("\n");
           fp=fopen("frames","r");
           ch=getc(fp);
           while(ch!=EOF)
           {
                   if(ch==esc&&j==0)
              {
                   ch=getc(fp);
                   j=1;
                   continue;
              }
              if(ch==flag&&j==0)
              {
                   ch=getc(fp);
                   continue;
              }
              if(ch==p&&j==0)
              {
                              ch=getc(fp);
                              continue;
              }
              if(ch==flag||ch==p||ch==esc&&j==1)
              {
                   printf("%c",ch);
                   j=0;
                   ch=getc(fp);
                   continue;
                             }
              else
              {
                   printf("%c",ch);
                   ch=getc(fp);
                   continue;    }
             }

             getch();
}



RELATED POSTS

0 comments