#ifndef minet_sockets #define minet_sockets #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef __cplusplus #define EXTERNC extern "C" #else #define EXTERNC #endif typedef enum {MINET_KERNEL, MINET_USER} minet_socket_types; EXTERNC int minet_error (); // Returns the error code for the last error. EXTERNC int minet_perror (char *s); // Prints an informative error message for the last error. EXTERNC int minet_init (minet_socket_types type); // initialize minet to use kernel or minet sockets. EXTERNC int minet_deinit (); // de-initialize minet. EXTERNC int minet_socket (int type); // Create a socket. Type must be SOCK_STREAM (TCP) or SOCK_DGRAM (UDP) EXTERNC int minet_bind (int sockfd, struct sockaddr_in *myaddr); // Bind a socket to the IP address (AF_INET) and port specified in myaddr. EXTERNC int minet_listen (int sockfd, int backlog); // Listen on a socket. EXTERNC int minet_accept (int sockfd, struct sockaddr_in *addr); // Accept a connection. EXTERNC int minet_connect (int sockfd, struct sockaddr_in *addr); // Connect to a remote socket. EXTERNC int minet_read (int fd, char *buf, int len); // Read from a connected socket (returns # bytes actually read). EXTERNC int minet_write (int fd, char *buf, int len); // Write to a connected socket (returns # bytes actually written). EXTERNC int minet_recvfrom (int fd, char *buf, int len, struct sockaddr_in *from); // Read from an unconnected socket. EXTERNC int minet_sendto (int fd, char *buf, int len, struct sockaddr_in *to); // Write to an unconnected socket. EXTERNC int minet_close (int sockfd); // Close a socket. #endif