Networking APIs
Socket API
The io-sock networking stack provides socket functions ported from FreeBSD as well as io-sock-specific ones.
The FreeBSD documentation provides reference and other information about socket functions. For example: https://docs.freebsd.org/en_US.ISO8859-1/books/developers-handbook/sockets-essential-functions.html.
The io-sock networking stack supports all the routines that application programmers would expect, including (but not limited to) the functions listed below. The FreeBSD 13.3 manual pages at https://www.freebsd.org/cgi/man.cgi are the best guide to their use:
accept() accept4() bind() bindresvport() bindresvport_sa() connect() dn_comp() dn_expand() endnetent() endnetgrent() endprotoent() endservent() ether_aton() ether_hostton() ether_line() ether_ntoa() ether_ntohost() feature_present() freeaddrinfo() freeifaddrs() freeifmaddrs() gai_strerror() getaddrinfo() getdomainname() getifaddrs() getifmaddrs() getnameinfo() getnetbyaddr() getnetbyname() getnetent() getnetgrent() getpeereid() getpeername() getprotobyname() getprotobyname_r() getprotobynumber() |
getprotobynumber_r() getprotoent() getprotoent_r() getservbyname_r() getservbyport() getservbyport_r() getservent() getservent_r() getsockname() getsockopt() htonl() htons() if_freenameindex() if_indextoname() if_nameindex() if_nametoindex() inet_addr() inet_aton() inet_net_ntop() inet_net_pton() inet_network() inet_ntoa() inet_ntoa_r() inet_ntop() inet_pton() inet6_opt_append() inet6_opt_find() inet6_opt_finish() inet6_opt_get_val() inet6_opt_init() inet6_opt_next() inet6_opt_set_val() inet6_rth_add() inet6_rth_getaddr() inet6_rth_init() inet6_rth_reverse() |
inet6_rth_segments() inet6_rth_space() innetgr() link_addr() link_ntoa() listen() nsdispatch() ntohl() ntohs() recv() recvfrom() recvmmsg() recvmsg() res_init() res_mkquery() res_query() res_querydomain() res_search() res_send() send() sendto() sendmmsg() sendmsg() setdomainname() setnetent() setnetgrent() setprotoent() setservent() setsockopt() shutdown() sockatmark() socket() sysctl() sysctlbynamefb() sysctlnametomib() sysctlnametomibfd() |
sysctlbynamefd(), sysctlnametomibfd()
The sysctlbynamefd() function is similar to sysctlbyname(), but you specify the descriptor of a socket you created earlier using socket(). Like systctl(), sysctlbyname() calls socket() to open a connection, gets or sets the information, and then closes the connection (using close()). Using sysctlbynamefd() allows you to avoid multiple calls to open and close a connection when you perform multiple sysctlbyname() calls. You can call socket(), pass fd to multiple sysctlfd() calls, and then close the connection. The connection is opened and closed only once.
#include <sys/param.h>
#include <sys/sysctl.h>
int sysctlbynamefd( const char *name,
void *oldp,
size_t *oldlenp,
void * newp,
size_t newlen,
int fd );
Similarly, the sysctlnametomibfd() function is a varition of sysctlnametomib() that specifies a descriptor of a socket.
#include <sys/types.h>
#include <sys/sysctl.h>
int sysctlnametomibfd ( const char * name,
int * mibp,
size_t * sizep,
int fd );
clearsockprefix(), setsockprefix()
The following functions were added with io-sock and are documented in the C Library Reference:
in6_addr structures
The io-sock networking stack ports the in6_addr structures from FreeBSD. For information on the IPv6 address that they correspond to, see the in6addr_* entry in the C Library Reference.
*_r() (reentrant) functions
The following socket functions have reentrant equivalents, indicated with the suffix _r:
- getprotoent()
- getprotobyname()
- getprotobynumber()
- getservent()
- getservbyname()
- getservbyport()
For example, getprotoent_r():
#include <netdb.h>
int getprotoent_r(struct protoent *pptr,
char *buffer,
size_t buflen,
struct protoent **result)
Instead of returning
a pointer to a statically allocated protoent structure as the function result,
these functions copy the structure into the location pointed to by pptr.
The buffer array is used to store the string fields pointed to by the returned protoent. (The non-reentrant functions allocate these strings in static storage.) The size of this array is specified in buflen. If buffer is too small, the call fails with the error ERANGE.
If the function call successfully obtains a protocol record, then *result is set pointing to pptr; otherwise, *result is set to NULL.
These functions return:- 0 on success, or -1 if an error occured.
- If the error is record not found (getprotobyname_r(), getprotobynumber_r()) or end of input (getprotoent_r()), result is set to NULL.
- ERANGE
- The buffer was too small. Try again with a larger buffer and buflen value.
Errors specific to io-sock
The io-sock socket functions ported from FreeBSD can generate errors that are not described in the FreeBSD documentation, have a different meaning than the one provided in that documentation, or have multiple meanings. Go to the FreeBSD documentation for other possible causes of these errors.
- EAFNOSUPPORT
- The io-sock networking manager isn't running, or io-sock was started with a prefix option value that is different from the SOCK environment variable. For more information, see the io-sock entry in the Utilities Reference.
- EBADMSG
-
There is a size mismatch in the source or destination buffers: not enough space in the destination or source buffer, not enough data sent to form a complete message, or too much data sent.
Files
The socket functions require that the following files are present:
For more information, go to the Utilities Reference.
Deprecated functions
The following table lists APIs that FreeBSD has deprecated and the functions that replace them:
Instead of: | Use: | FreeBSD manual pages |
---|---|---|
inet6_option_space, inet6_option_init, inet6_option_append, inet6_option_alloc, inet6_option_next, inet6_option_find | inet6_opt_init, inet6_opt_append, inet6_opt_finish, inet6_opt_set_val, inet6_opt_next, inet6_opt_find, inet6_opt_get_val | inet6_opt_init() |
inet6_rthdr_space, inet6_rthdr_init, inet6_rthdr_add, inet6_rthdr_lasthop, inet6_rthdr_reverse, inet6_rthdr_segments,inet6_rthdr_getaddr, inet6_rthdr_getflags | inet6_rth_space, inet6_rth_init, inet6_rth_add, inet6_rth_reverse, inet6_rth_segments, inet6_rth_getaddr | inet6_rthdr_space() |
endhostent(), gethostbyaddr(), gethostbyaddr_r(), gethostbyname(), gethostbyname_r(), gethostbyname2(), gethostbyname2_r(), gethostent(), gethostent_r() , getservbyname(), h_errno(), herror(), hstrerror(), sethostent | getaddrinfo(), getnameinfo() | getaddrinfo(), getnameinfo() |
The following APIs have been deprecated with no replacement:
- inet_lnaof()
- inet_makeaddr()
- inet_netof()
IPsec APIs
QNX OS provides the IPsec Policy Control Library (libipsec) to support APIs related to IPSec operation, including ipsec_dump_policy(), ipsec_get_policylen(), and ipsec_set_policy(), and ipsec_strerror().