J. Blustein

Network Computing

[Crs | Ann | Mats | Res]

Kurose & Ross's Network Simulation Code

[Assignment | Documentation | Source Code ]

Documentation: [Overview | KRnet | stucode | message_t | packet_t  | queue_t ]

[Include contents frame]

message_t

The unit of data passed between the upper layers and your protocols is a message_t which includes a character string. Use the following functions with this data type:

Creating/Destroying

message_t new_msg(void)

new_msg() must be called to create a message_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_msg(message_t M)

dispose_msg(M) will free the memory used by the message M. Call this function only when you do not need M anymore.

Setting Data Fields

void init_msg (message_t M)

init_msg (M) will initialize the data field of the message M. This function will work only if M has been created with new_msg().

void set_msg_data (message_t M, char *data)

set_msg_data(M, data) will copy the null-terminated character string data into the data field of M.

The longest possible value of the data field is determined by the value of PAYLOAD_SZ in the payload.h file. set_msg_data() will not allow the data field to overflow.

void append_msg_data (message_t M, char datum)

append_msg_data (M, datum) will include the character datum at the end of the data field in M (unless there is no more room in the data field).

The longest possible value of the data field is determined by the value of PAYLOAD_SZ in the payload.h file. append_msg_data() will not allow the data field to overflow.

Reading Data Fields

char * msg_data (message_t M)

msg_data(M) will return a pointer to the character string stored in the data field of M. (Remember that C strings are null-terminated, so the empty string consists only of '\0'.)

int print_msg (FILE * where, char * before, message_t M, char * after)

print_msg(where, before, M, after) will pretty-print the values in M preceded by before and followed by after. The output will be sent to the stream where.

For example: to print M to the standard output device with nothing before it and ending a line you would call print_msg(stdout, "", M, "\n");

Documentation: [ Overview | KRnet | stucode | message_t | packet_t  | queue_t ]


http://web.cs.dal.ca/~jamie/course/CS/3171/Materials/KR_1e/Code/Chapter3/doc/message.shtml
Version:
Sunday, 27-Jul-2003 13:34:59 ADT
CS 3171 Prof.:
J. Blustein <jamie@cs.dal.ca>

This webpage uses valid XHTML 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]