Question

Please type answer do not hand write. Thank you Write a program that implements message flow...

Please type answer do not hand write. Thank you

Write a program that implements message flow from the top layer to the bottom layer
of the 7-layer protocol model. Your program should include a separate protocol function
for each layer. Protocol headers are sequence up to 64 characters. Each protocol
function has two parameters: a message passed from the higher layer protocol (a char
buffer) and the size of the message. This function attaches its header in front of the
message, prints the new message on the standard output, and then invokes the protocol
function of the lower-layer protocol. Program input is an application message (a sequence
of 80 characters or less).

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer is as follows:

Code is as follows : Written in C language.

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "assert.h"

void application_layer_send(char *buffer, int len);
void presentation_layer_send(char *buffer, int len);
void session_layer_send(char *buffer, int len);
void transport_layer_send(char *buffer, int len);
void network_layer_send(char *buffer, int len);
void datalink_layer_send(char *buffer, int len);
void physical_layer_send(char *buffer, int len);

char* attach_header(char *buffer, char *header, int *len2) {
int len = strlen(buffer);
int hlen = strlen(header);
*len2 = len + hlen;

char *buffer2 = (char*)malloc(*len2 + 1);
memcpy(buffer2, header, hlen);
memcpy(buffer2 + hlen, buffer, len);
buffer2[*len2] = '\0';

return buffer2;
}

void application_layer_send(char *buffer, int len) {
static char header[] = "application_layer_header;";
assert(strlen(buffer) == len);

int len2 = 0;
char *buffer2 = attach_header(buffer, header, &len2);
printf("%s\n", buffer2);

presentation_layer_send(buffer2, len2);
free(buffer2);
}

void presentation_layer_send(char *buffer, int len) {
char header[] = "presentation_layer_header;";
assert(strlen(buffer) == len);

int len2 = 0;
char *buffer2 = attach_header(buffer, header, &len2);
printf("%s\n", buffer2);

session_layer_send(buffer2, len2);
free(buffer2);
}

void session_layer_send(char *buffer, int len) {
char header[] = "session_layer_header;";
assert(strlen(buffer) == len);

int len2 = 0;
char *buffer2 = attach_header(buffer, header, &len2);
printf("%s\n", buffer2);

transport_layer_send(buffer2, len2);
free(buffer2);
}

void transport_layer_send(char *buffer, int len) {
char header[] = "transport_layer_header;";
assert(strlen(buffer) == len);

int len2 = 0;
char *buffer2 = attach_header(buffer, header, &len2);
printf("%s\n", buffer2);

network_layer_send(buffer2, len2);
free(buffer2);
}

void network_layer_send(char *buffer, int len) {
char header[] = "network_layer_header;";
assert(strlen(buffer) == len);

int len2 = 0;
char *buffer2 = attach_header(buffer, header, &len2);
printf("%s\n", buffer2);

datalink_layer_send(buffer2, len2);
free(buffer2);
}

void datalink_layer_send(char *buffer, int len) {
char header[] = "datalink_layer_header;";
assert(strlen(buffer) == len);

int len2 = 0;
char *buffer2 = attach_header(buffer, header, &len2);
printf("%s\n", buffer2);

physical_layer_send(buffer2, len2);
free(buffer2);
}

void physical_layer_send(char *buffer, int len) {
char header[] = "physical_layer_header;";
assert(strlen(buffer) == len);

int len2 = 0;
char *buffer2 = attach_header(buffer, header, &len2);
printf("%s\n", buffer2);

free(buffer2);
}

void application_routine() {
char message[] = "Hello World!";
application_layer_send(message, strlen(message));
}

int main(int argc, char *argv[]) {
application_routine();
return 0;
}

if there is any query please ask in comments...

