xopen_networking.7 (2010 09)

x
xopen_networking(7) xopen_networking(7)
Note if the C library is also specified in the link line, the
Xnet library has to be specified before the
C
library. Otherwise, X/Open Sockets calls would have been resolved to BSD Sockets functions in the
C
library instead of X/Open Sockets functions in the
Xnet library.
Method B) Alternative Method
HP-UX provides two styles of Sockets API:
default BSD Sockets
X/Open Sockets
These two styles of Sockets API have the same function names but they have differences in semantics and
argument types. For example, the optlen field in X/Open
getsockopt() is size_t type, while BSD
getsockopt() is int type. In 64 bit mode,
size_t is 64 bit and int is still 32 bit.
Linking objects compiled to X/Open Sockets specification and objects compiled to BSD Sockets
specification in the same program using the linkage method in method A would erroneously resolve BSD
Sockets calls to X/Open Sockets functions in the
Xnet library. As a result, the program may result in
application core dumps or unexpected Socket errors when it is run. These symptoms commonly occur
when BSD Sockets
accept(), getpeername()
, getsockname()
, getsockopt(), recvfrom(),
sendmsg(), and recvmsg() are called.
For such mixed program configuration, the compilation and linkage methods described below in Compila-
tion should be used.
Compilation
Define
_HPUX_ALT_XOPEN_SOCKET_API
, in addition to either defining _XOPEN_SOURCE=600
in
UNIX 03 or _XOPEN_SOURCE
and _XOPEN_SOURCE_EXTENDED in UNIX 95.
For example to compile a 64-bit X/Open Sockets object and a 64-bit BSD Sockets object using
HP ANSI
Compiler:
UNIX 03
c99 +DD64 -D_XOPEN_SOURCE=600 -D_HPUX_ALT_XOPEN_SOCKET_API -c main.c -o
main.o
UNIX 95
c89 +DD64 -D_XOPEN_SOURCE -D_XOPEN_SOURCE_EXTENDED
-D_HPUX_ALT_XOPEN_SOCKET_API -c main.c -o main.o
BSD Sockets
cc -Ae +DD64 -c routines.c -o routines.o
With this method, X/Open Sockets calls are remapped by the static Sockets functions in <sys/socket.h> to
an alternative set of X/Open Sockets functions in C library. This alternative set has a prefix
_xpg_ in its
function names, for example,
_xpg_getsockopt()
.
Because the alternative set has different function names, X/Open Sockets calls are not confused with BSD
Sockets calls at link time.
Other than the naming difference, this alternative set is identical to the X/Open Sockets functions in Xnet
library. Other than adding an additional macro,
_HPUX_ALT_XOPEN_SOCKET_API, this compilation
method is compliant to X/Open specifications.
Linkage
Link with C library instead of Xnet library. Xnet library should not be included in the application link
line.
For example:
ld main.o routines.o -lc -o prog
Because Xnet library is not in the link line, BSD Sockets calls are not erroneously resolved to X/Open
Sockets functions in Xnet library.
FUTURE DIRECTION
Method B might become the default method in a future release. At that time,
_HPUX_ALT_XOPEN_SOCKET_API would be defined by default.
2 Hewlett-Packard Company 2 HP-UX 11i Version 3: September 2010