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
layer3.c File Reference

Layer 3 provides the capability to send and receive messages, where a message is defined as any sequence of bytes. More...

#include "layer.h"

Functions

int layer3_write (char *msg, int len)
 Sends a message. More...
 
int layer3_read (char *msg, int max)
 reads a message and stores it in memory starting at the address specified by msg More...
 

Detailed Description

Layer 3 provides the capability to send and receive messages, where a message is defined as any sequence of bytes.

More specifically, there is no length limitation at layer 3, so a sender can ask layer 3 to send any size message.

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 layer3.c -o ../build/layer3.o

Function Documentation

int layer3_read ( char *  msg,
int  max 
)

reads a message and stores it in memory starting at the address specified by msg

Parameters
[in]msgWhere the message that is read is stored.
[in]maxNo more than max bytes will be put into memory, so max must limit the size of the message read.
Returns
The size of the message received or -1 on error.

If a message is received by layer3_read() that would require more than max bytes, layer3_read() must return -1 (indicating an error).

int layer3_write ( char *  msg,
int  len 
)

Sends a message.

Parameters
[in]msgA message of any length to send.
[in]lenThe size of the message to send.
Returns
The number of bytes (of the message) sent on success (should be len) or -1 on error.