J. Blustein

Network Computing

[Crs | Ann | Mats | Res]

Kurose & Ross's Network Simulation Code

[Assignment | Documentation | Source Code ]

[Include contents frame]

packet_t

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:

Creating/Destroying packet_ts

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.

Setting Data Fields in packet_ts

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.

Copying packet_ts

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().

Reading Fields in packet_ts

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");

Size of packet_ts

int pkt_size(void)

pkt_size() returns the number of bytes that a packet_t data structure occupies on the network.


http://web.cs.dal.ca/~jamie/course/CS/3171/Materials/KR_1e/Code/Chapter3/doc/packet.shtml
Version:
Wednesday, 30-Jul-2003 21:44:04 ADT
CS 3171 Prof.:
J. Blustein <jamie@cs.dal.ca>

This webpage uses valid XHTPL 1.0

Based on
document at <URL:http://occawlonline.pearsoned.com/bookbind/pubbooks/kurose-ross1/chapter4/custom12/deluxe-content.html> (copied on 05 July 2002). That document is © 2000-2001 by Addison Wesley Longman A division of Pearson Education

[Include contents frame]