Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ BSD(3) — AIX/RT 2.2.1

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

sockets library

descriptions of individual BSD

descriptions of individual BSD

BSD 4.3 library

Purpose

     Describes the 4.3BSD functions provided by AIX.

Library

     Berkeley Library (libbsd.a)

Description

     This section provides a list of 4.3BSD routines supported
     in AIX  and information  to help  application programmers
     port 4.3BSD programs to AIX.   Some of these routines can
     be found  in libc.a, some  in libsock.a, and most  of the
     rest in  libbsd.a.  The location and  full description of
     each of  the 4.3BSD routines  can be found in  the appro-
     priate alphabetical location in this chapter.

     Even  if you  are familiar  with 4.3BSD  programming, you
     should read  this entire section before  porting existing
     programs or  writing new  AIX programs  that use  BSD 4.3
     library functions.  Once you  have read this section, you
     can refer  back to specific  discussions or to  the indi-
     vidual routine descriptions as needed.

BSD 4.3 LIBRARY ROUTINES

     The  following table  lists the  4.3BSD library  routines
     that are available in AIX  and indicates both the library
     where the  routine is located  and the page in  this book
     where further information can be found.

+-----------------------------------------+-----------------+-----------+
| Subroutine Name                         | library Name    | Page No.  |
+-----------------------------------------+-----------------+-----------+
| accept                                  |    libsock.a    |    3-6    |
+-----------------------------------------+-----------------+-----------+
| alphasort                               |    libbsd.a     |    3-8    |
+-----------------------------------------+-----------------+-----------+
| bcopy                                   |    libc.a       |    3-299  |
+-----------------------------------------+-----------------+-----------+
| bind                                    |    libsock.a    |    3-11   |
+-----------------------------------------+-----------------+-----------+
| bstring:  bcmp, bzero, ffs              |    libbsd.a     |    3-29   |
+-----------------------------------------+-----------------+-----------+
| connect                                 |    libsock.a    |    3-58   |
+-----------------------------------------+-----------------+-----------+
| copysign                                |    libm.a       |    3-63   |
+-----------------------------------------+-----------------+-----------+
| directory:  closedir, opendir, readdir, |    libbsd.a     |    3-91   |
| rewinddir, telldir, seekdir             |                 |           |
+-----------------------------------------+-----------------+-----------+
| dup2                                    |    libbsd.a     |    3-142  |
+-----------------------------------------+-----------------+-----------+
| fsync                                   |    libc.a       |    2-71   |
+-----------------------------------------+-----------------+-----------+
| ftruncate                               |    libc.a       |    2-73   |
+-----------------------------------------+-----------------+-----------+
| getdtablesize                           |    libbsd.a     |    3-226  |
+-----------------------------------------+-----------------+-----------+
| getgroups                               |    libc.a       |    2-81   |
+-----------------------------------------+-----------------+-----------+
| gethostbyaddr,           gethostbyname, |    libsock.a    |    3-231  |
| sethostent, endhostent                  |                 |           |
+-----------------------------------------+-----------------+-----------+
| gethostid, sethostid                    |    libsock.a    |    3-234  |
+-----------------------------------------+-----------------+-----------+
| gethostname, sethostname                |    libsock.a    |    3-236  |
+-----------------------------------------+-----------------+-----------+
| getitimer, setitimer                    |    libbsd.a     |    3-238  |
+-----------------------------------------+-----------------+-----------+
| getnetent,  getnetbyaddr, getnetbyname, |    libsock.a    |    3-241  |
| setnetent, endnetent                    |                 |           |
+-----------------------------------------+-----------------+-----------+
| getpeername                             |    libsock.a    |    3-247  |
+-----------------------------------------+-----------------+-----------+
| getprotoent,          getprotobynumber, |    libsock.a    |    3-249  |
| getprotobyname,            setprotoent, |                 |           |
| endprotoent                             |                 |           |
+-----------------------------------------+-----------------+-----------+
| getservent,              getservbyname, |    libsock.a    |    3-255  |
| getservbyport, setservent, endservent   |                 |           |
+-----------------------------------------+-----------------+-----------+
| getsockname                             |    libsock.a    |    3-257  |
+-----------------------------------------+-----------------+-----------+
| getsockopt, setsockopt                  |    libsock.a    |    3-259  |
+-----------------------------------------+-----------------+-----------+
| gettimeofday                            |    libbsd.a     |    3-262  |
+-----------------------------------------+-----------------+-----------+
| getwd                                   |    libbsd.a     |    3-268  |
+-----------------------------------------+-----------------+-----------+

