HPlogo HP 9000 Networking: BSD Sockets Interface Programmer's Guide > Chapter 8 Programming Hints

Portability Issues

» 

Technical documentation

Complete book in PDF

 » Table of Contents

 » Glossary

 » Index

This section describes implementation differences between 4.3 BSD Sockets and HP-UX IPC. It contains porting issues for:

  • IPC functions and library calls.

  • Other functions and library calls typically used by IPC programs.

Because HP-UX IPC is based on 4.3 BSD Sockets (it is a subset of 4.3 BSD), programs should port easily between HP-UX and 4.3 BSD systems. If you need to have portable applications, keep the information described in this appendix in mind when you write your IPC programs.

Porting Issues for IPC Functions and Library Calls

The following is a list of differences in IPC functions and library calls to watch out for if you want to port your IPC applications between HP-UX and 4.3 BSD systems.

Shutdown

When shutdown has been used on a datagram socket on an HP-UX system, the local port number bound to that socket remains unavailable for use until that socket has been destroyed by close.

Some other systems free that port number for use immediately after the shutdown. In general, sockets should be destroyed by close (or by terminating the process) when they are no longer needed. This allows you to avoid unnecessary delay in deallocating local port numbers.

Address Conversion Functions for DEC VAX Hosts

The functions htonl, htons, ntonl and ntons are not required on HP-UX systems. They are included for porting to a DEC VAX host. You can use these functions in your HP-UX programs for portability; they are defined as null macros on HP-UX systems, and are found in netinet/in.h.

FIONREAD Return Values

For HP-UX systems, the FIONREAD ioctl request on a datagram socket returns a number that may be larger than the number of bytes actually readable. Previously, HP-UX systems returned the maximum number of bytes that a subsequent recv would be able to return.

Listen's Backlog Parameter

HP-UX sets the actual size of the queue for pending connections to 3/2 * B+1, where B is the backlog value specified in the listen() function. This may change in future releases, but it will not be smaller than the backlog value.

Pending Connections

There is no guarantee which pending connection on a listening socket is returned by accept. HP-UX systems return the newest pending connection. Applications should be written such that they do not depend upon connections being returned by accept on a first-come, first-served basis.

Porting Issues for Other Functions and Library Calls Typically Used by IPC

The following is a list of differences in functions and library calls to watch out for when you port your IPC applications between HP-UX and 4.3 BSD systems.

Ioctl and Fcntl Calls

4.3 BSD terminal ioctl calls are incompatible with the HP-UX implementation. These calls are typically used in virtual terminal applications. The HP-UX implementation uses UNIX System V compatible calls.

Pty Location

Look for the pty masters in /dev/ptym/ptyp? and for the pty slaves in /dev/pty/ttyp?. An alternative location to check is /dev.

Utmp

The 4.3 BSD /etc/utmp file format is incompatible with the HP-UX implementation. The HP-UX implementation uses UNIX System V compatible calls. Refer to the utmp(4) man page for details.

Library Equivalencies

Certain commonly used library calls in 4.3 BSD are not present in HP-UX systems, but they do have HP-UX equivalents. To make code porting easier, use the following equivalent library calls. You can do this by putting them in an include file, or by adding the define statements (listed in the following table) to your code.

Table 8-4 Definition of Library Equivalents

Define Statement

4.3 BSD Library

HP-UX Library

#define

index(a,b)

strchr(a,b)

#define

rindex(a,b)

strrchr(a,b)

#define

bcmp(a,b,c)

memcmp(a,b,c)

#define

bcopy(a,b,c)

memcpy(b,a,c)

#define

bzero(a,b)

memset(a,0,b)

#define

getwd(a)

getcwd(a,MAXPATHLEN)

 

NOTE: Include string.h before using strchr and strrchr. Include sys/param.h before using getcwd.

Signal Calls

Normal HP-UX signal calls are different from 4.3 BSD signals. See the sigvector(2) man page for information on signal implementation.

Sprintf Return Value

For 4.3 BSD, sprintf returns a pointer to a string. For HP-UX systems, sprintf returns a count of the number of characters in the buffer.

© 1997 Hewlett-Packard Development Company, L.P.