Project 1 - Peer-to-peer and interface protocols using C
1.0
A half-duplex layered communication system.
|
Layer 4 adds simple error detection to layer 4 services. More...
#include "layer.h"
Macros | |
#define | LAYER4_H |
#define | CHKFRSZ 4 |
Functions | |
int | layer4_write (char *msg, int len) |
Computes a checksum of the message and sends it to layer4_read. More... | |
int | layer4_read (char *msg, int max) |
Reads a message into memory starting at the address specified by msg. More... | |
Layer 4 adds simple error detection to layer 4 services.
The errors to look for here involve transmission errors; we want to somehow make sure that the message received is the same as the message that was sent. The simplest approach to error detection is to use a checksum. The checksum is the sum % 65536. The resulting two-byte checksum should be sent along with the message data; the receiving end goes through the same steps to compute the checksum, then compares the received checksum to the computed checksum.
Peer-to-peer and Interface Protocols Using C
Compile with: gcc -c layer4.c -o ../build/layer4.o
int layer4_read | ( | char * | msg, |
int | max | ||
) |
Reads a message into memory starting at the address specified by msg.
[in] | msg | No more than max bytes will be put into memory, so max must limit the size of the message read. |
[in] | max | The maximum size of the message. |
int layer4_write | ( | char * | msg, |
int | len | ||
) |
Computes a checksum of the message and sends it to layer4_read.
[in] | msg | The message to send. |
[in] | len | The length of the message. |