home *** CD-ROM | disk | FTP | other *** search
/ Network PC / Network PC.iso / amiga utilities / communication / internet / amitcp3.0b / doc / netlib.doc < prev    next >
Encoding:
Text File  |  1997-11-21  |  56.8 KB  |  1,750 lines

  1. TABLE OF CONTENTS
  2.  
  3. net.lib/autoinit
  4. net.lib/autoinit_timer.device
  5. net.lib/autoinit_usergroup.library
  6. net.lib/charRead
  7. net.lib/chmod
  8. net.lib/chown
  9. net.lib/dup
  10. net.lib/dup2
  11. net.lib/fstat
  12. net.lib/gettimeofday
  13. net.lib/herror
  14. net.lib/init_inet_daemon
  15. net.lib/lineRead
  16. net.lib/lstat
  17. net.lib/perror
  18. net.lib/popen
  19. net.lib/PrintNetFault
  20. net.lib/PrintUserFault
  21. net.lib/rcmd
  22. net.lib/serveraccept
  23. net.lib/set_socket_stdio
  24. net.lib/sleep
  25. net.lib/stat
  26. net.lib/strerror
  27. net.lib/syslog
  28. net.lib/usleep
  29. net.lib/utime
  30. net.lib/autoinit                                             net.lib/autoinit
  31.  
  32.    NAME
  33.        autoinit - SAS C Autoinitialization Functions
  34.  
  35.    SYNOPSIS
  36.        LONG _STI_200_openSockets(void)
  37.  
  38.        void _STD_200_closeSockets(void)
  39.  
  40.    FUNCTION
  41.        These functions open and close the bsdsocket.library at the startup
  42.        and exit of the program, respectively.  For a program to use these
  43.        functions, it must be linked with netlib:net.lib (or some variant).
  44.        These functions are linked in only if the program references the
  45.        global symbol "SocketBase".
  46.  
  47.        If the library can be opened, the _STI_200_openSockets() calls
  48.        bsdsocket.library function SocketBaseTags() to tell the library the
  49.        address and the size of the errno variable of the calling program,
  50.        the program name (to be used in syslog() messages) and the address
  51.        of the h_error variable (in which the name resolver errors are
  52.        returned).
  53.  
  54.    NOTES
  55.        _STI_200_openSockets() also checks that the system version is at
  56.        least 37. It also puts up a requester if the bsdsocket.library is
  57.        not found or is of wrong version.
  58.  
  59.        The autoinitialization and autotermination functions are features
  60.        specific to the SAS C6.  However, these functions can be used with
  61.        other (ANSI) C compilers, too. Example follows:
  62.  
  63.        /* at start of main() */
  64.  
  65.        atexit(_STD_200_closeSockets);
  66.        if (_STD_200_openSockets() != 0)
  67.           exit(20);
  68.  
  69.    BUGS
  70.        The same autoinitialization won't work for both SAS C 6.3 and SAS C
  71.        6.50 or latter.  Only way to terminate an initialization function is
  72.        by exit() call with SAS C 6.3 binary.  If an autoinitialization
  73.        function is terminated by exit() call with SAS C 6.50 binary, the
  74.        autotermination functions won't be called.  Due this braindamage
  75.        these compilers require separate net.lib libraries.
  76.  
  77.    SEE ALSO
  78.        bsdsocket.library/SocketBaseTags(),
  79.        SAS/C 6 User's Guide p. 145 for details of autoinitialization and
  80.        autotermination functions.
  81.  
  82. net.lib/autoinit_timer.device                   net.lib/autoinit_timer.device
  83.  
  84.    NAME
  85.        timerinit - SAS C Autoinitialization Functions for timer.device
  86.  
  87.    SYNOPSIS
  88.        _STIopenTimer()
  89.  
  90.        LONG _STI_200_openTimer(void)
  91.  
  92.        _STDcloseTimer()
  93.  
  94.        void _STD_200_closeTimer(void)
  95.  
  96.    FUNCTION
  97.  
  98.        These functions open and close the timer.device at the startup and
  99.        exit of the program, respectively. For a program to use these
  100.        functions, it must be linked with netlib:net.lib.
  101.  
  102.        The opened device base is stored in the TimerBase global variable.
  103.  
  104.        If the device can be opened, the _STIopenTimer() sets up the time zone
  105.        information, which is used by the gettimeofday() function.
  106.  
  107.    NOTES
  108.        The time zone information is got from the environment variable named
  109.        TZ. The format for this variable is:
  110.  
  111.            zzznnnddd
  112.  
  113.        where zzz is three letter identifier for the time zone (for example
  114.        GMT), and the nnn is hours west from Greenwich on range [-23,24]
  115.        (negative values are to east).  The last field is the abbreviation for
  116.        the local daylight saving time zone (which is not interpreted by this
  117.        version).
  118.  
  119.        If the TZ environment variable cannot be found, Greenwich Mean Time
  120.        (GMT) is used instead.
  121.  
  122.        The autoinitialization and autotermination functions are features
  123.        specific to the SAS C6.  However, these functions can be used with
  124.        other (ANSI) C compilers, too.  Example follows:
  125.  
  126.        /* at start of main() */
  127.  
  128.        atexit(_STDcloseTimer);
  129.        _STDopenTimer();
  130.  
  131.    BUGS
  132.        TZ "hours west from GMT" should be interpreted as float.
  133.  
  134.        The same autoinitialization won't work for both SAS C 6.3 and SAS C
  135.        6.50 or latter.  Only way to terminate an initialization function is
  136.        by exit() call with SAS C 6.3 binary.  If an autoinitialization
  137.        function is terminated by exit() call with SAS C 6.50 binary, the
  138.        autotermination functions won't be called.  Due this braindamage
  139.        these compilers require separate net.lib libraries.
  140.  
  141.    SEE ALSO
  142.        net.lib/gettimeofday(),
  143.        SAS/C 6 User's Guide p. 145 for details of autoinitialization and
  144.        autotermination functions.
  145. net.lib/autoinit_usergroup.library         net.lib/autoinit_usergroup.library
  146.  
  147.    NAME
  148.        autoinit usergroup.library - SAS C Autoinitialization Functions
  149.  
  150.    SYNOPSIS
  151.        error = _STI_200_openUserGroup()
  152.  
  153.        LONG _STI_200_openUserGroup(void)
  154.  
  155.        _STD_200_closeUserGroup()
  156.  
  157.        void _STD_200_closeUserGroup(void)
  158.  
  159.    FUNCTION
  160.        These functions open and close the usergroup.library at the startup
  161.        and exit of the program, respectively.  For a program to use these
  162.        functions, it must be linked with netlib:usr.lib.
  163.  
  164.    NOTES
  165.        _STI_200_openUserGroup() also checks that the system version is at
  166.        least 37.  It puts up a requester if the usergroup.library is not
  167.        found or is too old version.
  168.  
  169.        The autoinitialization and autotermination functions are features
  170.        specific to the SAS C6.  However, these functions can be used with
  171.        other (ANSI) C compilers, too.  Example follows:
  172.  
  173.        /* at start of main() */
  174.  
  175.        atexit(_STD_200_closeUserGroup);
  176.        if (_STI_200_openUserGroup() != 0)
  177.           exit(20);
  178.  
  179.    BUGS 
  180.        The same autoinitialization won't work for both SAS C 6.3 and SAS C
  181.        6.50 or latter.  Only way to terminate an initialization function is
  182.        by exit() call with SAS C 6.3 binary.  If an autoinitialization
  183.        function is terminated by exit() call with SAS C 6.50 binary, the
  184.        autotermination functions won't be called.  Due this braindamage
  185.        these compilers require separate net.lib libraries.
  186.  
  187.    SEE ALSO
  188.        SAS/C 6 User's Guide p. 145 for details of autoinitialization and
  189.        autotermination functions.
  190.  
  191. net.lib/charRead                                             net.lib/charRead
  192.  
  193.    NAME
  194.        charRead -- read characters from socket one by one.
  195.  
  196.    SYNOPSIS
  197.        initCharRead(rc, fd)
  198.  
  199.        void initCharRead(struct CharRead *, int);
  200.  
  201.  
  202.        character = charRead(rc)
  203.  
  204.        int charRead(struct CharRead *);
  205.  
  206.  
  207.    DESCRIPTION
  208.        charRead is a macro package which return characters one by one 
  209.        from given socket input stream. The socket where data is to be read
  210.        is set by calling initCharRead(): rc is the pointer to charread
  211.        structure previously allocated. fd is the (socket) descriptor where
  212.        reading is to be done.
  213.  
  214.        charRead() returns the next character from input stream or one of
  215.        the following:
  216.  
  217.        RC_DO_SELECT    (-3)    - read input buffer is returned. Do select
  218.                                  before next call if you don't want charread
  219.                                  to block.
  220.  
  221.        RC_EOF          (-2)    - end-of-file condition has occurred.
  222.  
  223.        RC_ERROR        (-1)    - there has been an error while filling new
  224.                                  charread buffer. Check the value of Errno()
  225.  
  226.    NOTE
  227.        Always use variable of type int to store return value from charRead()
  228.        since the numeric value of characters returned may vary between
  229.        0 -255 (or even greater). As you may know, -3 equals 253 if of type
  230.        unsigned char.
  231.  
  232.    EXAMPLE
  233.        /*
  234.         * This piece of code shows how to use charread with select()
  235.         */
  236.        #include <sys/types.h>
  237.        #include <sys/socket.h>
  238.        #include <charread.h>
  239.  
  240.        main_loop(int sock)
  241.        {
  242.          struct CharRead rc;
  243.          fd_set readfds;
  244.          int c;
  245.  
  246.          initCharRead(&rc, sock);
  247.  
  248.          FD_ZERO(&readfds);
  249.  
  250.          while(1) {
  251.            FD_SET(sock, &readfds);     
  252.  
  253.            if (select(sock + 1. &readfds, NULL, NULL, NULL)) < 0) {
  254.              perror("select");
  255.              break;
  256.            }
  257.            if (FD_ISSET(sock, &readfds)) {
  258.              while((c = charRead(&rc)) >= 0)
  259.                handle_next_input_character(c);
  260.              if (c == RC_EOF)
  261.                break;
  262.              if (c == RC_ERROR) {
  263.                perror("charRead");
  264.                break;
  265.              }
  266.            }
  267.          }
  268.        }
  269.  
  270.     PORTABILITY
  271.        The source file charread.h should be able to be used in 
  272.        UNIX programs as is.
  273.  
  274.     AUTHORS
  275.        Tomi Ollila,
  276.        the AmiTCP/IP Group <amitcp-group@hut.fi>,
  277.  
  278.     SEE ALSO
  279.        lineRead(), bsdsocket.library/recv()
  280. net.lib/chmod                                                   net.lib/chmod
  281.  
  282.    NAME
  283.        chmod, fchmod - change mode of file
  284.  
  285.    SYNOPSIS
  286.        #include <sys/stat.h>
  287.  
  288.        int chmod(const char *path, mode_t mode);
  289.  
  290.        int fchmod(int fd, mode_t mode);
  291.  
  292.    DESCRIPTION
  293.        The function chmod() sets the file permission bits of the file
  294.        specified by the pathname path to mode. Fchmod() sets the permission
  295.        bits of the specified file descriptor fd. Chmod() verifies that the
  296.        process owner (user) either owns the file specified by path (or fd),
  297.        or is the super-user.  A mode is created from or'd permission bit
  298.        masks defined in <sys/stat.h>:
  299.  
  300.              #define S_IRWXU 0000700    /* RWX mask for owner */
  301.              #define S_IRUSR 0000400    /* R for owner */
  302.              #define S_IWUSR 0000200    /* W for owner */
  303.              #define S_IXUSR 0000100    /* X for owner */
  304.  
  305.              #define S_IRWXG 0000070    /* RWX mask for group */
  306.              #define S_IRGRP 0000040    /* R for group */
  307.              #define S_IWGRP 0000020    /* W for group */
  308.              #define S_IXGRP 0000010    /* X for group */
  309.  
  310.              #define S_IRWXO 0000007    /* RWX mask for other */
  311.              #define S_IROTH 0000004    /* R for other */
  312.              #define S_IWOTH 0000002    /* W for other */
  313.              #define S_IXOTH 0000001    /* X for other */
  314.  
  315.              #define S_ISUID 0004000    /* set user id on execution */
  316.              #define S_ISGID 0002000    /* set group id on execution */
  317.              #define S_ISVTX 0001000    /* save swapped text even after use *
  318. /
  319.  
  320.        The ISVTX (the sticky bit) indicates to the system which executable
  321.        files are shareable (pure).
  322.  
  323.        Writing or changing the owner of a file turns off the set-user-id
  324.        and set-group-id bits unless the user is the super-user.  This makes
  325.        the system somewhat more secure by protecting set-user-id
  326.        (set-group-id) files from remaining set-user-id (set-group-id) if
  327.        they are modified.
  328.  
  329.    RETURN VALUES
  330.        Upon successful completion, a value of 0 is returned.  Otherwise, a
  331.        value of -1 is returned and errno is set to indicate the error.
  332.  
  333.    ERRORS
  334.        Chmod() will fail and the file mode will be unchanged if:
  335.  
  336.        [ENOTDIR]     A component of the path prefix is not a directory.
  337.  
  338.        [ENAMETOOLONG]
  339.                      A component of a pathname exceeded 255 characters, or
  340.                      an entire path name exceeded 1023 characters.
  341.  
  342.        [ENOENT]      The named file does not exist.
  343.  
  344.        [EACCES]      Search permission is denied for a component of the
  345.                      path prefix.
  346.  
  347.        [EPERM]       The effective user ID does not match the owner of the
  348.                      file and the effective user ID is not the super-user.
  349.  
  350.        [EROFS]       The named file resides on a read-only file system.
  351.  
  352.        [EFAULT]      Path points outside the process's allocated address
  353.                      space.
  354.  
  355.        [EIO]         An I/O error occurred while reading from or writing to
  356.                      the file system.
  357.  
  358.        Fchmod() will fail if:
  359.  
  360.        [EBADF]       The descriptor is not valid.
  361.  
  362.        [EINVAL]      Fd refers to a socket, not to a file.
  363.  
  364.        [EROFS]       The file resides on a read-only file system.
  365.  
  366.        [EIO]         An I/O error occurred while reading from or writing to
  367.                      the file system.
  368.  
  369.    NOTES
  370.        This call is provided for Unix compatibility.  It does not know all
  371.        Amiga protection bits (Delete, Archive, Script).  The archive and
  372.        script bits are cleared, Delete set according the Write bit.
  373.  
  374.    SEE ALSO
  375.        open(),  chown(),  stat()
  376.  
  377. net.lib/chown                                                   net.lib/chown
  378.  
  379.    NAME
  380.        chown - change owner and group of a file
  381.  
  382.    SYNOPSIS
  383.        #include <unistd.h>
  384.  
  385.        success = chown(path, owner, group)
  386.  
  387.        int chown(const char *, uid_t, gid_t);
  388.  
  389.    DESCRIPTION
  390.        The owner ID and group ID of the file named by path or referenced by
  391.        fd is changed as specified by the arguments owner and group.  The
  392.        owner of a file may change the group to a group of which he or she is
  393.        a member, but the change owner capability is restricted to the
  394.        super-user.
  395.  
  396.        Chown() clears the set-user-id and set-group-id bits on the file to
  397.        prevent accidental or mischievious creation of set-user-id and
  398.        set-group-id programs.
  399.  
  400.        One of the owner or group id's may be left unchanged by specifying it
  401.        as -1.
  402.  
  403.        If the final component of path is a symbolic link, the ownership and
  404.        group of the symbolic link is changed, not the ownership and group of
  405.        the file or directory to which it points.
  406.  
  407.    RETURN VALUES
  408.        Zero is returned if the operation was successful; -1 is returned if an
  409.        error occurs, with a more specific error code being placed in the
  410.        global variable errno.
  411.  
  412.    ERRORS
  413.        Chown() will fail and the file will be unchanged if:
  414.  
  415.        [ENOTDIR]     A component of the path prefix is not a directory.
  416.  
  417.        [EINVAL]      The pathname contains a character with the high-order
  418.                      bit set.
  419.  
  420.        [ENAMETOOLONG]
  421.                      A component of a pathname exceeded 80 characters, or an
  422.                      entire path name exceeded 1023 characters.
  423.  
  424.        [ENOENT]      The named file does not exist.
  425.  
  426.        [EACCES]      Search permission is denied for a component of the path
  427.                      prefix.
  428.  
  429.        [ELOOP]       Too many symbolic links were encountered in translating
  430.                      the pathname.
  431.  
  432.        [EPERM]       The effective user ID is not the super-user.
  433.  
  434.        [EROFS]       The named file resides on a read-only file system.
  435.  
  436.        [EFAULT]      Path points outside the process's allocated address
  437.                      space.
  438.  
  439.        [EIO]         An I/O error occurred while reading from or writing to
  440.                      the file system.
  441.  
  442.    SEE ALSO
  443.        chmod(2)
  444.  
  445. net.lib/dup                                                       net.lib/dup
  446.  
  447.    NAME
  448.        dup, dup2 - duplicate an existing file descriptor
  449.  
  450.    SYNOPSIS
  451.        #include <unistd.h>
  452.  
  453.        int dup(int oldd)
  454.  
  455.        int dup2(int oldd, int newd)
  456.  
  457.    FUNCTION
  458.        Dup() duplicates an existing object descriptor and returns its value
  459.        to the calling program (newd = dup(oldd)). The argument oldd is a
  460.        small nonnegative integer index in the program's descriptor table.
  461.        The value must be less than the size of the table, which is returned
  462.        by getdtablesize().  The new descriptor returned by the call is the
  463.        lowest numbered descriptor currently not in use by the program.
  464.  
  465.        The object referenced by the descriptor does not distinguish between
  466.        oldd and newd in any way.  Thus if newd and oldd are duplicate
  467.        references to an open file, read() and write() calls all move a single
  468.        pointer into the file, and append mode, non-blocking I/O and
  469.        asynchronous I/O options are shared between the references.  If a
  470.        separate pointer into the file is desired, a different object
  471.        reference to the file must be obtained by issuing an additional open()
  472.        call.  The close-on-exec flag on the new file descriptor is unset.
  473.  
  474.        In dup2(), the value of the new descriptor newd is specified.  If this
  475.        descriptor is already in use, the descriptor is first deallocated as
  476.        if a close() call had been done first.
  477.  
  478.    RETURN VALUES
  479.        The value -1 is returned if an error occurs in either call.  The
  480.        external variable errno indicates the cause of the error.
  481.  
  482.    BUGS
  483.        The current UFB implementation for SAS C allows only sockets to be
  484.        duplicated.
  485.  
  486.    ERRORS
  487.        Dup() and dup2() fail if:
  488.  
  489.        [EBADF]       Oldd or newd is not a valid active descriptor
  490.  
  491.        [EMFILE]      Too many descriptors are active.
  492.  
  493.    SEE ALSO
  494.        accept(),  open(),  close(),  socket(),  getdtablesize()
  495.  
  496.    STANDARDS
  497.        Dup() and dup2() are expected to conform to IEEE Std 1003.1-1988
  498.        (``POSIX'').
  499.  
  500.    COPYRIGHT
  501.        This manual page is copyright © 1980, 1991 Regents of the
  502.        University of California.  All rights reserved.
  503.  
  504. net.lib/dup2                                                     net.lib/dup2
  505.    SEE ALSO
  506.        dup()
  507. net.lib/fstat                                                   net.lib/fstat
  508.  
  509.    SEE ALSO
  510.        stat()
  511.  
  512. net.lib/gettimeofday                                     net.lib/gettimeofday
  513.  
  514.    NAME   
  515.        gettimeofday - get date and time 
  516.  
  517.    SYNOPSIS
  518.        #include <sys/time.h>
  519.  
  520.        error = gettimeofday(tp, tzp)
  521.  
  522.        int gettimeofday(struct timeval *, struct timezone *)
  523.  
  524.    FUNCTION
  525.        The system's notion of the current Greenwich time and the
  526.        current time zone is obtained with the gettimeofday() call.
  527.        The time is expressed in seconds and microseconds since
  528.        midnight (0 hour), January 1, 1970.  The resolution of the
  529.        system clock is hardware dependent. If tzp is zero, the time
  530.        zone information will not be returned. Also, if your system
  531.        software is unable to provide time zone information, the
  532.        structure pointed by tzp will be filled with zeroes.
  533.   
  534.    PORTABILITY
  535.        UNIX
  536.  
  537.    INPUTS
  538.        The structures pointed to by tp and tzp are defined in
  539.        <sys/time.h> as:
  540.   
  541.             struct timeval {
  542.                  long tv_sec;      /* seconds since Jan. 1, 1970 */
  543.                  long tv_usec;     /* and microseconds */
  544.             };
  545.   
  546.             struct timezone {
  547.                  int  tz_minuteswest;   /* of Greenwich */
  548.                  int  tz_dsttime;  /* type of dst correction to apply */
  549.             };
  550.   
  551.        The timezone structure indicates the local time zone (meas-
  552.        ured in minutes of time westward from Greenwich), and a flag
  553.        that, if nonzero, indicates that Daylight Saving time
  554.        applies locally during the appropriate part of the year.
  555.  
  556.    RESULT
  557.        Returns 0 when successful and -1 with specific error code in 
  558.        errno in case of an error. No error codes are specified,
  559.        however.
  560.        
  561.    NOTES
  562.        gettimeofday() uses GetSysTime() function of the timer.device,
  563.        which is new to V36 of the device.
  564.  
  565.        Time zone information is taken from the locale.library, if it
  566.        is available (it is included in all Amiga systems from 2.1 and
  567.        up). Otherwise the environment variable "TZ" is consulted. If
  568.        it fails, the time zone is initialized to the GMT.
  569.  
  570.        Global variable TimerBase _must_ be initialized before
  571.        gettimeofday() is called. This is normally done automatically
  572.        by the autoinit module (timerinit.c) included in the net.lib.
  573.  
  574.    SEE ALSO
  575.        timer.device/GetSysTime()
  576. net.lib/herror                                                 net.lib/herror
  577.  
  578.    NAME
  579.        herror - print name resolver error message to stderr.
  580.  
  581.    SYNOPSIS
  582.        #include <stdio.h>
  583.  
  584.        herror(banner)
  585.        void herror(const char *)
  586.  
  587.    FUNCTION
  588.        The herror() function finds the error message corresponding to the
  589.        current value of host error using the SocketBaseTags() and writes
  590.        it, followed by a newline, to the stderr. If the argument string
  591.        is non-NULL it is used as a prefix to the message string and
  592.        separated from it by a colon and space (`: '). If the argument is
  593.        NULL only the error message string is printed.
  594.  
  595.    NOTES
  596.        The herror() function requires the stdio functions to be linked.
  597.  
  598.    SEE ALSO
  599.        <netinclude:netdb.h>, SocketBaseTagList(), perror()
  600.  
  601. net.lib/init_inet_daemon                             net.lib/init_inet_daemon
  602.  
  603.    NAME
  604.        init_inet_daemon - obtain socket accepted by the inetd
  605.  
  606.    SYNOPSIS
  607.        int init_inet_daemon(void);
  608.  
  609.    FUNCTION
  610.        Obtain the server socket accepted by the inetd, the Internet
  611.        super-server.
  612.  
  613.    RETURN VALUES
  614.        socket descriptor if successful, -1 with specific error code
  615.        on errno otherwise.
  616.  
  617.    ERRORS
  618.        ENXIO     - The process was not started by the inetd.
  619.  
  620.    NOTES
  621.        If the process was started by the inetd, but the ObtainSocket()
  622.        call fails, then this function exit()s with some specific exit
  623.        code, so that inetd can clean up the unobtained socket.
  624.  
  625.        Use the net.lib function set_socket_stdio() to redirect stdio,
  626.        stdout and stderr to the returned socket, if necessary.
  627.  
  628.    AUTHOR
  629.        Jarno Rajahalme, Pekka Pessi, 
  630.        the AmiTCP/IP Group <amitcp-group@hut.fi>,
  631.        Helsinki University of Technology, Finland.
  632.  
  633.    SEE ALSO
  634.        serveraccept(), set_socket_stdio(), bsdsocket/ObtainSocket(),
  635.        netutil/inetd
  636. net.lib/lineRead                                             net.lib/lineRead
  637.  
  638.    NAME
  639.        lineRead -- read newline terminated strings from socket
  640.  
  641.    SYNOPSIS
  642.        initLineRead(rl, fd, lftype, bufsize)
  643.  
  644.        void initLineRead(struct LineRead *, int, int, int);
  645.  
  646.  
  647.        length = lineRead(rl)
  648.  
  649.        int lineread(struct LineRead *);
  650.  
  651.  
  652.    FUNCTION
  653.        lineRead() reads newline terminated strings from given descriptor
  654.        very efficiently. All the options needed are set by calling
  655.        initLineRead(): rl is the pointer to lineread structure previously
  656.        allocated. fd is the (socket) descriptor where reading is to be
  657.        done. lftype can have following 3 values:
  658.  
  659.            RL_LFNOTREQ - Newline terminated strings are returned unless
  660.                          there is no newlines left in currently buffered
  661.                          input. In this case remaining buffer is returned.
  662.  
  663.            RL_LFREQLF  - If there is no newlines left in currently buffered
  664.                          input the remaining input data is copied at the
  665.                          start of buffer. Caller is informed that next
  666.                          call will fill the buffer (and it may block).
  667.                          Lines are always returned with newline at the end
  668.                          unless the string is longer than whole buffer.
  669.  
  670.            RL_LFREQNUL  - Like LF_REQLF, but remaining newline is removed.
  671.                          Note here that lenght is one longer that actual
  672.                          string length since line that has only one
  673.                          newline at the end would return length as 0
  674.                          which indigate string incomplete condition.
  675.  
  676.        bufsize is used to tell lineread how big the receive buffer is.
  677.        always put RL_BUFSIZE here since that value is used to determine
  678.        the memory allocated for the buffer. This option is given to you
  679.        so you may decide to use different buffer size than the default
  680.        1024.
  681.  
  682.        lineRead() returns the newline terminated string in rl_line field
  683.        of lineread structure. Return values of lineRead() are:
  684.  
  685.             1 - RL_BUFSIZE     - normal length of returned string.
  686.  
  687.             0                  - If zero is returned just after select(),
  688.                                  end-of-file condition has occurred.
  689.                                  Otherwise string is not completed yet.
  690.                                  Make sure you call select() (or use non-
  691.                                  blocking IO) if you don't want next call
  692.                                  to block.
  693.  
  694.            -1                  - if rl_Line field of lineread structure
  695.                                  is NULL, it indicates error condition.
  696.                                  If rl_Line points to start of string
  697.                                  buffer, input string has been longer
  698.                                  than buffer. In this case rl_Line points
  699.                                  to zero terminated string of length
  700.                                  RL_BUFSIZE.
  701.  
  702.        You may modify the zero terminated string returned by lineRead() in
  703.        any way, but memory around the string is private lineread memory.
  704.  
  705.    EXAMPLE
  706.        /*
  707.         * The following code shows how to use lineread with select()
  708.         */
  709.        #ifdef USE_LOW_MEMORY_BUFFER
  710.        #define RL_BUFSIZE 256
  711.        #endif
  712.  
  713.        #include <sys/types.h>
  714.        #ifdef AMIGA
  715.        #include <bsdsocket.h>
  716.        #endif
  717.        #include <lineread.h>
  718.  
  719.        #define NULL 0
  720.  
  721.        ...
  722.  
  723.        main_loop(int sock)
  724.        {
  725.          struct LineRead * rl;
  726.          int length;
  727.          fd_set reafdfs;
  728.  
  729.          if (rl = (struct LineRead *)AllocMem(sizeof (*rl), 0)) {
  730.  
  731.            initLineRead(rl, sock, LF_REQLF, RL_BUFSIZE);
  732.  
  733.            FD_ZERO(&readfds);
  734.  
  735.            while(1) {
  736.              FD_SET(sock, &readfds);
  737.  
  738.              if (select(sock + 1, &readfds, NULL, NULL, NULL)) < 0) {
  739.                perror("select");
  740.                break;
  741.              }
  742.              if (FD_ISSET(sock, &readfds))
  743.                if ((length = lineRead(rl)) == 0) /* EOF */
  744.                  break;
  745.                do {
  746.                  if (length > 0)
  747.                    write(1, rl->rl_Line, length); /* stdout. write() for */
  748.                                                   /* speed demonstration */
  749.                  else { /* length == -1 */
  750.                    if (rl->rl_Line == NULL); {
  751.                      perror("lineRead");
  752.                      break;
  753.                    }
  754.                    else {
  755.                      fprintf(stderr, "lineread input buffer overflow!\n");
  756.                      write(1, rl->rl_Line, RL_BUFSIZE);
  757.                      write(1, "\n", 1);
  758.                    }
  759.                  }
  760.                } while ((length = lineRead(rl)) != 0); /* 0 -> do select() */
  761.            }
  762.          FreeMem(rl, sizeof (*rl);
  763.          }
  764.          else
  765.            fprintf("AllocMem: Out Of memory\n");
  766.        }
  767.  
  768.     PORTABILITY
  769.        The source modules lineread.c and lineread.h should compile
  770.        in UNIX machines as is.
  771.  
  772.     AUTHORS
  773.        Tomi Ollila,
  774.        the AmiTCP/IP Group <amitcp-group@hut.fi>,
  775.  
  776.     SEE ALSO
  777.        charRead(), bsdsocket.library/recv()
  778.  
  779. net.lib/lstat                                                   net.lib/lstat
  780.  
  781.    SEE ALSO
  782.        stat()
  783.  
  784. net.lib/perror                                                 net.lib/perror
  785.  
  786.    NAME
  787.        perror - socket error messages
  788.  
  789.    SYNOPSIS
  790.        extern int errno;
  791.  
  792.        #include <stdio.h>
  793.  
  794.        perror(banner)
  795.        void perror(const char *)
  796.  
  797.    FUNCTION
  798.        The perror() function finds the error message corresponding to the
  799.        current value of the global variable errno and writes it, followed
  800.        by a newline, to the stderr. If the argument string is non-NULL it
  801.        is preappended to the message string and separated from it by a
  802.        colon and space (`: '). If string is NULL only the error message
  803.        string is printed.
  804.  
  805.    NOTES
  806.        The perror() function requires the stdio functions to be linked.
  807.  
  808.    SEE ALSO
  809.        strerror(), PrintNetFault(), <netinclude:sys/errno.h>
  810.  
  811. net.lib/popen                                                   net.lib/popen
  812.    NAME
  813.        popen, pclose - initiate I/O to/from a process
  814.  
  815.    SYNOPSIS
  816.        #include <stdio.h>
  817.  
  818.        FILE *popen(command, type)
  819.        char *command, *type;
  820.  
  821.        pclose(stream)
  822.        FILE *stream;
  823.  
  824.    DESCRIPTION
  825.        The arguments to popen are pointers to null-terminated
  826.        strings containing respectively a command line and an
  827.        I/O mode, either "r" for reading or "w" for writing.  It
  828.        creates a pipe between the calling process and the command
  829.        to be executed.  The value returned is a stream pointer that
  830.        can be used (as appropriate) to write to the standard input
  831.        of the command or read from its standard output.
  832.  
  833.        A stream opened by popen **MUST** be closed by pclose, which
  834.        waits for the associated process to terminate and returns
  835.        the exit status of the command.
  836.  
  837.        Because stdio files are shared, a type "r" command may be
  838.        used as an input filter, and a type "w" as an output filter.
  839.  
  840.    DIAGNOSTICS
  841.        Popen returns a null pointer if files or processes cannot be
  842.        created.
  843.  
  844.        Pclose returns -1 if stream is not associated with a
  845.        `popened' command.
  846.  
  847.    AUTHOR
  848.        Original version by Rick Schaeffer <ricks@isc-br.isc-br.com>
  849. /
  850.  
  851. include <stdio.h>
  852. include <stdlib.h>
  853. include <string.h>
  854. include <stdarg.h>
  855.  
  856. include <exec/types.h>
  857. include <exec/memory.h>
  858. include <dos/dos.h>
  859. include <dos/dosextens.h>
  860. include <dos/record.h>
  861. include <dos/dostags.h>
  862.  
  863. include <proto/exec.h>
  864. include <proto/dos.h>
  865. include <clib/alib_protos.h>
  866.  
  867. include <errno.h>
  868.  
  869. define NOTDEF
  870.  
  871. xtern char *mktemp(char *);
  872.  
  873. truct POmsg {
  874.    struct Message  POm;
  875.    int     rc;
  876.    char        *cmd;
  877.    struct Library  *DOSBase;
  878.    };
  879.  
  880.  
  881. truct pstruct {
  882.    FILE    *fptr;
  883.    struct POmsg    childmsg;
  884.    };
  885.  
  886. define MAXPIPES    6
  887. tatic struct pstruct poarray[MAXPIPES];
  888.  
  889. tatic int childprocess(void);
  890.  
  891. ILE *popen(const char *cmd, const char *mode)
  892.  
  893.    static char tempname[] = "pipe:pXXX.XXX";
  894.    char        *pname,redir[20];
  895.    short       i;
  896.    int         pmode;
  897.    struct pstruct  *poptr;
  898.    BPTR            pfd;
  899.    struct Process  *child;
  900.    struct CommandLineInterface *cli;
  901.    BPTR Binfh, Boutfh;
  902.    ULONG closeinp, closeoutp;
  903.    ULONG stacksize;
  904.    struct Process *thistask;
  905.  
  906.    /* First, get pointers to our process and cli structs */
  907.    thistask = (struct Process *) FindTask(NULL);
  908.    cli = Cli();
  909.    poptr = NULL;
  910.  
  911.    /* now find an open pipe (we currently only allow 6 simultaneously
  912.       open pipes) */
  913.    for (i=0; i<MAXPIPES; i++) {
  914.        if (poarray[i].fptr == NULL) {
  915.            poptr = &poarray[i];
  916.            break;
  917.            }
  918.        }
  919.    if (poptr == NULL) {
  920.        fprintf(stderr,"popen: Unable to find an open pipe\n");
  921.        errno = EMFILE;
  922.        return(NULL);
  923.        }
  924.    if (strcmp(mode,"r") == 0)
  925.        pmode = MODE_NEWFILE;
  926.    else if (strcmp(mode,"w") == 0)
  927.        pmode = MODE_OLDFILE;
  928.    else {
  929.        fprintf(stderr,"popen: Mode must be 'r' or 'w'\n");
  930.        errno = EINVAL;
  931.        return(NULL);
  932.        }
  933.  
  934.    /* Try to make a guaranteed unique file name for the pipe */
  935.    strcpy(redir,tempname);
  936.    redir[5] = 'a' + i;
  937.  
  938.    pname = mktemp(redir);            /* set up a pipe: file name */
  939.  
  940.    /* Now get the child's stack and priority set up */
  941.    if (cli)
  942.        stacksize = cli->cli_DefaultStack << 2;
  943.    else
  944.        stacksize = thistask->pr_StackSize;
  945.  
  946.    /* Open the side of the pipe for the child */
  947.    pfd = Open(pname,pmode);
  948.    if (pfd == 0) {
  949.        errno = __io2errno(_OSERR = IoErr());
  950.        fprintf(stderr,"popen: Unable to open pipe file\n");
  951.        return(NULL);
  952.        }
  953.  
  954.    /* set up the tags for the new process */
  955.    if (pmode == MODE_NEWFILE) {
  956.        Binfh     = (Tag) Input();
  957.        Boutfh    = (Tag) pfd;
  958.        closeinp  = FALSE;
  959.        closeoutp = TRUE;
  960.        }
  961.    else {
  962.        Binfh     = (Tag) pfd;
  963.        Boutfh    = (Tag) Output();
  964.        closeinp  = TRUE;
  965.        closeoutp = FALSE;
  966.        }
  967.  
  968.    /* create the command.  since the "System" function runs through
  969.       the default shell, we need to tell it not to fail so that we
  970.       ALWAYS get back the exit status.  This wouldn't be necessary
  971.       if the CLI created by the System function inherited the parent's
  972.       FAILAT level
  973.    */
  974.    poptr->childmsg.cmd = malloc(strlen(cmd) + 15);
  975.    strcpy(poptr->childmsg.cmd,"failat 9999\n");
  976.    strcat(poptr->childmsg.cmd,cmd);
  977.  
  978.    /* Create a port that we can get the child's exit status through */
  979.    poptr->childmsg.POm.mn_ReplyPort = CreateMsgPort();
  980.    poptr->childmsg.POm.mn_Node.ln_Type = NT_MESSAGE;
  981.    poptr->childmsg.POm.mn_Node.ln_Pri = 0;
  982.    if (poptr->childmsg.POm.mn_ReplyPort == 0) {
  983.        fprintf(stderr,"popen: Couldn't create message port\n");
  984.        errno = ENOMEM;
  985.        return(NULL);
  986.        }
  987.  
  988.    /* Now we can start the new process.  NOTE: this is actually going
  989.       to create a process consisting ONLY of the function "childprocess"
  990.       which can be seen below.  childprocess() then runs the command
  991.       passed in the startup message.
  992.    */
  993.    child = CreateNewProcTags(
  994.        NP_Entry,   (Tag) childprocess,
  995.        NP_Input,   Binfh,
  996.        NP_Output,  Boutfh,
  997.        NP_CloseInput,  closeinp,
  998.        NP_CloseOutput, closeoutp,
  999.        NP_StackSize,   stacksize,
  1000.        NP_Cli,     TRUE,
  1001.        TAG_DONE
  1002.        );
  1003.  
  1004.    poptr->childmsg.DOSBase = (struct Library *)DOSBase;
  1005.  
  1006.    /* now pass the child the startup message */
  1007.    PutMsg(&child->pr_MsgPort,(struct Message *) &poptr->childmsg);
  1008.  
  1009.    /* Now open our side of the pipe */
  1010.    poptr->fptr = fopen(pname,mode);
  1011.    if (poptr->fptr == NULL) {
  1012.        fprintf(stderr,"popen: Unable to open pipe file %s\n",pname);
  1013.        DeleteMsgPort(poptr->childmsg.POm.mn_ReplyPort);
  1014.        return(NULL);
  1015.        }
  1016.    return(poptr->fptr);
  1017.  
  1018.  
  1019. ILE *popenl(const char *arg0, ...)
  1020.  
  1021.    va_list ap;
  1022.    char argbuf[512], *mode;
  1023.  
  1024.    strcpy(argbuf, arg0);
  1025.    va_start(ap, arg0);
  1026.    while(1)
  1027.    {
  1028.        char *s = va_arg(ap, char *);
  1029.  
  1030.        if(s == NULL)
  1031.        {
  1032.        strcat(argbuf, "\n");
  1033.        break;
  1034.        } /* if */
  1035.  
  1036.        strcat(argbuf, " ");
  1037.  
  1038.        if(strchr(s, ' '))
  1039.        {
  1040.        strcat(argbuf, "\"");
  1041.        strcat(argbuf, s);
  1042.        strcat(argbuf, "\"");
  1043.        }
  1044.        else
  1045.        {
  1046.        strcat(argbuf, s);
  1047.        } /* if */
  1048.    }
  1049.    mode = va_arg(ap, char *);
  1050.    va_end(ap);
  1051.  
  1052.    return(popen(argbuf, mode));
  1053.  
  1054.  /* popenl */
  1055.  
  1056. nt pclose(FILE *fptr)
  1057.  
  1058.    short       i;
  1059.  
  1060.    /* Figure out which pipe we used for this file */
  1061.    for (i=0; i<MAXPIPES; i++)
  1062.        if (poarray[i].fptr == fptr)
  1063.            break;
  1064.    if (i >= MAXPIPES) {
  1065.        fprintf(stderr,"popen: DISASTER...couldn't find file pointer in pclose
  1066. \n");
  1067.        exit(1);
  1068.        }
  1069.  
  1070.    /* close the file */
  1071.    fclose(fptr);
  1072.  
  1073.    /* now wait for the exit status */
  1074.    WaitPort(poarray[i].childmsg.POm.mn_ReplyPort);
  1075.    poarray[i].fptr = NULL;
  1076.  
  1077.    /* clean things up */
  1078.    DeletePort(poarray[i].childmsg.POm.mn_ReplyPort);
  1079.    free(poarray[i].childmsg.cmd);
  1080.    return(poarray[i].childmsg.rc);
  1081.  
  1082.  
  1083. * SAS/C autoinitialization for cleanup! */
  1084. oid __stdargs _STD_4000_popen(void)
  1085.  
  1086.    short i;
  1087.  
  1088.    /* Close all the open pipes! */
  1089.    for(i=0; i<MAXPIPES; i++)
  1090.    {
  1091.        if(poarray[i].fptr)
  1092.        {
  1093.            pclose(poarray[i].fptr);
  1094.        } /* if */
  1095.    } /* for */
  1096.  
  1097.  /* _STD_4000_popen */
  1098.  
  1099. ifdef NOTDEF
  1100.  
  1101. har *mktemp(char * template)
  1102.  
  1103.    register char *cp;
  1104.    register unsigned long val;
  1105.  
  1106.    cp = template;
  1107.    cp += strlen(cp);
  1108.    for (val = (unsigned long) FindTask(0L) ; ; )
  1109.        if (*--cp == 'X') {
  1110.            *cp = val%10 + '0';
  1111.            val /= 10;
  1112.        } else if (*cp != '.')
  1113.            break;
  1114.  
  1115.    if (*++cp != 0) {
  1116.        *cp = 'A';
  1117.        while (access(template, 0) == 0) {
  1118.            if (*cp == 'Z') {
  1119.                *template = 0;
  1120.                break;
  1121.            }
  1122.            ++*cp;
  1123.        }
  1124.    } else {
  1125.        if (access(template, 0) == 0)
  1126.            *template = 0;
  1127.    }
  1128.    return template;
  1129.  
  1130.  
  1131. endif
  1132.  
  1133. * WATCH OUT! This only works without __saveds because of the special
  1134.   SAS/C 6.1 tricks I use! Check the output with omd! */
  1135. tatic int __interrupt childprocess(void)
  1136.  
  1137.    struct ExecBase *SysBase = *((struct ExecBase **)4);
  1138.    struct Library *DOSBase;
  1139.    struct Process  *me;
  1140.    struct POmsg    *startupmsg;
  1141.    int             i = RETURN_FAIL;
  1142.  
  1143.    /* find our process structure */
  1144.    me = (struct Process *) FindTask(NULL);
  1145.  
  1146.    /* Wait for the parent to kick us off */
  1147.    WaitPort(&me->pr_MsgPort);
  1148.  
  1149.    /* Get the command to execute */
  1150.    startupmsg = (struct POmsg *) GetMsg(&me->pr_MsgPort);
  1151.  
  1152.    DOSBase = startupmsg->DOSBase;
  1153.  
  1154.    if(DOSBase)
  1155.    {
  1156.        /* Now run the command.  stdin and stdout are already set up */
  1157.        i = SystemTags(startupmsg->cmd,
  1158.               SYS_UserShell, 1,
  1159.               TAG_DONE);
  1160.    } /* if */
  1161.  
  1162.    if(i > 0)
  1163.    {
  1164.        /* UNIX compatibility ... */
  1165.        i <<= 8;
  1166.    } /* if */
  1167.  
  1168.    startupmsg->rc = i;
  1169.    /* pass the exit code back to the parent */
  1170.    ReplyMsg((struct Message *) startupmsg);
  1171.    return(0);
  1172.  
  1173. net.lib/PrintNetFault                                   net.lib/PrintNetFault
  1174.  
  1175.    NAME
  1176.        PrintNetFault - socket error messages
  1177.  
  1178.    SYNOPSIS
  1179.        PrintNetFault(code, banner)
  1180.        void PrintNetFault(LONG, const UBYTE *)
  1181.  
  1182.    FUNCTION
  1183.        The PrintNetFault() function finds the error message corresponding
  1184.        to the code and writes it, followed by a newline, to the standard
  1185.        error or Output() filehandle. If the argument string is non-NULL it
  1186.        is preappended to the message string and separated from it by a
  1187.        colon and space (`: '). If string is NULL only the error message
  1188.        string is printed.
  1189.  
  1190.    NOTES
  1191.        The PrintNetFault() function uses the DOS IO functions.
  1192.  
  1193.    SEE ALSO
  1194.        strerror(), perror(), <netinclude:sys/errno.h>
  1195.  
  1196. net.lib/PrintUserFault                                 net.lib/PrintUserFault
  1197.  
  1198.    NAME
  1199.        PrintUserFault - socket error messages
  1200.  
  1201.    SYNOPSIS
  1202.        PrintUserFault(code, banner)
  1203.        void PrintUserFault(LONG, const UBYTE *)
  1204.  
  1205.    FUNCTION
  1206.        The PrintUserFault() function finds the error message corresponding to
  1207.        the code and writes it, followed by a newline, to the standard error
  1208.        or Output() filehandle. If the argument string is non-NULL it is
  1209.        preappended to the message string and separated from it by a colon and
  1210.        space (`: '). If string is NULL only the error message string is
  1211.        printed.
  1212.  
  1213.    NOTES
  1214.        The PrintUserFault() function used the DOS io functions.  It is
  1215.        recommended to use PrintUserFault() when the standard C IO functions
  1216.        are not otherwise in use.
  1217.  
  1218.    SEE ALSO
  1219.        strerror(), perror(), <netinclude:sys/errno.h>
  1220.  
  1221. net.lib/rcmd                                                     net.lib/rcmd
  1222.  
  1223.    NAME
  1224.        rcmd, rresvport - routines for returning a stream to a remote command
  1225.  
  1226.    SYNOPSIS
  1227.        #include <clib/socket_protos.h>
  1228.  
  1229.        int rcmd(char **ahost, int inport, const char *locuser, 
  1230.                 const char *remuser, const char *cmd, int *fd2p);
  1231.  
  1232.        int rresvport(int *port);
  1233.  
  1234.    FUNCTION
  1235.        The rcmd() function is used by the super-user to execute a command on
  1236.        a remote machine using an authentication scheme based on reserved port
  1237.        numbers.  The rresvport() function returns a descriptor to a socket
  1238.        with an address in the privileged port space.  Both functions are
  1239.        present in the same file and are used by the rsh command (among
  1240.        others).
  1241.  
  1242.        The rcmd() function looks up the host *ahost using gethostbyname(),
  1243.        returning -1 if the host does not exist.  Otherwise *ahost is set to
  1244.        the standard name of the host and a connection is established to a
  1245.        server residing at the well-known Internet port inport.
  1246.  
  1247.        If the connection succeeds, a socket in the Internet domain of type
  1248.        SOCK_STREAM is returned to the caller, and given to the remote command
  1249.        as stdin and stdout. If fd2p is non-zero, then an auxiliary channel to
  1250.        a control process will be set up, and a descriptor for it will be
  1251.        placed in *fd2p. The control process will return diagnostic output
  1252.        from the command (unit 2) on this channel, and will also accept bytes
  1253.        on this channel as being UNIX signal numbers, to be forwarded to the
  1254.        process group of the command.  If fd2p is 0, then the stderr (unit 2
  1255.        of the remote command) will be made the same as the stdout and no
  1256.        provision is made for sending arbitrary signals to the remote process,
  1257.        although you may be able to get its attention by using out-of-band
  1258.        data.
  1259.  
  1260.        The protocol is described in detail in netutil/rshd.
  1261.  
  1262.        The rresvport() function is used to obtain a socket with a privileged
  1263.        address bound to it.  This socket is suitable for use by rcmd() and
  1264.        several other functions.  Privileged Internet ports are those in the
  1265.        range 0 to 1023.  Only the super-user is allowed to bind an address of
  1266.        this sort to a socket.
  1267.  
  1268.    DIAGNOSTICS
  1269.        The rcmd() function returns a valid socket descriptor on success.  It
  1270.        returns -1 on error and prints a diagnostic message on the standard
  1271.        error.
  1272.  
  1273.        The rresvport() function returns a valid, bound socket descriptor on
  1274.        success.  It returns -1 on error with the global value errno set
  1275.        according to the reason for failure.  The error code EAGAIN is
  1276.        overloaded to mean `All network ports in use.'
  1277.  
  1278.    SEE ALSO
  1279.        netutil/rlogin,  netutil/rsh,  rexec(),  netutil/rexecd,
  1280.        netutil/rlogind, netutil/rshd
  1281.  
  1282. net.lib/serveraccept                                     net.lib/serveraccept
  1283.  
  1284.    NAME
  1285.        serveraccept - Accept a server connection on named port
  1286.  
  1287.    SYNOPSIS
  1288.        socket = serveraccept(name, peer);
  1289.  
  1290.        long serveraccept(char *, struct sockaddr_in *);
  1291.  
  1292.    DESCRIPTION
  1293.        The serveraccept() library call binds a socket to the named Internet
  1294.        TCP port. Then it listens the socket and accepts the connection to
  1295.        the port. The peer's socket address is returned in sockaddr pointed
  1296.        by sockaddr argument.
  1297.  
  1298.        The port name is resolved by getservbyname() call. A numeric value
  1299.        for port name is also accepted.
  1300.  
  1301.        This module is meant for daemon developing.
  1302.  
  1303.    INPUTS
  1304.        name   - port name or numeric string.
  1305.        peer   - pointer to struct sockaddr_in
  1306.  
  1307.    RESULT
  1308.        socket - positive socket id for success or -1 for failure.
  1309.  
  1310.        peer   - sockaddr_in structure containing peer's internet address.
  1311.                 Note that on error, the structure containing peer address
  1312.                 is not necessarily updated.
  1313.  
  1314.    AUTHOR
  1315.        Pekka Pessi, the AmiTCP/IP Group, <amitcp-group@hut.fi>,
  1316.        Helsinki University of Technology, Finland.
  1317.  
  1318.    SEE ALSO
  1319.        bsdsocket/accept, bsdsocket/getservbyname
  1320.  
  1321. net.lib/set_socket_stdio                             net.lib/set_socket_stdio
  1322.  
  1323.    NAME
  1324.        set_socket_stdio - redirect stdio to/from a socket
  1325.  
  1326.    SYNOPSIS
  1327.        int set_socket_stdio(int sock);
  1328.  
  1329.    FUNCTION
  1330.        Redirect stdio (stdin, stdout and stderr) to/from socket 'sock'.
  1331.        This is done by dup2()'ing 'sock' to the level 1 files underneath
  1332.        the stdin, stdout and stderr.
  1333.  
  1334.        The original 'sock' reference is closed on successful return, so
  1335.        the socket descriptor given as argument should not be used after
  1336.        this function returns (successfully).
  1337.  
  1338.    RETURN VALUES
  1339.        0 if successful, -1 on error. Global variable 'errno' contains
  1340.        the specific error code set by the failing function.
  1341.  
  1342.    NOTES
  1343.        This module pulls in the link library stdio modules.
  1344.  
  1345.    AUTHOR
  1346.        Jarno Rajahalme, the AmiTCP/IP Group <amitcp-group@hut.fi>,
  1347.        Helsinki University of Technology, Finland.
  1348.  
  1349.    SEE ALSO
  1350.        dup2()
  1351. net.lib/sleep                                                   net.lib/sleep
  1352.  
  1353.    NAME
  1354.        sleep - suspend process execution for the specified time
  1355.  
  1356.    SYNOPSIS
  1357.        void sleep(unsigned int seconds);
  1358.  
  1359.    FUNCTION
  1360.        Process execution is suspended for number of seconds specified in 
  1361.        'seconds'. The sleep will be aborted if any of the break signals
  1362.        specified for the process is received (only CTRL-C by default).
  1363.  
  1364.    PORTABILITY
  1365.        UNIX
  1366.  
  1367.    INPUTS
  1368.        'seconds' - number of seconds to sleep.
  1369.  
  1370.    RESULT
  1371.        Does not return a value.
  1372.  
  1373.    NOTES
  1374.        The sleep is implemented as a single select() call with all other
  1375.        than time out argument as NULL.
  1376.  
  1377.    SEE ALSO
  1378.        bsdsocket.library/select()
  1379.  
  1380. net.lib/stat                                                     net.lib/stat
  1381.  
  1382.    NAME
  1383.        stat, lstat, fstat - get file status
  1384.  
  1385.    SYNOPSIS
  1386.        #include <sys/types.h>
  1387.        #include <sys/stat.h>
  1388.  
  1389.        success = stat(path, buf)
  1390.  
  1391.        int stat(const char *, struct stat *);
  1392.  
  1393.        success =  lstat(path, buf);
  1394.  
  1395.        int lstat(const char *, struct stat *);
  1396.  
  1397.        success = fstat(fd, buf);
  1398.  
  1399.        int fstat(int, struct stat *);
  1400.  
  1401.    DESCRIPTION
  1402.        The stat() function obtains information about the file pointed to by
  1403.        path. Read, write or execute permission of the named file is not
  1404.        required, but all directories listed in the path name leading to the
  1405.        file must be seachable.
  1406.  
  1407.        Lstat() is like stat() except in the case where the named file is a
  1408.        symbolic link, in which case lstat() returns information about the
  1409.        link, while stat() returns information about the file the link
  1410.        references.
  1411.  
  1412.        The fstat() obtains the same information about an open file known by
  1413.        the file descriptor fd, such as would be obtained by an open call.
  1414.  
  1415.        Buf is a pointer to a stat() structure as defined by <sys/stat.h>
  1416.        (shown below) and into which information is placed concerning the
  1417.        file.
  1418.  
  1419.           struct  stat
  1420.           {
  1421.             dev_t   st_dev;         /* unique device id */ 
  1422.             ino_t   st_ino;         /* inode of file (key block) */ 
  1423.             mode_t  st_mode;        /* Unix style mode */ 
  1424.             ushort  st_nlink;       /* number of links (unimplemented) */ 
  1425.             uid_t   st_uid;         /* owner's user ID */ 
  1426.             gid_t   st_gid;         /* owner's group ID */ 
  1427.             dev_t   st_rdev;        /* special file ID (unimplemented) */ 
  1428.             off_t   st_size;        /* file size */ 
  1429.             time_t  st_atime;       /* Time of last access */ 
  1430.             time_t  st_mtime;       /* Last modification time */ 
  1431.             time_t  st_ctime;       /* Last file status change time */ 
  1432.             long    st_blksize;     /* Size of disk block */ 
  1433.             long    st_blocks;      /* Size in blocks */ 
  1434.             long    st_dosmode;     /* DOS protection bits */ 
  1435.             short   st_type;        /* DOS file type */ 
  1436.             char   *st_comment;     /* DOS file comment */ 
  1437.           };
  1438.  
  1439.        The time-related fields of struct stat have same contents, time when
  1440.        file data last modified.
  1441.  
  1442.        The status information word st_mode has bits as follows:
  1443.  
  1444.          #define S_ISUID  0004000    /* set user id on execution */ 
  1445.          #define S_ISGID  0002000    /* set group id on execution */ 
  1446.          #define S_ISVTX  0001000    /* save swapped text even after use */ 
  1447.          #define S_IRUSR  0000400    /* read permission for owner */ 
  1448.          #define S_IWUSR  0000200    /* write permission for owner */ 
  1449.          #define S_IXUSR  0000100    /* execute permission for owner */ 
  1450.          #define S_IRGRP  0000040    /* read permission for group */ 
  1451.          #define S_IWGRP  0000020    /* write permission for group */ 
  1452.          #define S_IXGRP  0000010    /* execute permission for group */ 
  1453.          #define S_IROTH  0000004    /* read permission for other */ 
  1454.          #define S_IWOTH  0000002    /* write permission for other */ 
  1455.          #define S_IXOTH  0000001    /* execute permission for other */ 
  1456.          #define S_IFCHR  0020000    /* character special */ 
  1457.          #define S_IFDIR  0040000    /* directory */ 
  1458.          #define S_IFBLK  0060000    /* block special */ 
  1459.          #define S_IFREG  0100000    /* regular */ 
  1460.          #define S_IFLNK  0120000    /* symbolic link */ 
  1461.          #define S_IFSOCK 0140000    /* socket */ 
  1462.          #define S_IFIFO  0010000    /* named pipe (fifo) */ 
  1463.  
  1464.        For a list of access modes, see <sys/stat.h>, access(2) and chmod(2).
  1465.  
  1466.    RETURN VALUES
  1467.        Upon successful completion a value of 0 is returned.  Otherwise, a
  1468.        value of -1 is returned and errno is set to indicate the error.
  1469.  
  1470.    ERRORS
  1471.        The functions stat() and lstat() will fail if:
  1472.  
  1473.        [ENOTDIR]       A component of the path prefix is not a directory.
  1474.  
  1475.        [ENAMETOOLONG]  A component of a pathname exceeded 255 characters,
  1476.                        or an entire path name exceeded 1023 characters.
  1477.  
  1478.        [ENOENT]        The named file does not exist.
  1479.  
  1480.        [ELOOP]         Too many symbolic links were encountered in
  1481.                        translating the pathname.
  1482.  
  1483.        [EACCES]        Search permission is denied for a component of the
  1484.                        path prefix.
  1485.  
  1486.        [EFAULT]        Buf or name points to an invalid address.
  1487.  
  1488.        [EIO]           An I/O error occurred while reading from or writing
  1489.                        to the file system.
  1490.  
  1491.        The function fstat() will fail if:
  1492.  
  1493.        [EBADF]   fd is not a valid open file descriptor.
  1494.  
  1495.        [EFAULT]  Buf points to an invalid address.
  1496.  
  1497.        [EIO]     An I/O error occurred while reading from or writing to the
  1498.                  file system.
  1499.  
  1500.    SEE ALSO
  1501.        chmod(),  chown()
  1502.  
  1503.    BUGS 
  1504.        Applying fstat to a socket returns a zero'd buffer.
  1505.  
  1506. net.lib/strerror                                             net.lib/strerror
  1507.  
  1508.    NAME
  1509.        strerror -- return the text for given error number
  1510.  
  1511.    SYNOPSIS
  1512.        string = strerror(error);
  1513.  
  1514.        char * strerror(int);
  1515.  
  1516.    FUNCTION
  1517.        This function returns pointer to the (English) string describing the
  1518.        error code given as argument. The error strings are defined for the
  1519.        error codes defined in <sys/errno.h>.
  1520.  
  1521.    NOTES
  1522.        The string pointed to by the return value should not be modified by
  1523.        the program, but may be overwritten by a subsequent call to this
  1524.        function.
  1525.  
  1526.    BUGS
  1527.        The strerror() prototype should be 
  1528.        const char *strerror(unsigned int); 
  1529.        However, the SAS C includes define it differently.
  1530.  
  1531.    SEE ALSO
  1532.        <netinclude:sys/errno.h>, perror(), PrintNetFault()
  1533. net.lib/syslog                                                 net.lib/syslog
  1534.  
  1535.    NAME   
  1536.        openlog(), closelog(), setlogmask() -- syslog utility functions
  1537.  
  1538.    SYNOPSIS
  1539.        #include <syslog.h>
  1540.        
  1541.        openlog(ident, logopt, facility);
  1542.  
  1543.        void openlog(const char *, int, int);
  1544.  
  1545.        closelog();
  1546.  
  1547.        void closelog(void);
  1548.  
  1549.        oldmask = setlogmask(maskpri);
  1550.        
  1551.        int setlogmask(int);
  1552.        
  1553.    FUNCTION
  1554.        openlog() can be called to initialize the log file, if special
  1555.        processing is needed.  ident is a string that precedes every
  1556.        message.  logopt is a mask of bits, logically OR'ed together,
  1557.        indicating logging options.  The values for logopt are:
  1558.        
  1559.             LOG_PID             Log the process ID with each message;
  1560.                                 useful for identifying instantiations
  1561.                                 of daemons.
  1562.  
  1563.             LOG_CONS            Force writing messages to the console
  1564.                                 if unable to send it to syslogd.
  1565.                                 This option is safe to use in daemon
  1566.                                 processes that have no controlling
  1567.                                 terminal because syslog() forks
  1568.                                 before opening the console.
  1569.  
  1570.             LOG_NDELAY          Open the connection to syslogd
  1571.                                 immediately.  Normally, the open is
  1572.                                 delayed until the first message is
  1573.                                 logged.  This is useful for programs
  1574.                                 that need to manage the order in
  1575.                                 which file descriptors are allocated.
  1576.  
  1577.             LOG_NOWAIT          Do not wait for children forked to
  1578.                                 log messages on the console. Obsolete
  1579.                                 in AmiTCP/IP, since AmiTCP/IP does
  1580.                                 not fork.
  1581.  
  1582.        facility encodes a default facility to be assigned to all
  1583.        messages written subsequently by syslog() with no explicit
  1584.        facility encoded. The facility codes are:
  1585.  
  1586.             LOG_KERN            Messages generated by the kernel.
  1587.                                 These cannot be generated by any user
  1588.                                 processes.
  1589.  
  1590.             LOG_USER            Messages generated by random user
  1591.                                 processes.  This is the default
  1592.                                 facility identifier if none is
  1593.                                 specified.
  1594.  
  1595.             LOG_MAIL            The mail system.
  1596.  
  1597.             LOG_DAEMON          System daemons, such as inetd, ftpd,
  1598.                                 etc.
  1599.  
  1600.             LOG_AUTH            The authorization system: login, su,
  1601.                                 getty, etc.
  1602.  
  1603.             LOG_LPR             The line printer spooling system: lp,
  1604.                                 lpsched, etc.
  1605.  
  1606.             LOG_LOCAL0          Reserved for local use. Similarly for
  1607.                                 LOG_LOCAL1 through LOG_LOCAL7.
  1608.  
  1609.  
  1610.        closelog() closes the log file.
  1611.  
  1612.        setlogmask() sets the log priority mask to maskpri and returns
  1613.        the previous mask.  Calls to syslog() with a priority not set
  1614.        in maskpri are rejected.  The mask for an individual priority
  1615.        pri is calculated by the macro LOG_MASK(pri); the mask for all
  1616.        priorities up to and including toppri is given by the macro
  1617.        LOG_UPTO(toppri).  By default, all priorities are logged.
  1618.  
  1619.    EXAMPLES
  1620.        who logs a message regarding some sort of unexpected and
  1621.        serious error:
  1622.  
  1623.            syslog(LOG_ALERT, "who: internal error 23");
  1624.  
  1625.        ftpd uses openlog() to arrange to log its process ID, to log
  1626.        to the console if necessary, and to log in the name of the
  1627.        daemon facility:
  1628.  
  1629.            openlog("ftpd", LOG_PID|LOG_CONS, LOG_DAEMON);
  1630.  
  1631.        Arrange to log messages only at levels LOG_ERR and lower:
  1632.  
  1633.            setlogmask(LOG_UPTO(LOG_ERR));
  1634.  
  1635.        Typical usage of syslog() to log a connection:
  1636.  
  1637.            syslog(LOG_INFO, "Connection from host %d", CallingHost);
  1638.  
  1639.        If the facility has not been set with openlog(), it defaults
  1640.        to LOG_USER.
  1641.  
  1642.        Explicitly set the facility for this message:
  1643.  
  1644.            syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
  1645.        
  1646.    NOTES
  1647.        openlog() does not copy and store the ident string internally;
  1648.        it stores only the character pointer.  Therefore it is the
  1649.        responsibility of the programmer to make sure that the ident
  1650.        argument points to the correct string while syslog() is being
  1651.        called. 
  1652.  
  1653.    BUGS
  1654.        Most of the logopt and facility codes are currently being
  1655.        ignored by AmiTCP/IP, but they should be used for future
  1656.        compatibility.
  1657.  
  1658.        The autoinit module of the net.lib tells the program name 
  1659.        to the AmiTCP/IP at program startup, so use of the openlog()
  1660.        for that purpose only is not necessary.
  1661.  
  1662.    AUTHOR
  1663.        syslog() was developed by the University of California,
  1664.        Berkeley.
  1665.  
  1666.    SEE ALSO
  1667.        bsdsocket.library/syslog(), bsdsocket.library/SocketBaseTagList()
  1668. net.lib/usleep                                                 net.lib/usleep
  1669.  
  1670.    NAME
  1671.        usleep - suspend process execution for the specified time
  1672.  
  1673.    SYNOPSIS
  1674.        void usleep(unsigned int microseconds);
  1675.  
  1676.    FUNCTION
  1677.        Process execution is suspended for number of microseconds
  1678.        specified in 'microseconds'. The sleep will be aborted if any
  1679.        of the break signals specified for the process is received
  1680.        (only CTRL-C by default).
  1681.  
  1682.    PORTABILITY
  1683.        UNIX
  1684.  
  1685.    INPUTS
  1686.        'microseconds' - number of microseconds to sleep.
  1687.  
  1688.    RESULT
  1689.        Does not return a value.
  1690.  
  1691.    NOTES
  1692.        The sleep is implemented as a single select() call with all other
  1693.        than time out argument as NULL.
  1694.  
  1695.    SEE ALSO
  1696.        bsdsocket.library/select()
  1697.  
  1698. net.lib/utime                                                   net.lib/utime
  1699.  
  1700.    NAME
  1701.        utime - set file access and modification times
  1702.  
  1703.    SYNOPSIS
  1704.        #include <utime.h>
  1705.  
  1706.        int error = utime(const char *name, const struct utimbuf *times)
  1707.  
  1708.    FUNCTION
  1709.        The access and modification times for the file 'name' are modified
  1710.        according to the 'times'. If 'times' is NULL, the times are set to
  1711.        systems current time.
  1712.  
  1713.    PORTABILITY
  1714.        UNIX
  1715.  
  1716.    INPUTS
  1717.        'name'  - the name of the file to be affected.
  1718.  
  1719.        'times' - pointer to a structure containing the time values,
  1720.                  defined in <utime.h> as:
  1721.  
  1722.                      struct utimbuf {
  1723.                          time_t actime;        /* Access time */
  1724.                          time_t modtime;        /* Modification time */
  1725.                      };
  1726.  
  1727.                  Both times are in units of seconds since Jan. 1, 1970,
  1728.                  Greenwich Mean Time.
  1729.  
  1730.                  If the 'times' is given as the NULL pointer, the current
  1731.                  time is used.
  1732.  
  1733.    RESULT
  1734.        Returns 0 when successful and -1 with specific error code in errno in
  1735.        case of an error.
  1736.  
  1737.    NOTES
  1738.        Since AmigaDOS files have only one time stamp, both access and
  1739.        modification times cannot be supported. Since the AmigaDOS file date
  1740.        is the modification time, only the 'modtime' field of the 'times' is
  1741.        used.
  1742.  
  1743.        The conversion from 1.1.1970 based GMT to 1.1.1978 based local time is
  1744.        done with external long __local_to_GMT, which is defined and
  1745.        initialized by the timerinit.c module included in the net.lib.
  1746.  
  1747.    SEE ALSO
  1748.        dos.library/DateStamp(), dos.library/SetFileDate(), net.lib/timerinit
  1749.  
  1750.