Add a comment
Know the answer?
Add Answer to:
Please type answer do not hand write. Thank you Write a program that implements message flow...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Q.1. Write a C program that determines whether a line entered by a user is a...

    Q.1. Write a C program that determines whether a line entered by a user is a palindrome or not. You must demonstrate it as an application of stack (you may use linked list implementation demonstrated in the class). Hint! Think of the basic property of a stack i.e. LIFO (list-in-first-out). Q.2. Write a charQueue header file containing all the function headers of following functions: 1- initiateQueue—to initialize a queue 2- enqueue—to add a node at the rear end of the...

  • I need help programming this program in C. 1.) Write a program that reads a message,...

    I need help programming this program in C. 1.) Write a program that reads a message, then checks whether it's a palindrome (the letters in the message are the same from left to right as from right to left), example is shown below: Enter a message: He lived as a devil, eh? Palindrome Enter a message: Madam, I am Adam. Not a Palindrome 2.) Ignore all characters that aren't letters. Use integer variables to keep track of positions in the...

  • Please write a c++ header file, class implementation file and main file that does all of...

    Please write a c++ header file, class implementation file and main file that does all of the following and meets the requirements listed below. Also include a Output of your code as to show that your program works and functions properly. EXERCISING A DOUBLY-LINKED LIST CLASS This project consists of two parts, the second of which appears below. For the first part, write a class that implements an unordered list abstract data type using a doubly-linked list with pointers to...

  • Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate...

    Write a C++ program named, gradeProcessor.cpp, that will do the following tasks: -Print welcome message -Generate the number of test scores the user enters; have scores fall into a normal distribution for grades -Display all of the generated scores - no more than 10 per line -Calculate and display the average of all scores -Find and display the number of scores above the overall average (previous output) -Find and display the letter grade that corresponds to the average above (overall...

  • write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy....

    write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...

  • Please read the problem carefully and answer the 2 questions below code: /***************************************************************** * Program: palindrome.c...

    Please read the problem carefully and answer the 2 questions below code: /***************************************************************** * Program: palindrome.c * * Purpose: implements a recursive function for determining *   if a string is a palindrome * * Authors: Steven R. Vegdahl, Tammy VanDeGrift, Martin Cenek * *****************************************************************/ #include #include #include /***************************************************************** * is_palindrome - determines whether a string of characters is a palindrome * * calling sequence: *    result = is_palindrome(str, first_index, last_index) * * parameters - *    str - the string to test *    first_index -...

  • Consider the following program that reads students’ test scores into an array and prints the contents of the array. You will add more functions to the program. The instructions are given below.

    Consider the following program that reads students’ test scores into an array and prints the contents of the array.   You will add more functions to the program.  The instructions are given below.              For each of the following exercises, write a function and make the appropriate function call in main.Comments are to be added in the program. 1.       Write a void function to find the average test score for each student and store in an array studentAvgs. void AverageScores( const int scores[][MAX_TESTS],                       int...

  • Please write code using Python. Rubric Assignment Solution Total: 100 pts Program successfully retrieves and validates...

    Please write code using Python. Rubric Assignment Solution Total: 100 pts Program successfully retrieves and validates user input 15 pts Morse Code Function Created 10 pts Function Uses Parameters to get input message 15 pts Function successfully converts passed message to Morse Code and returns the Morse Code equivalent of message 45 pts Program calls Morse Code function and outputs the result of the function (i.e. the actual Morse Code) 15 pts Main Function Requirement Part 2 MUST have a...

  • In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and...

    In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and use recursive functions In this lab, we will write a program that uses three recursive functions. Requirements: Important: You must use the array for this lab, no vectors allowed. First Recursive Function Write a function that recursively prints a string in reverse. The function has ONLY one parameter of type string. It prints the reversed character to the screen followed by a newline character....

  • C++ programming question Topic: Class 'Date' Hello everybody, can some one help me... ... Write a...

    C++ programming question Topic: Class 'Date' Hello everybody, can some one help me... ... Write a class Date with the following properties: a) Data elements of the class are day, month, year. All three data elements are defined by the Type int. b) A set and a get element function are to be provided for each data element. In Within the framework of this task, it should be assumed that the values that are passed for day and year, are...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT