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