Consulting djbware Publications


State-of-the-art C routines provided as easy-to-use library for Internet services.

Scope: What are the fehQlibs?

The software of Dan Bernstein (qmail, ucspi-tcp, djbdns) includes supplementary C routines which obsoletes the usage of C's STDIO lib while replacing those by some safer implementations, in particular for string handling.

All this material is now public domain and the fehQlibs provide a basic framework for byte, string, I/O, socket, and IPv4/IPv6 handling in addition with the constant database cdb together with dnsstub resolver routines for Internet services applying the same or an even enhanced API.

The approach includes two main archives

simply to be linked (statically) with some IP applications without the hustle to care about the implemtation basics, header files, and potential bugs in here. Applications can focus on their duty and don't need to re-implement the basics.

The fehQlibs don't include any application routines but rather can be compiled and installed on most Unix system; serving as library only. Different from Dan Bernstein's implementation is the IPv6 conformance throughout and the error/log message interface.

History: Some background

Dan Bernstein used a series of own developed C routines as a replacement of the buggy and occassionally bloated C-library. Additional programs were included, providing services for a Constant Database (cdb), IPv4 address parsing and manipulation, IPv4 sockets and a DNS stub resolver.

These programs are kept stable and functioning over several software products Dan released over the years. However, some changes did occure, namely the use of buffer instead of substdio providing some better abstraction.

Felix von Leitner (and probably many others) used those routines as base for own releases, now put under the GNU license scheme (libowfat, djblib) and extending it's functionality significantly while including IPv6 support.

Kai Peter published an own djblib clone qlibs which was the starting point of fehQlibs. Given my previous experiences with Dan's routines, my objectives are to provide a clean socket interface for IPv4/IPv6 without the often needed case decisions. In addition, the dnsstub resolver has been upgraded to support IPv6 Link-local addresses (LLU) together with all the other IPv6 routines; allowing an additional interface-index to be included.

Implementation: The details

The fehQlibs - though functionally complete - are in particular suited for devices with little resources only, IoT devices in particular. On the other hand, they perform extremely well for larger projects.

The following is the exhaustive list of '*.c' routines to be compiled provided by scope:

Scope C routines
Storage alloc.c, stralloc.c
Byte handling/ manipulation byte.c, uint16p.c, uint32p.c, uint64p.c, uint128p.c
String handling/ manipulation case.c, scan.c, str.c, fmt.c
Input/output handling buffer.c, fd.c, getln.c, getoptb.c, open.c, seek.c, readclose.c
IP address handling/ manipulation ip4.c, ip6.c
Socket routines socket_bind.c, socket_connect.c socket_if.c socket_info.c socket_recv.c socket_send.c, socket_setup.c, socket_tcp.c socket_udp.c
Network communication timeout.c, timoutconn.c
Interprocess communication iopause.c, lock.c ndelay.c pathexec.c, sig,c, wait.c
Constant Database cdbmake.c, cdbread.c
Time routines tai.c, taia.c
Logging errstr.c, logmsg.c
DNS stub routines dns_ip.c, dns_cname.c, dns_name.c, dns_txt.c, dns_mx.c
DNS low level routines dns_dfd.c, dns_domain.c, dns_dtda.c, dns_ipq.c, dns_nd.c, dns_packet.c, dns_random.c, dns_resolve.c, dns_rcip.c, dns_rcrw.c, dns_sortip.c, dns_transmit.c
System/user interaction prot.c


Currently, there isn't much documentation about fehQlibs except for the embedded one:

Man pages (referencing the current version of fehQlibs):

alloc buffer byte case cdbmake
cdbread dns dnsstub env error
fd fmt getln getoptb iopause
ip4 ip6 logmsg pathexec scan
socket_bind socket_connect socket_if socket_info socket_recv
socket_send socket_setup socket_tcp socket_udp stralloc
taia timeout timeoutconn wait


You may want to read my (little outdated) presentions:

Download & Installation


Version & Download Description Verification Doxygen
fehQlibs-12c fehQlibs with enhanced/changed DNS stub resolver suited for s/qmail (regression tested; done) MD5 (fehQlibs-12c.tgz) = 3b65cf5f091bec0e402b22272d05eeab
Build: 20190802
fehQlibs-10 Previous release of fehQlibs (10) MD5 (fehQlibs-10.tgz) = 75bc13ca4a275c72c921b9485688c77f
Build: 20181214


Installation is pretty easy:

That's it! The fehQlibs are a library. No executables are installed!

Usage with my routines (ucspi-tcp6, ucspi-ssl, djbdnscurve6)

Once you have downloaded and installed the fehQlibs, I expect those to be symlinked to /usr/local/qlibs.

However, if you provide the fehQlibs in a different directory, customize the configuration file conf-qlibs to comply with your settings.

General usage

Using fehQlibs requires just two steps:

Assuming your source code calls any of the routines

  1. include the location of the header files while calling the compiler; typically I use: cc -O2 -Wall -I/usr/local/qlibs/include
  2. tell the linker to use the qlibs and potentially dnsresolv libraries: cc -s -L/usr/local/qlibs -lqlibs -ldnsresolv

In case, you have projects based on Dan's strerr messages you need to include those as source code.


fehQlibs are known to install well and work under Linux (32/64 bit) on x86, FreeBSD, OmniOs, RasPi (Raspbian/FreeBSD 12), MacOS X (x86, PPC).

Errata & Changelog

Version Changes
fehQlbis-12(c) Revised negative return codes for dnsstub resolver routines.
fehQlibs-12(a) The DNS stub resolver routines return now the number of answers received.
Minor cleanups and finalizations.
fehQlibs-10 Improved handling of poll and select calls while using their return codes in addition.
Added functions socket_dualstack and socket_nodualstack (providing better compatibility for OS which use socket option IPV6_V6ONLY).
For some backgrund on poll and IPV6_V6ONLY check
(a) Marek's (totally not insane) idea of the day
(b) Re: Disabling IPV6_V6ONLY a bad idea?

Added the 'shared object' (PIC) and libraries upon generation.

Attached LICENSE and CHANGELOG file.