answersLogoWhite

0

Frame Sorting Program using C

Updated: 12/24/2022
User Avatar

Wiki User

12y ago

Best Answer
Frame Sort

Basically the frame are sent from the sender side by assigning a frame id,which could be a number.During the transmission of frames across the link the frames can be transmitted out of order w.r.t the frame id assigned to each of the frame.

The frames need to be in order to maintain integrity.

Even though the frames are sent in order,during the transmission the frames may experience delay or routing or any other event which can shuffle the order.

Thus frame sorting is done at the receiver side at the buffer at the DATA Link layer

before sending it to the higher layers.

The sorting can be done in many sorting techniques like bubble sort,merge sort etc.

Simple framesort code in C#include

#include

#include

#include

struct frame

{

char preamble[5];

char dest[48];

char src[48];

int length;

char data[256];

char crc[32];

int seqno;

};

struct frame f[50];

struct frame temp;

int number;

int i,j;

char inputstring[500];

int datasize=5;

void displayinformation()

{

int k=0;

for(k=0;k<=number;k++)

printf("%s",f[k].data);

printf("\n\n");

}

void read()

{

int i=0,j=0,k=0;

char dest[50],src[50];

printf("\nEnter src address : ");

gets(src);

printf("\nEnter dest address : ");

gets(dest);

printf("\nEnter the information : ");

gets(inputstring);

int inputlength=strlen(inputstring);

i=0;

j=0;

f[i].seqno=0;

strcpy(f[i].src,src);

strcpy(f[i].dest,dest);

while(k<=inputlength)

{

f[i].data[j]=inputstring[k++];

if(++j>=datasize)

{

i++;

f[i].seqno=i;

f[i-1].length=datasize;

strcpy(f[i].src,src);

strcpy(f[i].dest,dest);

j=0;

}

}

f[i].length=strlen(f[i].data);

number=i+1;

if(f[i].length==0)

number--;

}

void displayframes()

{

int j;

printf("\n");

for(j=0;j

{

if(j==0)

{

printf("Seq No\t\tDest\t\t\tSrc\t\t\tData\t\tLength\n");

printf("---------------------------------------------------------------------------------------\n");

}

printf("%d\t\t%s\t\t%s\t\t%s\t\t%d\n",f[j].seqno,f[j].dest,f[j].src,f[j].data,f[j].length);

}

}

void shuffle()

{

int i=0,l,p;

i=number;

while(--i>=0)

{

l=rand()%number;

p=rand()%number;

temp=f[l];

f[l]=f[p];

f[p]=temp;

}

}

void bubblesortframes()

{

for(i=0;i

{

for(j=0;j

{

if(f[j].seqno>f[j+1].seqno)

{

temp=f[j];

f[j]=f[j+1];

f[j+1]=temp;

}

}

}

}

int main()

{

read();

printf("\n\nInformation at sender\n");

printf("%s",inputstring);

printf("\nFrame at sender \n");

displayframes();

shuffle();

printf("\n---\nFrame at receiver\n");

displayframes();

printf("\nInformation received at reciever\n");

displayinformation();

bubblesortframes();

printf("\n---\nFrames at receiver after sorting\n");

displayframes();

printf("\nInformation at receiver after sorting\n");

displayinformation();

return 0;

OutputEnter src address : 176.16.1.12

Enter dest address : 176.16.1.44

Enter the information : Mysore boy rocks.

Information at sender

Mysore boy rocks.

Frame at sender

Seq No Dest Src Data Length

---------------------------------------------------------------------------------------

0 176.16.1.44 176.16.1.12 Mysor 5

1 176.16.1.44 176.16.1.12 e boy 5

2 176.16.1.44 176.16.1.12 rock 5

3 176.16.1.44 176.16.1.12 s. 2

---

Frame at receiver

Seq No Dest Src Data Length

---------------------------------------------------------------------------------------

3 176.16.1.44 176.16.1.12 s. 2

1 176.16.1.44 176.16.1.12 e boy 5

0 176.16.1.44 176.16.1.12 Mysor 5

2 176.16.1.44 176.16.1.12 rock 5

Information received at reciever

s.e boyMysor rock

---

Frames at receiver after sorting

Seq No Dest Src Data Length

---------------------------------------------------------------------------------------

0 176.16.1.44 176.16.1.12 Mysor 5

1 176.16.1.44 176.16.1.12 e boy 5

2 176.16.1.44 176.16.1.12 rock 5

3 176.16.1.44 176.16.1.12 s. 2

Information at receiver after sorting

Mysore boy rocks.

Frame Sorting Technique used in buffer.

#include

struct frame{

int num;

char str[20];

};

struct frame arr[10];

int n;

void sort() /*Bubble sort */

{

int i,j;

struct frame temp;

for(i=0;i

for(j=0;j

if(arr[j].num>arr[j+1].num)

{ temp=arr[j];

arr[j]=arr[j+1];

arr[j+1]=temp;

}

}

int main()

{

int i;

system("clear");

printf("Enter the number of frames\n");

scanf("%d",&n);

printf("Enter the frame sequence number and frame contents\n");

for(i=0;i

scanf("%d%s",&arr[i].num,&arr[i].str);

sort();

printf("The frame in sequences\n");

for(i=0;i

printf("%d\t%s\n",arr[i].num,arr[i].str);

}

Mr. Gauro

Nepal Engineering and Technical Science Academy

Birendranagar, Surkhet

Nepal

User Avatar

Wiki User

12y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Frame Sorting Program using C
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Sorting an array in PHP without using sort function?

plz as soon as possible give me the program for shorting an array in asscending order without using any sort function in c++


C program for sorting the numbers?

C program for sorting the numbers is very basic, start writing it and if you are having problems, post your program here and a description of the problem and you will be helped. If you are taking a computer course, how do you expect to pass exams if you have plagiarized someone else work for your assignments.


C program for comparison of dates using structures?

C program for comparison of dates using structures


Write Client and server program in C language using UDP?

Write and run a client and a server program in C-language using UDP


Program to print sorting of an array?

For program in C language: http://wiki.answers.com/Q/Program_to_print_sorting_of_an_array_in_clanguage&updated=1&waNoAnsSet=2 Program in C++: #include #include void main() { int i,j,n,t,a[50]; clrscr(); cout"%d",&n; cout


Write a c program Fibonacci series using for loop in java?

Exactly what do you mean by 'C program in Java'


Is c an application or software?

"C" is a programming language. It is implemented by writing a program using the C syntax and then translated by a compiler, which is an application program.


How do you extend to another c program using a superclass?

C does not support superclassing. Try C++.


Program that is executed in c but not in c?

Answer1. When you save file using extension ".c" the program executes using "C" compiler and it cannot execute any other program which is not in "C".So, we cannot execute program in "C" which is not in "C".2. When you save file using extension ".cpp" the program executes using "C++" compiler and it can execute program of "C" but it should be saved with extension ".cpp".So, There is a program which is not in "C++" can be executed in "C++" compiler.Another answerYour question is ambiguous. 1. Okay in C++ but not in C:int main (void){ cout


How do you write a c program to convert binary to decimal by using while statement?

write a c++ program to convert binary number to decimal number by using while statement


How can you debug a C program in Unix?

You can debug C programs using gdb on Unix.


What is the importance of using functions in a c program?

C programs do not function without functions.