libporty - the net package

This package provides low level networking calls for creating sockets and network connections, synchronous dns resolving and polling for socket activity.

The networking and communication model of libporty is simple: sockets are all equivalent and any stream I/O is a socket (see net_async package for more details on how stdio or background processes are converted to sockets). The user may create multiple sockets and a poll call is provided and to wait for activity on one or more sockets. The user application is single threaded asynchronous normally.

Sockets are of type P_net_socket. The caller should not rely on this type to be an integer. A macro P_NET_INVALID_SOCKET is defined; if a socket is == P_NET_INVALID_SOCKET, the socket is invalid (or unused).

Before using the network layer, the application must call P_net_init(). Before exiting, P_net_uninit() shall be called.

libporty/net/network.h

API for the core functionality is implemented in network.h (and in turn in os_dep.h).
call level summary
P_net_init low initialize network layer
P_net_uninit low uninitialize network layer
P_socket (internal) create a new socket - note: the application should not use this call directly.
P_net_close low close a socket
P_poll low poll for activity on a set of sockets
P_net_set_nonblocking low set an existing socket non-blocking
P_net_set_blocking low set an existing socket blocking
P_net_enable_broadcast low enable broadcast messages if the underlying protocol allows (for example on UDP)
P_net_shutdown low close a full-duplex socket in one or both directions
The following enum constants are used with some of the calls:
enum level summary
P_net_err low error code (typically used as return value)
P_net_nonblock_t low controls whether sockets operations should be non-blocking, for some of the calls
P_net_broadcast_t low controls whether sockets shold allow broadcasting

libporty/net/local.h

Libporty components often communicate with eachother over local sockets. This component can create a local socket pair, which is an anonymous socket on UNIX and a local network (usully TCP) connection on platforms that do not support that.
call level summary
P_net_local_socket low create a new local socket pair

libporty/net/dns4.h

Synchronous (blocking) dns lookups for TCP/IP v4. Terminology: name is a textual hostname; addr is an IP address as text and IP is binary IP address represented as a 32-bit unsigned long int.
call level summary
P_dns4_name_to_IP low convert hostname to IP address
P_dns4_IP_to_name low convert IP address to hostname
P_dns4_get_my_name low returns the hostname of the host system
P_dns4_get_my_IP low returns the primary IP address of the host system
P_dns4_is_addr low checks if a string contains a valid-looking IP address (non-blocking)
P_dns4_IP_to_addr low converts an IP to string address (non-blocking)
P_dns4_addr_to_IP low converts a string address to IP (non-blocking)

libporty/net/tcp4.h

Simplified (and portable) API for TCP/IPv4. The basic features of listening for incoming connections, connect to remote host are implemented.
call level summary
P_tcp4_connect low connect to remote server
P_tcp4_listen low listen for incoming connections
P_tcp4_accept low accept next pending icoming connection

libporty/net/udp4.h

Simplified (and portable) API for UDP/IPv4.
call level summary
P_udp4_connect low "connect" to remote server
P_udp4_listen low listen for incoming data
P_udp4_recvfrom low read packet from a listening socket and also store source IP/port.