The unit of data passed between your routines and the network layer is a packet_t which includes a character string representing the data that is passed between the application layers and the following data that is used only by the transport layers:
Use the following functions with this data type:
packet_t
s
packet_t new_pkt(void)
new_pkt()
must be called to create a
packet_t
variable for you to manipulate. It will
return a pointer to the data type, or NULL
if the
data type could not be created.
void dispose_pkt(packet_t P)
dispose_pkt(P)
will free the memory
used by the packet_t
P
.
This function is called for you as soon as
clientInput()
or serverInput()
returns.
packet_t
s
void init_pkt (packet_t P)
init_pkt (P)
will initialize the data field
of the packet P
.
This function will work only if P
has been
created with new_pkt()
.
void set_pkt_data
(packet_t P,
int seq_num,
int ack_num,
int checksum,
char * payload)
This function will copy the named values into the fields in the
P
.
The longest possible value of the
payload
field is determined by the
value of PAYLOAD_SZ
in the payload.h
file. set_pkt_data()
will not allow the
payload
field to overflow.
packet_t
s
void copy_pkt (packet_t copy,
packet_t orig)
This function will copy all of the data in
orig
to copy
.
This function will work only if copy
has been
created with new_pkt()
.
packet_t
s
char * pkt_data (packet_t P)
pkt_data(P)
will return a pointer to the
character string stored in the payload
field of
P
. (Remember that C character strings are
null-terminated, so the empty string consists only of
'\0'
.)
int pkt_seq (packet_t P)
pkt_seq(P)
will return a copy of the
sequence number stored in the packet_t
P
.
int pkt_ack (packet_t P)
pkt_ack(P)
will return a copy of the
ACK number stored in the
packet_t
P
.
int pkt_check (packet_t P)
pkt_check(P)
will return a copy of the
checksum int
stored in the packet_t
P
.
int print_pkt (FILE * where,
char * before,
packet_t P,
char * after)
print_pkt(where, before,
P, after)
will pretty-print the
values in P
preceded by
before
and followed by
after
. The output will be sent to the
stream where
.
For example: to print P
to the standard
output device with nothing before it and ending a line you would
call
print_pkt(stdout, "", P, "\n");
packet_t
s
int pkt_size(void)
pkt_size()
returns the number of bytes that a
packet_t
data structure occupies on the network.