|
cnet's datatypes, event types, and error typescnet's provides a small number of data- and enumerated types, each defined in the <cnet.h> header file.
The CnetNodeType enumerated 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 CnetLinkType enumerated typeEach node's link is either a LOOPBACK, an Ethernet, or a point-to-point link. The type of a link may be determined by examining the value of linkinfo[link].linktype. For example:if(linkinfo[link].linktype == LT_ETHERNET) (void)CNET_set_promiscuous(link, 1);
Calls to the functions
CNET_set_promiscuous, and CNET_set_nicaddrcannot set the attributes of link 0, the LOOPBACK link, nor set a NIC address to either the zero address, 00:00:00:00:00:00, or the broadcast address, ff:ff:ff:ff:ff:ff.
The CnetNicaddr datatypeEach Physical Layer link of type LT_ETHERNET or LT_POINT2POINT has a specific Network Interface Card (NIC) address. cnet provides the CnetNicaddr datatype to represent the addresses of its NICs, as an array of LEN_NICADDR (=6) unsigned characters.Frames written to Ethernet links are ``expected'' to carry the address of their destination Network Interface Card (NIC) at the very beginning of the frame. cnet interprets the leading LEN_NICADDR bytes of each frame on an Ethernet segment to be an address. The special address, whose string representation is ff:ff:ff:ff:ff:ff, is interpreted as the Ethernet broadcast address. Any frame carrying the broadcast address as its destination address will be delivered to all NICs on the Ethernet segment, except the sender. cnet does not support multicast or group addressing. cnet provides the functions CNET_parse_nicaddr and CNET_format_nicaddr to convert between character strings and the CnetNicaddr datatype.
The CnetInt64 datatypeAs of v2.0, cnet supports a 64-bit integer datatype named CnetInt64 which is used to store all times (now in microseconds) and large statistics. The datatype and a number of arithmetic, conversion, and I/O routines are defined in the <cnet64bits.h> header file which, like the <cnet.h> header file (and included by it), is located via the value of CNETPATH. The CnetInt64 datatype is fully described on its own webpage.
The CnetEvent enumerated 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 enumerated 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"); } }
|
cnet was written and is maintained by Chris McDonald (chris@csse.uwa.edu.au) | ![]() |