+-----------------------------------------+-----------------+-----------+
| Subroutine Name                         | library Name    | Page No.  |
+-----------------------------------------+-----------------+-----------+
| htonl, htons, ntohl, ntohs              |    libsock.a    |    3-271  |
+-----------------------------------------+-----------------+-----------+
| index, rindex                           |    libbsd.a     |    3-273  |
+-----------------------------------------+-----------------+-----------+
| inet_addr,   inet_network,   inet_ntoa, |    libsock.a    |    3-274  |
| inet_makeaddr, inet_lnaof, inet_netof   |                 |           |
+-----------------------------------------+-----------------+-----------+
| initgroups                              |    libc.a       |    3-276  |
+-----------------------------------------+-----------------+-----------+
| insque, remque                          |    libbsd.a     |    3-277  |
+-----------------------------------------+-----------------+-----------+
| killpg                                  |    libbsd.a     |    3-278  |
+-----------------------------------------+-----------------+-----------+
| listen                                  |    libsock.a    |    3-281  |
+-----------------------------------------+-----------------+-----------+
| mkdir                                   |    libc.a       |    2-104  |
+-----------------------------------------+-----------------+-----------+
| random, srandom, initstate, setstate    |    libbsd.a     |    3-371  |
+-----------------------------------------+-----------------+-----------+
| rcmd, rresvport, ruserok                |    libsock.a    |    3-373  |
+-----------------------------------------+-----------------+-----------+
| readv                                   |    libbsd.a     |        -- |
|                                         |                 | Heading   |
|                                         |                 | id        |
|                                         |                 | 'readv'   |
|                                         |                 | unknown   |
|                                         |                 | --        |
+-----------------------------------------+-----------------+-----------+
| reboot                                  |    libc.a       |    2-158  |
+-----------------------------------------+-----------------+-----------+
| recv, recvfrom, recvmsg                 |    libsock.a    |    3-376  |
+-----------------------------------------+-----------------+-----------+
| rename                                  |    libc.a       |    2-160  |
+-----------------------------------------+-----------------+-----------+
| resolver:     res_mkquery,    res_send, |    libsock.a    |    3-386  |
| res_init, dn_comp, dn_expand, getshort, |                 |           |
| getlong, putshort, putlong              |                 |           |
+-----------------------------------------+-----------------+-----------+
| rexec                                   |    libsock.a    |    3-391  |
+-----------------------------------------+-----------------+-----------+
| rmdir                                   |    libc.a       |    2-163  |
+-----------------------------------------+-----------------+-----------+
| scandir                                 |    libbsd.a     |    3-398  |
+-----------------------------------------+-----------------+-----------+
| select                                  |    libc.a       |    2-165  |
+-----------------------------------------+-----------------+-----------+
| send, sendto, sendmsg                   |    libsock.a    |    3-400  |
+-----------------------------------------+-----------------+-----------+
| setbuffer, setlinebuf                   |    libbsd.a     |    3-404  |
+-----------------------------------------+-----------------+-----------+
| setgroups                               |    libc.a       |    2-180  |
+-----------------------------------------+-----------------+-----------+
| setreuid                                |    libc.a       |    3-406  |
+-----------------------------------------+-----------------+-----------+
| shutdown                                |    libsock.a    |    3-409  |
+-----------------------------------------+-----------------+-----------+

+-----------------------------------------+-----------------+-----------+
| sigblock                                |    libc.a       |    2-199  |
+-----------------------------------------+-----------------+-----------+
| sigpause                                |    libc.a       |    2-206  |
+-----------------------------------------+-----------------+-----------+

