#include <libsimpleio/libipv4.h> void IPV4_resolve(char *name, int32_t *addr, int32_t *error); void IPV4_ntoa(int32_t addr, char *dst, int32_t dstsize, int32_t *error); void TCP4_connect(int32_t addr, int32_t port, int32_t *fd, int32_t *error); void TCP4_accept(int32_t addr, int32_t port, int32_t *fd, int32_t *error); void TCP4_server(int32_t addr, int32_t port, int32_t *fd, int32_t *error); void TCP4_close(int32_t fd, int32_t *error); void TCP4_send(int32_t fd, void *buf, int32_t bufsize, int32_t *count, int32_t *error); void TCP4_receive(int32_t fd, void *buf, int32_t bufsize, int32_t *count, int32_t *error); void UDP4_open(int32_t addr, int32_t port, int32_t *fd, int32_t *error); void UDP4_close(int32_t fd, int32_t *error); void UDP4_send(int32_t fd, int32_t addr, int32_t port, void *buf, int32_t bufsize, int32_t flags, int32_t *count, int32_t *error); void UDP4_receive(int32_t fd, int32_t *addr, int32_t *port, void *buf, int32_t bufsize, int32_t flags, int32_t *count, int32_t *error);Link with -lsimpleio.
IPV4_resolve() attempts to resolve an IPv4 address string passed in *name (containing a domain name, a local host name like localhost or a dotted decimal address like 1.2.3.4). Upon success, the 32-bit IPv4 address will be returned in *addr.
IPV4_ntoa() converts an IPv4 address to a dotted decimal address string. The address of the destination buffer is passed in *dst and its size, which must be at least 16 bytes, is passed in dstsize. Upon success, the dotted decimal address string will be returned in *dst.
TCP4_connect() attempts to connect to a IPv4 TCP server. The 32-bit IPv4 address is passed in addr and the 16-bit TCP port number is passed in port. Upon successful connection, a stream file descriptor will be returned in *fd.
TCP4_accept() waits for an incoming connection request from a IPv4 TCP client. Either INADDR_ANY may be passed in addr to bind to (i.e. listen on) all network interfaces, or the 32-bit IPV4 address of a particular network interface may be passed to bind to only that interface. The 16-bit TCP port number is passed in port. Upon successful connection, a stream file descriptor will be returned in *fd.
TCP4_server() operates like TCP4_accept() except that upon successful connection, the original server process forks to create a new and separate connection handler process. The server process continues to listen for more connection requests, without returning from TCP4_server(), while in the new connection handler process, TCP4_server() does return, with a stream file descriptor for the new connection returned in *fd.
TCP4_close() closes a previously opened IPv4 TCP stream. The stream file descriptor is passed in fd.
TCP4_send() sends data to a IPv4 TCP stream. The stream file descriptor is passed in fd. The transmit buffer address is passed in buf and its size is passed in bufsize. Upon success, the number of bytes actually sent will be returned in *count.
TCP4_receive() receives data from a IPv4 TCP stream. The stream file descriptor is passed in fd. The receive buffer address is passed in buf and its size is passed in bufsize. Upon success, the number of bytes actually received will be returned in *count.
UDP4_open() opens a UDP datagram socket. The IP address of the network interface to bind the socket to is passed in the addr parameter. A value of zero or INADDR_ANY indicates the socket should bind to all network interfaces. The UDP port number is passed in the port parameter. A value of zero indicates the kernel should automatically select a port number. Upon successful completion, a UDP socket file descriptor will be returned in *fd.
UDP4_close() closes a previously opened UDP socket. The UDP socket file descriptor is passed in fd.
UDP4_send() sends a UDP datagram. The UDP socket file descriptor is passed in fd. The IPv4 address of the destination network node is passed in addr. The UDP port number of the destination network node is passed in port. The UDP datagram is passed in *buf and its size in bytes is passed in bufsize. Flags for the sendto() Linux system call are passed in flags. The number of bytes sent will be returned in *count.
UDP4_receive() receives a UDP datagram. The UDP socket file descriptor is passed in fd. The IPv4 address of the source network node will be returned in *addr. The UDP port number of the source network node will be returned in *port. The UDP datagram will be returned in *buf. The size of the datagram buffer will be passed in bufsize. Flags for the recvfrom() Linux system call are passed in flags. The number of bytes received will be returned in *count.