.\" man page for Munts Technologies Linux Simple I/O Library .\" .\" Copyright (C)2016-2023, Philip Munts dba Munts Technologies. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions are met: .\" .\" * Redistributions of source code must retain the above copyright notice, .\" this list of conditions and the following disclaimer. .\" .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" .\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE .\" ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE .\" LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" .TH libipv4 2 "21 December 2018" "version 1" "Linux Simple I/O Library" .SH NAME .B libipv4 \-\- Linux Simple I/O Library: IPv4 TCP Module .SH SYNOPSIS .nf .B #include .BI "void IPV4_resolve(char *" name ", int32_t *" addr ", int32_t *" error ");" .BI "void IPV4_ntoa(int32_t " addr ", char *" dst ", int32_t " dstsize ", int32_t *" error ");" .BI "void TCP4_connect(int32_t " addr ", int32_t " port ", int32_t *" fd ", int32_t *" error ");" .BI "void TCP4_accept(int32_t " addr ", int32_t " port ", int32_t *" fd ", int32_t *" error ");" .BI "void TCP4_server(int32_t " addr ", int32_t " port ", int32_t *" fd ", int32_t *" error ");" .BI "void TCP4_close(int32_t " fd ", int32_t *" error ");" .BI "void TCP4_send(int32_t " fd ", void *" buf ", int32_t " bufsize ", int32_t *" count "," .BI " int32_t *" error ");" .BI "void TCP4_receive(int32_t " fd ", void *" buf ", int32_t " bufsize ", int32_t *" count "," .BI " int32_t *" error ");" .BI "void UDP4_open(int32_t " addr ", int32_t " port ", int32_t *" fd ", int32_t *" error ");" .BI "void UDP4_close(int32_t " fd ", int32_t *" error ");" .BI "void UDP4_send(int32_t " fd ", int32_t " addr ", int32_t " port ", void *" buf "," .BI " int32_t " bufsize ", int32_t " flags ", int32_t *" count ", int32_t *" error ");" .BI "void UDP4_receive(int32_t " fd ", int32_t *" addr ", int32_t *" port ", void *" buf "," .BI " int32_t " bufsize ", int32_t " flags ", int32_t *" count ", int32_t *" error ");" .fi Link with .BR -lsimpleio . .SH DESCRIPTION .nh All functions return either .B 0 (upon success) or an .B errno value (upon failure) in .IR *error . .PP .B IPV4_resolve() attempts to resolve an IPv4 address string passed in .IR *name (containing a domain name, a local host name like .B localhost or a dotted decimal address like .BR 1.2.3.4 ). Upon success, the 32-bit IPv4 address will be returned in .IR *addr . .PP .B IPV4_ntoa() converts an IPv4 address to a dotted decimal address string. The address of the destination buffer is passed in .IR *dst and its size, which must be at least 16 bytes, is passed in .IR dstsize . Upon success, the dotted decimal address string will be returned in .IR *dst . .PP .B TCP4_connect() attempts to connect to a IPv4 TCP server. The 32-bit IPv4 address is passed in .IR addr and the 16-bit TCP port number is passed in .IR port . Upon successful connection, a stream file descriptor will be returned in .IR *fd . .PP .B TCP4_accept() waits for an incoming connection request from a IPv4 TCP client. Either .B INADDR_ANY may be passed in .IR 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 .IR port . Upon successful connection, a stream file descriptor will be returned in .IR *fd . .PP .B TCP4_server() operates like .B 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 .B TCP4_server(), while in the new connection handler process, .B TCP4_server() does return, with a stream file descriptor for the new connection returned in .IR *fd . .PP .B TCP4_close() closes a previously opened IPv4 TCP stream. The stream file descriptor is passed in .IR fd . .PP .B TCP4_send() sends data to a IPv4 TCP stream. The stream file descriptor is passed in .IR fd . The transmit buffer address is passed in .IR buf " and" its size is passed in .IR bufsize . Upon success, the number of bytes actually sent will be returned in .IR *count . .PP .B TCP4_receive() receives data from a IPv4 TCP stream. The stream file descriptor is passed in .IR fd . The receive buffer address is passed in .IR buf " and" its size is passed in .IR bufsize . Upon success, the number of bytes actually received will be returned in .IR *count . .PP .B UDP4_open() opens a UDP datagram socket. The IP address of the network interface to bind the socket to is passed in the .IR addr parameter. A value of zero or .B INADDR_ANY indicates the socket should bind to all network interfaces. The UDP port number is passed in the .IR 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 .IR *fd . .PP .B UDP4_close() closes a previously opened UDP socket. The UDP socket file descriptor is passed in .IR fd . .PP .B UDP4_send() sends a UDP datagram. The UDP socket file descriptor is passed in .IR fd . The IPv4 address of the destination network node is passed in .IR addr . The UDP port number of the destination network node is passed in .IR port . The UDP datagram is passed in .IR *buf and its size in bytes is passed in .IR bufsize . Flags for the .B sendto() Linux system call are passed in .IR flags . The number of bytes sent will be returned in .IR *count . .PP .B UDP4_receive() receives a UDP datagram. The UDP socket file descriptor is passed in .IR fd . The IPv4 address of the source network node will be returned in .IR *addr . The UDP port number of the source network node will be returned in .IR *port . The UDP datagram will be returned in .IR *buf . The size of the datagram buffer will be passed in .IR bufsize . Flags for the .B recvfrom() Linux system call are passed in .IR flags . The number of bytes received will be returned in .IR *count . .SH SEE ALSO .BR libsimpleio "(2), " libadc "(2), " libdac "(2), " libevent "(2), " libgpio "(2)," .br .BR libhidraw "(2), " libi2c "(2), " liblinux "(2), " liblinx "(2), " libpwm "(2)," .br .BR libserial "(2), " libspi "(2), " libstream "(2), " libwatchdog "(2)" .SH AUTHOR Philip Munts dba Munts Technologies.