+-----------------------------------------+-----------------+-----------+
| Subroutine Name                         | library Name    | Page No.  |
+-----------------------------------------+-----------------+-----------+
| sigsetmask                              |    libc.a       |    2-207  |
+-----------------------------------------+-----------------+-----------+
| sigstack                                |    libc.a       |    2-209  |
+-----------------------------------------+-----------------+-----------+
| sigvec                                  |    libc.a       |    2-211  |
+-----------------------------------------+-----------------+-----------+
| socket                                  |    libsock.a    |    3-416  |
+-----------------------------------------+-----------------+-----------+
| socketpair                              |    libsock.a    |    3-419  |
+-----------------------------------------+-----------------+-----------+
| syslog, openlog, closelog, setlogmask   |    libbsd.a     |    3-438  |
+-----------------------------------------+-----------------+-----------+
| utimes                                  |    libbsd.a     |    3-464  |
+-----------------------------------------+-----------------+-----------+
| varargs                                 |    libc.a       |    3-466  |
+-----------------------------------------+-----------------+-----------+
| wait3                                   |    libbsd.a     |    3-472  |
+-----------------------------------------+-----------------+-----------+
| writev                                  |    libbsd.a     |    3-474  |
+-----------------------------------------+-----------------+-----------+

PORTING 4.3BSD APPLICATIONS TO AIX

     This section is designed  to provide programmers with the
     information necessary  to use  the 4.3BSD  functions pro-
     vided  by  AIX.  It  explains  how  to use  the  libbsd.a
     library  and suggests  some of  the changes  that may  be
     needed to port 4.3BSD programs to AIX.

     In general, when  porting you should try  to use makefile
     changes whenever  possible, changing the  original source
     code  only when  absolutely necessary.   Changes you  may
     want to make in the makefile include:

     When compiling

               o   Add a  "-I/usr/include/bsd" option  to your
                   compile command  to give you access  to the
                   4.3BSD include files.

               o   If you are using  the signal system call as
                   it    is   used    in    4.3BSD,   add    a
                   "-DBSD_REMAP_SIGNAL_TO_SIGVEC"   option  to
                   your compile command.

     When linking

               o   To  access the  BSD  4.3 library  routines,
                   link to /usr/lib/libbsd.a.

               o   To  access  the sockets  library  routines,
                   link to /usr/lib/libsock.a.

     If you must  modify your source code, for the  cpp C lan-
     guage preprocessor, enclose your  changes in ifdef state-
     ments similar to the following:

       #ifdef AIX
               <code for AIX specific version>
       #else
               <code for 4.3BSD specific version>
       #endif

     Note:  The define for the AIX Operating System is AIX.

     When  porting 4.3BSD  application  programs  to AIX,  you
     should  be  aware  that  system  calls  in  AIX  are  not
     restarted  after  receiving  a  signal, as  they  are  in
     4.3BSD.  Instead, AIX  system calls return a  value of -1
     and set  the global variable  errno to EINTR  when inter-
     rupted by a signal.

