Project 1 - Peer-to-peer and interface protocols using C  1.0
A half-duplex layered communication system.
 All Classes Files Functions Macros
Macros | Functions
layer2.c File Reference

Layer 2 provides the transmission and receipt of a chunk of data. More...

#include "layer.h"

Macros

#define LAYER2_H
 
#define SCHKSZE   2 /* small check size */
 

Functions

int layer2_write (char *chunk, int len)
 Sends a chunk that consists of the sequence of bytes starting at the address specified by the first parameter (chunk) with length len. More...
 
int layer2_read (char *chunk, int max)
 Reads a chunk and stores the incoming bytes in the buffer starting at the address specified by the first parameter (chunk). More...
 

Detailed Description

Layer 2 provides the transmission and receipt of a chunk of data.

DETAILED DESCRIPTION

Peer-to-peer and Interface Protocols Using C

Author
Nicholas Guthrie guthr.nosp@m.n@rp.nosp@m.i.edu http//nickguthrie.com January 30, 2014

Compile with: gcc -c layer4.c -o ../build/layer4.o

Function Documentation

int layer2_read ( char *  chunk,
int  max 
)

Reads a chunk and stores the incoming bytes in the buffer starting at the address specified by the first parameter (chunk).

Warning
Make sure that your layer2_read() does not allow the sender to overflow the buffer! And it's not enough to recognize when this has happened and return an error; you must not store anything beyond the max location of chunk.
Parameters
[in]chunkA sequence of bytes whose length is no greater than 16 bytes as defined by MAX_CHUNK_SIZE which can contain any type of data.
[in]maxNo more than max bytes will be put into chunk, so max limits the size of the chunk read.
Returns
Upon successfully receiving a chunk, the size of the chunk in bytes is returned.
int layer2_write ( char *  chunk,
int  len 
)

Sends a chunk that consists of the sequence of bytes starting at the address specified by the first parameter (chunk) with length len.

Warning
all errors that can be detected here must be handled here including valid values of len and the return value of layer1_write()
Parameters
[in]chunkThe data to write using layer 1 protocols.
[in]lenThe size of the chunk to write.
Returns
len on success, -1 on error