|
with various data-link layer, network layer, routing and transport
layer networking protocols. It has been specifically developed for
undergraduate teaching.">
undergraduate, teaching">
TEXT ="black" LINK="blue" VLINK="purple">
cnet's node types, event types, and error typescnet's provides three enumerated data types, each defined in its <cnet.h> header file.
The CnetNodeType typeEach node is either a host (a workstation) or a router. The type of a node may be determined by examining its value of nodeinfo.nodetype. For example:if(nodeinfo.nodetype == NT_HOST) (void)CNET_set_handler(EV_APPLICATIONREADY, appl_ready, 0);
Note that calls to the functions
CNET_write_application, CNET_read_application, CNET_enable_application, CNET_disable_application and CNET_set_handler(EV_APPLICATIONLAYER,...) or CNET_set_handler(EV_KEYBOARDREADY,...) are only valid if called from a node of node type NT_HOST.
The CnetEvent typeEvents occur in cnet when a node reboots, the Application Layer has a message for delivery, the Physical Layer receives a frame on a link, the keyboard provides a line of input, a link changes state (either up or down), a timer event expires, a debugging button (under X-windows) is selected, and a node is (politely) shutdown (no event is delivered if a node pauses, crashes or suffers a hardware failure). All such events are of type CnetEvent. Interest may be registered in each event with CNET_set_handler; events are received as the first parameter of each event handler, and their invocation may be traced with CNET_set_trace.
The CnetError typeMost cnet library functions return the integer 0 on success and the integer -1 on failure. The most recent error status is reflected in the global variable cnet_errno. All values of cnet_errno will be instances of the enumerated type CnetError. Errors may be reported to stderr with cnet_perror() and their error message string accessed from cnet_errstr[(int)cnet_errno]. For example:if(CNET_write_application(msgbuffer, &msglength) != 0) { /* an error has occured */ if(cnet_errno == ER_BADSESSION) { /* handle this special case */ .... } else { cnet_perror("writing to application"); } }
|