TCPIP32.LIB
TCPIP32.LIB is a combined TCP/IP import library for OS/2, providing both the BSD socket API and the name resolution API in a single library backed by TCPIP32.DLL. It is distributed with IBM TCP/IP for OS/2 version 4.2 and later, and with the IBM OS/2 Developer's Toolkit for OS/2 Warp 4.52.
TCPIP32.LIB consolidates the functionality of the older SO32DLL.LIB + TCP32DLL.LIB pair into one import library, and adds several functions that are absent from both: socketpair, send_file, accept_and_recv, sysctl, gethostbyname2, inet_pton/inet_ntop, herror, hstrerror, sock_strerror, and an extended BIND 8-compatible resolver interface.
File size in the OS/2 Warp 4.52 Toolkit 4.5: 23,040 bytes (2000-10-16). Source DLL: TCPIP32.DLL.
Relationship to SO32DLL.LIB and TCP32DLL.LIB
| Library | DLL | Socket API | Resolver | Extended functions |
|---|---|---|---|---|
| SO32DLL.LIB + TCP32DLL.LIB | SO32DLL.DLL + TCP32DLL.DLL | Yes | Yes | No |
| TCPIP32.LIB (this file) | TCPIP32.DLL | Yes | Yes | Yes (see below) |
An application should use either TCPIP32.LIB or the SO32DLL.LIB+TCP32DLL.LIB pair. Linking all three together against the same program is not supported. TCPIP32.LIB is the preferred choice for applications targeting OS/2 Warp 4.2 and later.
Socket API
TCPIP32.LIB provides the complete BSD socket API. The function semantics are identical to SO32DLL.LIB; see that page for full parameter documentation. All functions are exported in the same three calling-convention forms (lowercase, UPPERCASEMSC, _lowercaseMSC) as the older libraries.
Lifecycle
socket, soclose, shutdown, soabort, so_cancel, sock_init
Server-side
bind, listen, accept
Client-side
connect
Addressing
getsockname, getpeername
Send and receive
send, recv, sendto, recvfrom,
sendmsg, recvmsg, readv, writev
Options and control
getsockopt, setsockopt, select, os2_select,
ioctl, os2_ioctl
Error handling
sock_errno, psock_errno, set_errno
Reentrant
Raccept, Rbind, Rconnect, Rlisten, Rgetsockname, Rgethostbyname
Miscellaneous
gethostid, getinetversion, addsockettolist, removesocketfromlist,
cleanupsockets, winsockcleanupsockets
Name Resolution API
TCPIP32.LIB provides the complete name resolution API equivalent to TCP32DLL.LIB. See that page for full parameter documentation.
Host lookups
gethostbyname, gethostbyaddr, gethostent, gethostname,
sethostent, endhostent
Network, protocol, service lookups
getnetbyaddr, getnetbyname, getnetent, setnetent, endnetent,
getprotobyname, getprotobynumber, getprotoent, setprotoent, endprotoent,
getservbyname, getservbyport, getservent, setservent, endservent
Address conversion
inet_addr, inet_ntoa, inet_lnaof, inet_makeaddr, inet_netof, inet_network
Byte order
htonl, htons, ntohl, ntohs
Time and error
gettimeofday, rexec, h_errno (via tcp_h_errno1)
Extended Functions
These functions are present in TCPIP32.LIB but absent from both SO32DLL.LIB and TCP32DLL.LIB.
socketpair
socketpair(domain, type, protocol, sv[2])- Creates a pair of connected sockets.
svis a two-element array filled with the two socket descriptors. Data written tosv[0]is readable fromsv[1]and vice versa — a bidirectional, in-process pipe over sockets. On OS/2,domainmust beAF_INET;AF_UNIXdomain sockets are not available. - Useful for: parent-child process communication, connecting two threads, or implementing a self-pipe for waking a blocked
select()call.
accept_and_recv
accept_and_recv(ls, cs, caddr, caddrlen, buf, buflen, flags, timeout)- A combined accept-and-first-receive call. Accepts an incoming connection and immediately waits for the first data packet, returning both the new socket descriptor and the initial data in a single call. Reduces round-trips for request-response protocols (HTTP, etc.) where the client sends immediately after connecting.
timeoutis astruct timevalspecifying how long to wait for the first data; NULL blocks indefinitely.
send_file
send_file(s, sf, flags)- Zero-copy file transmission. Sends the contents of an OS/2 file handle directly to a socket, bypassing the user-space buffer.
sfis astruct sf_parmsstructure specifying:header_data/header_length— optional header bytes to prepend (e.g. an HTTP response header)file_handle— an OS/2HFILEopened withDosOpenfile_size— total bytes to send from the file (0 = send entire file)file_offset— starting offset within the filetrailer_data/trailer_length— optional trailer bytes to append
- Returns the number of bytes sent. The kernel transfers data from the file's page cache directly to the network stack without copying through user space.
- This is the OS/2 equivalent of Linux
sendfile(2)and FreeBSDsendfile(2). It is the most efficient way to serve static files over HTTP on OS/2.
sysctl
sysctl(name, namelen, oldval, oldlenp, newval, newlen)- BSD
sysctl(3)interface for querying and setting kernel TCP/IP parameters at runtime.nameis an integer array identifying the parameter (e.g.{CTL_NET, PF_INET, IPPROTO_TCP, TCPCTL_MSSDFLT}). Passingnewval = NULLperforms a read-only query. - Example parameters accessible via
sysctlon OS/2: TCP MSS default, TCP keepalive interval, IP time-to-live default, UDP checksum setting, routing table entries. - The MIB name constants are defined in
sys\sysctl.handnetinet\tcp.h.
gethostbyname2
gethostbyname2(name, af)- Extended version of
gethostbynamethat takes an explicit address family parameteraf. Introduced in BIND 8 as a preparation step toward IPv6;gethostbyname(name)is equivalent togethostbyname2(name, AF_INET). On OS/2, onlyAF_INETis meaningful, but code using this function is more easily ported to dual-stack IPv4/IPv6 systems.
inet_aton
inet_aton(cp, inp)- Converts a dotted-decimal string to an
in_addrstructure. Returns 1 on success, 0 on failure. Preferred overinet_addr()becauseinet_addr()usesINADDR_NONE(0xFFFFFFFF) as its error sentinel, which is ambiguous since 255.255.255.255 is a valid broadcast address.
inet_ntop and inet_pton
inet_ntop(af, src, dst, size)- Converts a binary network address to a printable string. For
AF_INET, produces a dotted-decimal string identical toinet_ntoa()but thread-safe (writes into caller-supplieddstbuffer ofsizebytes). On OS/2, also acceptsAF_INET6to format IPv6 addresses as colon-separated hex groups ("2001:db8::1").
inet_pton(af, src, dst)- Converts a printable address string to binary. The inverse of
inet_ntop. Returns 1 on success, 0 if the string is not a valid address, −1 on error. Supports both dotted-decimal IPv4 and colon-hex IPv6 strings. - These two functions are the modern replacements for
inet_addr/inet_ntoa: they are thread-safe, they handle IPv6, andinet_ptonhas an unambiguous error return.
inet_net_ntop and inet_net_pton
inet_net_ntop(af, src, bits, dst, size)- Formats a network address with its prefix length as CIDR notation (e.g.
"192.168.1.0/24").bitsis the prefix length.
inet_net_pton(af, src, dst, size)- Parses a CIDR-notation network address string into binary form. Returns the prefix length on success, −1 on error.
Additional inet_* utilities
inet_neta(in, buf, size)- Formats a network address (without host bits) as a string, omitting trailing zero octets. Used in routing table display (e.g.
"10"instead of"10.0.0.0").
inet_nsap_ntoa(binlen, binary, ascii)/inet_nsap_addr(ascii, binary, maxlen)- Convert between binary and ASCII representations of NSAP (Network Service Access Point) addresses. Used by OSI networking diagnostics; rarely needed in standard TCP/IP applications.
Error text functions
herror(msg)- Prints
msg: error-text\nto stderr whereerror-textdescribes the currenth_errnovalue. The DNS/resolver equivalent ofperror().
hstrerror(err)- Returns a pointer to a string describing the given
h_errnoerror code. The DNS equivalent ofstrerror(). Values:"Host not found","Try again","Non-recoverable error","No address associated with name".
sock_strerror(err)- Returns a pointer to a string describing a socket error code (from
sock_errno()). The socket equivalent ofstrerror(). Useful for logging precise error messages without a manual table.
Extended DNS resolver (BIND 8 interface)
TCPIP32.LIB exports the BIND 8-compatible resolver interface under the double-underscore (__) prefix convention. These replace the single-underscore forms from TCP32DLL.LIB and add functions for DNS packet inspection, location records, and base64 encoding.
Core resolver:
__res_init, __res_query, __res_querydomain, __res_search,
__res_mkquery, __res_send, __res_close
Validation:
__res_dnok(dn) — checks that a domain name contains only legal characters.
__res_hnok(hn) — checks that a hostname is valid (no underscores, valid label lengths).
__res_mailok(addr) — validates a mail address domain.
__res_ownok(owner) — validates a DNS resource record owner name.
Name compression:
__dn_comp, __dn_expand, __dn_skipname, __dn_count_labels, dn_find
Response packet printing (debug / diagnostic):
These functions format DNS response packet fields as human-readable text. They write to a caller-supplied buffer or to stdout, and are primarily used by DNS diagnostic utilities such as nslookup and dig:
__p_query(msg)- Prints a complete DNS query/response packet in a human-readable format.
__fp_query(msg, file)- Like
__p_querybut writes to a given FILE stream.
__fp_nquery(msg, len, file)- Like
__fp_querybut with an explicit packet length (for truncated packets).
__fp_resstat(res, file)- Prints the current resolver state (
_resstructure contents) to a FILE stream.
__p_rr(rr, msg, file)- Prints a single DNS resource record.
__p_cdname(cp, msg, file)/__p_cdnname(cp, msg, len, file)- Print a compressed domain name from a packet.
__p_fqname(cp, msg, file)/__p_fqnname(cp, msg, len, file)- Print a fully-qualified domain name.
__p_class(class)- Returns the string name for a DNS class code (e.g.
"IN"forC_IN).
__p_type(type)- Returns the string name for a DNS record type code (e.g.
"A","MX","NS").
__p_option(option)- Returns the string name for a resolver option flag.
__p_time(value)- Formats a DNS TTL value as a human-readable time string.
__p_secstodate(secs)- Converts a seconds-since-epoch value to a date string for DNSSEC record display.
__p_class_syms,__p_type_syms- Exported symbol tables mapping class/type integers to name strings. Used internally by the
__p_*printing functions.
Symbolic value conversion:
__sym_ntop(sym, value, success)- Looks up a numeric value in a symbol table and returns its string name.
__sym_ston(sym, name, success)- Looks up a string name in a symbol table and returns its numeric value.
__sym_ntos(sym, value, success)- Similar to
__sym_ntopbut returns the short form of the name.
LOC record utilities:
__loc_aton(ascii, binary)- Parses a DNS LOC record (geographic location) from ASCII representation into binary.
__loc_ntoa(binary, ascii)- Formats a DNS LOC record from binary into ASCII.
Base64 utilities:
__b64_ntop(src, srclength, target, targsize)- Encodes binary data as base64. Used for encoding DNS KEY and SIG records (DNSSEC).
__b64_pton(src, target, targsize)- Decodes base64 text to binary.
Host alias resolution:
__hostalias(name)- Checks the HOSTALIASES environment variable file for a short alias that expands to a full hostname. Called internally by
__res_search.
Query matching:
__res_nameinquery(name, type, class, buf, eom)- Checks whether a given name/type/class combination appears in a DNS query packet's question section.
__res_queriesmatch(buf1, eom1, buf2, eom2)- Checks whether two DNS query packets ask the same question (for matching responses to requests).
__res_randomid()- Generates a random 16-bit DNS query ID. Used internally to avoid query ID collisions.
__res_isourserver(inp)- Returns 1 if the given address is one of the configured name servers.
Usage
TCPIP32.LIB replaces both SO32DLL.LIB and TCP32DLL.LIB. Do not link all three in the same application.
IBM VisualAge C++ / ILINK
icc -O2 -Gm -c myapp.c ilink /PM:VIO myapp.obj os2386.lib tcpip32.lib
OpenWatcom (wlink)
wcl386 -bt=os2 -mf -c myapp.c wlink system os2v2 file myapp.obj library os2386.lib library tcpip32.lib
EMX/GCC
gcc -Zomf -c myapp.c gcc -Zomf -o myapp.exe myapp.o os2386.lib tcpip32.lib
Include files
The same IBM TCP/IP SDK headers used for SO32DLL/TCP32DLL apply. Additional headers for the extended functions:
| Header | Additional contents for TCPIP32 extensions |
|---|---|
sys\socket.h |
struct sf_parms for send_file; socketpair prototype
|
arpa\inet.h |
inet_aton, inet_ntop, inet_pton, inet_net_ntop, inet_net_pton, inet_neta prototypes
|
resolv.h |
BIND 8 __res_* and __dn_* prototypes; __p_* diagnostic prototypes
|
sys\sysctl.h |
MIB name constants and sysctl prototype
|
netdb.h |
herror, hstrerror prototypes
|
Comparison with SO32DLL.LIB + TCP32DLL.LIB
| Feature | SO32DLL.LIB + TCP32DLL.LIB | TCPIP32.LIB |
|---|---|---|
| Number of import libraries | 2 (SO32DLL + TCP32DLL) | 1 |
| Source DLLs | SO32DLL.DLL + TCP32DLL.DLL | TCPIP32.DLL |
socketpair |
No | Yes |
send_file (zero-copy) |
No | Yes |
accept_and_recv |
No | Yes |
sysctl |
No | Yes |
gethostbyname2 |
No | Yes |
inet_pton / inet_ntop |
No | Yes |
inet_aton |
No | Yes |
herror / hstrerror |
No | Yes |
sock_strerror |
No | Yes |
BIND 8 resolver (__res_*, __dn_*) |
BIND 4 (res_*, dn_*) |
BIND 8 (__res_*, __dn_*)
|
DNS packet printing (__p_*, __fp_*) |
No | Yes |
Base64 utilities (__b64_*) |
No | Yes |
LOC record utilities (__loc_*) |
No | Yes |
| OS/2 version required | Warp 3+ | Warp 4.2+ |
Version History
| Version | IBM TCP/IP release | Date | Notes |
|---|---|---|---|
| 1.0 | IBM TCP/IP for OS/2 4.2 | ~1999 | Initial release. Combined SO32DLL+TCP32DLL functionality into TCPIP32.DLL. Added socketpair, send_file, BIND 8 resolver.
|
| 1.1 | IBM TCP/IP for OS/2 4.21 / OS/2 Warp 4.52 | 2000 | Added accept_and_recv, sysctl, inet_ntop/inet_pton, LOC and base64 utilities for DNSSEC groundwork. Final IBM release. File size: 23,040 bytes (2000-10-16).
|