/******************************************/ /* network.h 0.2.2 (1999-Dec-05-Sun) */ /* Adam M. Costello */ /******************************************/ /* Send network-layer packets. */ /* This is ANSI C code. */ #ifndef NETWORK_H #define NETWORK_H #include enum { max_network_address_length = 64 }; struct network_address { unsigned short length; unsigned char address[max_network_address_length]; }; /* Every address has its own length, in bytes, not to exceed */ /* the maximum declared above. The unused bytes could contain */ /* anything, so be careful not to compare them when comparing */ /* two addresses. */ struct network_packet { struct network_address source; struct network_address destination; const unsigned char *payload; size_t payload_length; }; void network_send_packet(struct network_packet packet); /* Sends (unreliably) a packet carrying the supplied payload */ /* from the indicated source (which must be an interface of the */ /* sending host) to the indicated destination. The network may */ /* delay, drop, duplicate, reorder, misroute, and alter packets. */ /* */ /* WARNING: Different machines have different internal */ /* representations of data types (like integers and structures). */ /* Therefore you must convert all data to a well-defined sequence */ /* of bytes before putting it into a packet. */ /* */ /* Note that the network will copy the payload, so the caller */ /* retains ownership of that memory. */ size_t network_max_payload_length( struct network_address source, struct network_address destination ); /* Returns the maximum allowable payload length for the given */ /* source and destination, which is guaranteed to be at least */ /* 320. You may assume that this won't change over time (though */ /* this is an unrealistic assumption). Packets with payloads */ /* that are too long will be dropped, not fragmented. */ #endif /* NETWORK_H */