4.3BSD Include Files

     While not all of the 4.3BSD include files are provided as
     part of  AIX, the files  you are  most likely to  need in
     porting applications  are available.  The  general 4.3BSD
     files  can be  found in  the /usr/include/bsd  directory,
     while the  include files  for networking and  sockets are
     located  under  the   /usr/include  directory.   Specific
     information  on  using  several of  these  include  files
     follows this  list, then  instructions are  provided that
     tell you how to acces these files.

     List of 4.3BSD Include Files

     The 4.3BSD include files that are provided with AIX are:

                    General Include Files        Network Include Files

                    bsd/fcntl.h                  arpa/ftp.h
                    bsd/sgtty.h                  arpa/inet.h
                    bsd/strings.h                arpa/nameser.h
                    bsd/sysexits.h               arpa/telnet.h
                    bsd/sys/dir.h                arpa/tftp.h
                    bsd/sys/file.h               net/af.h
                    bsd/sys/ioctl.h              net/if.h
                    bsd/sys/msgbuf.h             net/if_arp.h
                    bsd/sys/param.h              netinet/in.h
                    bsd/sys/resource.h           netinet/in_systm.h
                    bsd/sys/signal.h             netinet/in_var.h
                    bsd/sys/syslog.h             netdb.h
                    bsd/sys/time.h               resolv.h
                    bsd/sys/ttychars.h           sys/un.h
                    bsd/sys/ttydev.h
                    bsd/sys/types.h
                    bsd/sys/wait.h
                    math.h
                    sys/socket.h
                    sys/uio.h

     Before using the bsd/sys/dir.h or bsd/sys/signal.h files,
     you should be aware of the following:

     dir.h       This  include   file  defines   and  declares
                 4.3BSD-type directory entry structures.  This
                 definition causes  problems if used  with the
                 AIX user.h file or other files that expect an
                 AIX-type directory structure.  Unless you are
                 using   the   opendir,   closedir,   readdir,
                 rewinddir,  seekdir,  and telldir  functions,
                 you should not include this file.

     signal.h    This include file is  used primarily to remap
                 signal names from 4.3BSD  names to AIX names.
                 In addition,  signal.h can be used  to change
                 the  definition of  the  signal system  call,
                 since this  system call handles  signals dif-
                 ferently in AIX than  in 4.3BSD.  To make the
                 system calls compatible, the bsd/sys/signal.h
                 file  contains a  static function  signal (),
                 surrounded                                 by
                 #ifdef BSD_REMAP_SIGNAL_TO_SIGVEC statements.
                 If you  have a  pure 4.3BSD  application, you
                 may need to define BSD_REMAP_SIGNAL_TO_SIGVEC
                 so  that signals  are not  reset after  being
                 caught.  If  you have a mixed  4.3BSD and AIX
                 application that expects  to reset signals in
                 the signal  handler, then do not  define this
                 symbol.

     To  compile  a  4.3BSD  source program  that  uses  these
     include files, you can use one of two methods:

     o   The first method is used with simple programs that do
         not contain much kernel-specific  code.  To compile a
         program  of  this  type, add  the  -I/usr/include/bsd
         option to the  cc command, either in  the makefile or
         on the  command line.  This is  the preferred method,
         since  it does  not  require changes  to the  program
         source code.

     o   The second method is to explicitly include files from
         the /usr/include/bsd  file tree.  This  method should
         be used only as a last resort.

     Changes in 4.3BSD Include Files:

     1.  The typedefs in the  4.3BSD networking include files,
         used by the sockets  routines, have been changed from
         u_long to ulong.

     2.  To avoid duplicate defines,  the 4.3BSD include files
         contain the text of any applicable AIX include files,
         whether of the same name or for related purposes.

     3.  Most of  the 4.3BSD include files  use the convention
         of  defining  _H_filename.h  so   that  they  can  be
         included multiple time without causing errors.

     4.  Parts of some 4.3BSD include files that have no rele-
         vance to AIX  are enclosed in #ifdef BSD_COMPILE_ONLY
         statements.   If you  only want  to compile,  you may
         need to define this symbol.  However, undefined names
         and  symbols  from  these files  indicate  that  your
         program will not  work in AIX without  changes to the
         source code.

Specific Information on BSD 4.3 library Routines

     A few of the 4.3BSD library routines function differently
     in AIX.  This section provides  you with details of these
     differences for a few routines,  then gives you a list of
     individual routine descriptions  that also contain infor-
     mation on such differences.

     strcpyn     Calls  to this  subroutine  must be  replaced
                 with the strncpy subroutine.

     strcatn     Calls  to this  subroutine  must be  replaced
                 with the strncat subroutine.

     _doprnt     To help  you in porting  4.3BSD applications,
                 the following routine is also provided:

                 The  _doprnt   subroutine  performs  internal
                 printf functions.

                 _doprnt (format, args, stream)
                 char *format;
                 va_list *args;
                 FILE *stream;

                 In  AIX, the  _doprnt subroutine  returns the
                 count of characters printed or EOF.

     sleep       The sleep  subroutine uses the  alarm, pause,
                 and signal  system calls to achieve  a simple
                 delay.  Since  signal handling in  4.3BSD and
                 AIX is  not the  same, 4.3BSD code  that also
                 uses  SIGALRM from  setitimer  may not  work.
                 This is particularly likely if the sleep call
                 is issued  inside a  signal handler,  such as
                 when exiting.

                 To solve this problem, replace the sleep sub-
                 routine with either a  spin loop or a private
                 version of sleep made with the setitimer sub-
                 routine and the  signal system call, defining
                 BSD_REMAP_SIGNAL_TO_SIGVEC  so   that  4.3BSD
                 compatible signals are used.

     If your 4.3BSD program uses any of the subroutines on the
     following  list, refer  to the  full description  of that
     routine  in  this  chapter  before  porting.   Additional
     4.3BSD subroutines with differences in AIX include:

         getitimer, setitimer
         gettimeofday
         killpg
         setbuffer, setlinebuf
         setreuid
         syslog
         utimes
         wait3

