Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your C program should conform to the following specification: Write a C program that computes a simple checksum of 10 8-bit integers. This program is

Your C program should conform to the following specification:

Write a C program that computes a simple checksum of 10 8-bit integers.

  • This program is based upon the calculation of the checksum value of a IPv4 header, defined by RFC791.
  • Program name: checksum
  • Reads 10 bytes from standard input (stdin), using the 'read' system call
  • Interpets or casts each of these bytes as an integer value in the range of 0..2^8-1 (I.e., 0..255).
  • Via a loop, examines each of these bytes in turn,
    • computes the running 1's complement sum for 8-bit numbers
    • saves the 6th byte into a variable called "checksum", and use the value of zero (0) instead for the calculation of the sum
  • Performs the one's complement of the final sum and saves this value to a variable called "complement"
  • Outputs the value of "checksum" and "complement" to standard output (stdout) via the printf C library call
  • If the value of "checksum" and "complement" are not the same, outputs the string "Error Detected!" to standard error (stderr).

#include "stdio.h" #include "stdlib.h" #include  #define max_int (255) #define byte (char) int main (int argc, char * argv[], char ** envp) { int count = 10; int sum = 0; byte checksum; byte complement; /* the following is the prototype for the read system call */ /* int read(int fildes, void *buf, size_t nbyte); */ 
 fprintf(stdout, "Stored Checksum: %d, Computed Checksum: %d ", checksum, complement); if (checksum != complement ) { fprintf(stderr, "Error Detected! "); return 1; } return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle RMAN For Absolute Beginners

Authors: Darl Kuhn

1st Edition

1484207637, 9781484207635

More Books

Students also viewed these Databases questions

Question

What other visualizations might you use to explore sales revenue?

Answered: 1 week ago

Question

Differentiate tan(7x+9x-2.5)

Answered: 1 week ago

Question

Explain the sources of recruitment.

Answered: 1 week ago

Question

Differentiate sin(5x+2)

Answered: 1 week ago

Question

Compute the derivative f(x)=1/ax+bx

Answered: 1 week ago

Question

4-35. The two reporters (ran after) every lead enthusiastically.

Answered: 1 week ago