4.3BSD tty Devices

     One  area where  you may  need  to make  changes to  your
     source code  is in the use  of the tty driver,  since the
     AIX and 4.3BSD drivers are different.

     If  your   4.3BSD  program   uses  the   curses  library,
     libcurses.a, tty issues should  be handled at that level.
     Note,  however, that  AIX  uses  the terminfo  subroutine
     instead of the termcap subroutine that is used in 4.3BSD.

     If your  4.3BSD program sets  tty modes, you may  need to
     insert ifdef statements around the 4.3BSD tty source code
     and replace it with new  source code using the AIX termio
     structures.

     When writing  or updating code  that gets and  uses ptys,
     keep in mind that:

     o   AIX and  4.3BSD use different naming  conventions for
         ptys.

         In 4.3BSD,  the controller side is  named /dev/ttyxy,
         while the servant side is named /dev/ptyxy.  In these
         names, x  represents p or  q or r.  The  y represents
         any one value from  0 to 9 or from a  to f.  The only

         difference  in the  names is  that the  controller is
         called   /dev/tty,  while   the  servant   is  called
         /dev/pty.

         In AIX,  the controller side is  named /dev/ptcn, and
         the servant side  is named /dev/ptsn, with  n in both
         cases representing  a decimal number greater  than or
         equal to 0.  The difference in names is that the con-
         troller  is called  /dev/ptc,  while  the servant  is
         called /dev/pts.

     o   ptys are obtained differently in AIX than 4.3BSD.

         In AIX, a getty command can be running on the servant
         side of  a pty, waiting  for the telnet program  or a
         similar program  to attach  itself on  the controller
         side.  This possibility prevents programs from trying
         controller ptys  until one  opens, then  assuming the
         servant side is available, as is the case in 4.3BSD

         Programs that need to get  ptys in AIX must check the
         /etc/portstatus   file  to   see  which   tty  ports,
         including ptys,  are enabled.  For  more information,
         see "portstatus."

4.3BSD ioctls

     The AIX and  4.3BSD operating systems do  not support the
     same ioctls.   For a list  of the 4.3BSD ioctls  that are
     not   supported  in   AIX,  see   the  sections   of  the
     /usr/include/bsd/sys/ioctl.h  file between  the following
     lines:

     #ifdef BSD_COMPILE_ONLY
     #endif BSD_COMPILE_ONLY

     Several  of the  4.3BSD  ioctls  have equivalent  fcntls,
     while AIX  has only the  fcntl calls.  In  addition, some
     4.3BSD fcntls are not available in AIX, so ioctls must be
     used instead.  For example:

     Used in 4.3BSD       Used in AIX

     ioctl FIONBIO        fcntl F_SETFL to set NDELAY
     fcntl F_SETOWN       ioctl   FIOSETOWN   to   set   owner
                          (sockets only)

     These differences can be  handled by using the applicable
     ioctl or fcntl  in place of the original  code.  For more
     information on the sockets ioctls, see "socket."

Related Information

     In this book:  "sockets library."

     The descriptions of individual  BSD commands in AIX Oper-
     ating System Commands Reference.

     The descriptions of individual  BSD commands in Interface
     Program for use with TCP/IP.

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026