13 net.lib/init_inet_daemon
20 net.lib/PrintUserFault
25 net.lib/set_socket_stdio
35 \fnet.lib/charRead net.lib/charRead
38 charRead -- read characters from socket one by one.
43 void initCharRead(struct CharRead *, int);
46 character = charRead(rc)
48 int charRead(struct CharRead *);
52 charRead is a macro package which return characters one by one
53 from given socket input stream. The socket where data is to be read
54 is set by calling initCharRead(): rc is the pointer to charread
55 structure previously allocated. fd is the (socket) descriptor where
56 reading is to be done.
58 charRead() returns the next character from input stream or one of
61 RC_DO_SELECT (-3) - read input buffer is returned. Do select
62 before next call if you don't want charread
65 RC_EOF (-2) - end-of-file condition has occurred.
67 RC_ERROR (-1) - there has been an error while filling new
68 charread buffer. Check the value of Errno()
71 Always use variable of type int to store return value from charRead()
72 since the numeric value of characters returned may vary between
73 0 -255 (or even greater). As you may know, -3 equals 253 if of type
78 * This piece of code shows how to use charread with select()
80 #include <sys/types.h>
81 #include <sys/socket.h>
90 initCharRead(&rc, sock);
95 FD_SET(sock, &readfds);
97 if (select(sock + 1. &readfds, NULL, NULL, NULL)) < 0) {
101 if (FD_ISSET(sock, &readfds)) {
102 while((c = charRead(&rc)) >= 0)
103 handle_next_input_character(c);
115 The source file charread.h should be able to be used in
119 lineRead(), bsdsocket.library/recv()
120 \fnet.lib/chmod net.lib/chmod
123 chmod, fchmod - change mode of file
126 #include <sys/stat.h>
128 int chmod(const char *path, mode_t mode);
130 int fchmod(int fd, mode_t mode);
133 The function chmod() sets the file permission bits of the file
134 specified by the pathname path to mode. Fchmod() sets the permission
135 bits of the specified file descriptor fd. Chmod() verifies that the
136 process owner (user) either owns the file specified by path (or fd),
137 or is the super-user. A mode is created from or'd permission bit
138 masks defined in <sys/stat.h>:
140 #define S_IRWXU 0000700 /* RWX mask for owner */
141 #define S_IRUSR 0000400 /* R for owner */
142 #define S_IWUSR 0000200 /* W for owner */
143 #define S_IXUSR 0000100 /* X for owner */
145 #define S_IRWXG 0000070 /* RWX mask for group */
146 #define S_IRGRP 0000040 /* R for group */
147 #define S_IWGRP 0000020 /* W for group */
148 #define S_IXGRP 0000010 /* X for group */
150 #define S_IRWXO 0000007 /* RWX mask for other */
151 #define S_IROTH 0000004 /* R for other */
152 #define S_IWOTH 0000002 /* W for other */
153 #define S_IXOTH 0000001 /* X for other */
155 #define S_ISUID 0004000 /* set user id on execution */
156 #define S_ISGID 0002000 /* set group id on execution */
157 #define S_ISVTX 0001000 /* save swapped text even after use *
160 The ISVTX (the sticky bit) indicates to the system which executable
161 files are shareable (pure).
163 Writing or changing the owner of a file turns off the set-user-id
164 and set-group-id bits unless the user is the super-user. This makes
165 the system somewhat more secure by protecting set-user-id
166 (set-group-id) files from remaining set-user-id (set-group-id) if
170 Upon successful completion, a value of 0 is returned. Otherwise, a
171 value of -1 is returned and errno is set to indicate the error.
174 Chmod() will fail and the file mode will be unchanged if:
176 [ENOTDIR] A component of the path prefix is not a directory.
179 A component of a pathname exceeded 255 characters, or
180 an entire path name exceeded 1023 characters.
182 [ENOENT] The named file does not exist.
184 [EACCES] Search permission is denied for a component of the
187 [EPERM] The effective user ID does not match the owner of the
188 file and the effective user ID is not the super-user.
190 [EROFS] The named file resides on a read-only file system.
192 [EFAULT] Path points outside the process's allocated address
195 [EIO] An I/O error occurred while reading from or writing to
198 Fchmod() will fail if:
200 [EBADF] The descriptor is not valid.
202 [EINVAL] Fd refers to a socket, not to a file.
204 [EROFS] The file resides on a read-only file system.
206 [EIO] An I/O error occurred while reading from or writing to
210 This call is provided for Unix compatibility. It does not know all
211 Amiga protection bits (Delete, Archive, Script). The archive and
212 script bits are cleared, Delete set according the Write bit.
215 open(), chown(), stat()
217 \fnet.lib/chown net.lib/chown
220 chown - change owner and group of a file
225 success = chown(path, owner, group)
227 int chown(const char *, uid_t, gid_t);
230 The owner ID and group ID of the file named by path or referenced by
231 fd is changed as specified by the arguments owner and group. The
232 owner of a file may change the group to a group of which he or she is
233 a member, but the change owner capability is restricted to the
236 Chown() clears the set-user-id and set-group-id bits on the file to
237 prevent accidental or mischievious creation of set-user-id and
238 set-group-id programs.
240 One of the owner or group id's may be left unchanged by specifying it
243 If the final component of path is a symbolic link, the ownership and
244 group of the symbolic link is changed, not the ownership and group of
245 the file or directory to which it points.
248 Zero is returned if the operation was successful; -1 is returned if an
249 error occurs, with a more specific error code being placed in the
250 global variable errno.
253 Chown() will fail and the file will be unchanged if:
255 [ENOTDIR] A component of the path prefix is not a directory.
257 [EINVAL] The pathname contains a character with the high-order
261 A component of a pathname exceeded 80 characters, or an
262 entire path name exceeded 1023 characters.
264 [ENOENT] The named file does not exist.
266 [EACCES] Search permission is denied for a component of the path
269 [ELOOP] Too many symbolic links were encountered in translating
272 [EPERM] The effective user ID is not the super-user.
274 [EROFS] The named file resides on a read-only file system.
276 [EFAULT] Path points outside the process's allocated address
279 [EIO] An I/O error occurred while reading from or writing to
285 \fnet.lib/dup net.lib/dup
288 dup, dup2 - duplicate an existing file descriptor
295 int dup2(int oldd, int newd)
298 Dup() duplicates an existing object descriptor and returns its value
299 to the calling program (newd = dup(oldd)). The argument oldd is a
300 small nonnegative integer index in the program's descriptor table.
301 The value must be less than the size of the table, which is returned
302 by getdtablesize(). The new descriptor returned by the call is the
303 lowest numbered descriptor currently not in use by the program.
305 The object referenced by the descriptor does not distinguish between
306 oldd and newd in any way. Thus if newd and oldd are duplicate
307 references to an open file, read() and write() calls all move a single
308 pointer into the file, and append mode, non-blocking I/O and
309 asynchronous I/O options are shared between the references. If a
310 separate pointer into the file is desired, a different object
311 reference to the file must be obtained by issuing an additional open()
312 call. The close-on-exec flag on the new file descriptor is unset.
314 In dup2(), the value of the new descriptor newd is specified. If this
315 descriptor is already in use, the descriptor is first deallocated as
316 if a close() call had been done first.
319 The value -1 is returned if an error occurs in either call. The
320 external variable errno indicates the cause of the error.
323 The current UFB implementation for SAS C allows only sockets to be
327 Dup() and dup2() fail if:
329 [EBADF] Oldd or newd is not a valid active descriptor
331 [EMFILE] Too many descriptors are active.
334 accept(), open(), close(), socket(), getdtablesize()
337 Dup() and dup2() are expected to conform to IEEE Std 1003.1-1988
341 This manual page is copyright © 1980, 1991 Regents of the
342 University of California. All rights reserved.
344 \fnet.lib/dup2 net.lib/dup2
347 \fnet.lib/fstat net.lib/fstat
352 \fnet.lib/getpid net.lib/getpid
355 getpid - get calling process identification
361 Getpid() returns the process ID of the calling process. The
362 ID is guaranteed to be unique and is useful for constructing temporary
366 In AmigaOS process ID is the same as pointer to its context descriptor
367 returned by FindTask(NULL). This function is provided for direct POSIX
371 getppid(), kill(), bsdsocket.library/gethostid(),
372 exec.library/FindTask()
374 \fnet.lib/getppid net.lib/getppid
377 getppid - get parent process identification
383 Getppid() returns the process ID of the parent of the calling process.
386 This function is availible only in MorphOS and AROS operating systems.
387 m68k AmigaOS 3.x does not have a meaning of parent process.
390 getpid(), kill(), bsdsocket.library/gethostid(),
391 exec.library/FindTask()
393 \fnet.lib/gettimeofday net.lib/gettimeofday
396 gettimeofday - get date and time
399 #include <sys/time.h>
401 error = gettimeofday(tp, tzp)
403 int gettimeofday(struct timeval *, struct timezone *)
406 The system's notion of the current Greenwich time and the
407 current time zone is obtained with the gettimeofday() call.
408 The time is expressed in seconds and microseconds since
409 midnight (0 hour), January 1, 1970. The resolution of the
410 system clock is hardware dependent. If tzp is zero, the time
411 zone information will not be returned. Also, if your system
412 software is unable to provide time zone information, the
413 structure pointed by tzp will be filled with zeroes.
419 The structures pointed to by tp and tzp are defined in
423 long tv_sec; /* seconds since Jan. 1, 1970 */
424 long tv_usec; /* and microseconds */
428 int tz_minuteswest; /* of Greenwich */
429 int tz_dsttime; /* type of dst correction to apply */
432 The timezone structure indicates the local time zone (meas-
433 ured in minutes of time westward from Greenwich), and a flag
434 that, if nonzero, indicates that Daylight Saving time
435 applies locally during the appropriate part of the year.
438 Returns 0 when successful and -1 with specific error code in
439 errno in case of an error. No error codes are specified,
443 gettimeofday() uses GetSysTime() function of the timer.device,
444 which is new to V36 of the device.
446 Time zone information is taken from the locale.library, if it
447 is available (it is included in all Amiga systems from 2.1 and
448 up). Otherwise the environment variable "TZ" is consulted. If
449 it fails, the time zone is initialized to the GMT.
451 Global variable TimerBase _must_ be initialized before
452 gettimeofday() is called. This is normally done automatically
453 by the autoinit module (timerinit.c) included in the net.lib.
456 timer.device/GetSysTime()
457 \fnet.lib/herror net.lib/herror
460 herror - print name resolver error message to stderr.
463 #include <clib/netlib_protos.h>
466 void herror(const char *)
469 The herror() function finds the error message corresponding to the
470 current value of host error using the SocketBaseTags() and writes
471 it, followed by a newline, to the stderr. If the argument string
472 is non-NULL it is used as a prefix to the message string and
473 separated from it by a colon and space (`: '). If the argument is
474 NULL only the error message string is printed.
477 The herror() function requires the stdio functions to be linked.
480 <netinclude:netdb.h>, SocketBaseTagList(), perror()
482 \fnet.lib/init_inet_daemon net.lib/init_inet_daemon
485 init_inet_daemon - obtain socket accepted by the inetd
488 int init_inet_daemon(void);
491 Obtain the server socket accepted by the inetd, the Internet
495 socket descriptor if successful, -1 with specific error code
499 ENXIO - The process was not started by the inetd.
502 If the process was started by the inetd, but the ObtainSocket()
503 call fails, then this function exit()s with some specific exit
504 code, so that inetd can clean up the unobtained socket.
506 Use the net.lib function set_socket_stdio() to redirect stdio,
507 stdout and stderr to the returned socket, if necessary.
510 serveraccept(), set_socket_stdio(), bsdsocket/ObtainSocket(),
513 \fnet.lib/kill net.lib/kill
516 kill - send signal to a process
519 int kill(pid_t pid, int sig);
522 The kill() function sends the signal given by sig to pid, a
523 process or a group of processes. Sig may be one of the signals
524 specified in <signal.h> or it may be 0, in which case error
525 checking is performed but no signal is actually sent. This can
526 be used to check the validity of pid.
529 'pid' - a process ID to perform action on.
530 'sig' - can be 0 of one of the following values defined in the include
533 NAME Action in AmigaOS UNIX functionality
534 SIGHUP not implemented terminal line hangup
535 SIGINT not implemented interrupt program
536 SIGQUIT not implemented quit program
537 SIGILL not implemented illegal instruction
538 SIGTRAP not implemented trace trap
539 SIGABRT not implemented abort() call (formerly SIGIOT)
540 SIGEMT not implemented emulate instruction executed
541 SIGFPE not implemented floating-point exception
542 SIGKILL not implemented kill program
543 SIGBUS not implemented bus error
544 SIGSEGV not implemented segmentation violation
545 SIGSYS not implemented system call given invalid
547 SIGPIPE not implemented write on a pipe with no reader
548 SIGALRM not implemented real-time timer expired
549 SIGTERM send CTRL-C to the software termination signal
551 SIGURG not implemented urgent condition present on
553 SIGSTOP not implemented stop (cannot be caught or
555 SIGTSTP not implemented stop signal generated from
557 SIGCONT not implemented continue after stop
558 SIGCHLD not implemented child status has changed
559 SIGTTIN not implemented background read attempted from
561 SIGTTOU not implemented background write attempted to
563 SIGIO not implemented I/O is possible on a descriptor
564 SIGXCPU not implemented cpu time limit exceeded
565 SIGXFSZ not implemented file size limit exceeded
566 SIGVTALRM not implemented virtual time alarm
567 SIGPROF not implemented profiling timer alarm
568 SIGWINCH not implemented Window size change
569 SIGINFO not implemented status request from keyboard
570 SIGUSR1 not implemented User defined signal 1
571 SIGUSR2 not implemented User defined signal 2
574 Upon successful completion, a value of 0 is returned.
575 Otherwise, a value of -1 is returned and errno is set to
579 Only SIGTERM is currently supported. Other signals will give
583 Kill() will fail and no signal will be sent if:
585 [EINVAL] Sig is not a valid signal number.
587 [ESRCH] No process can be found corresponding to that
593 \fnet.lib/lineRead net.lib/lineRead
596 lineRead -- read newline terminated strings from socket
599 initLineRead(rl, fd, lftype, bufsize)
601 void initLineRead(struct LineRead *, int, int, int);
604 length = lineRead(rl)
606 int lineread(struct LineRead *);
610 lineRead() reads newline terminated strings from given descriptor
611 very efficiently. All the options needed are set by calling
612 initLineRead(): rl is the pointer to lineread structure previously
613 allocated. fd is the (socket) descriptor where reading is to be
614 done. lftype can have following 3 values:
616 RL_LFNOTREQ - Newline terminated strings are returned unless
617 there is no newlines left in currently buffered
618 input. In this case remaining buffer is returned.
620 RL_LFREQLF - If there is no newlines left in currently buffered
621 input the remaining input data is copied at the
622 start of buffer. Caller is informed that next
623 call will fill the buffer (and it may block).
624 Lines are always returned with newline at the end
625 unless the string is longer than whole buffer.
627 RL_LFREQNUL - Like LF_REQLF, but remaining newline is removed.
628 Note here that lenght is one longer that actual
629 string length since line that has only one
630 newline at the end would return length as 0
631 which indigate string incomplete condition.
633 bufsize is used to tell lineread how big the receive buffer is.
634 always put RL_BUFSIZE here since that value is used to determine
635 the memory allocated for the buffer. This option is given to you
636 so you may decide to use different buffer size than the default
639 lineRead() returns the newline terminated string in rl_line field
640 of lineread structure. Return values of lineRead() are:
642 1 - RL_BUFSIZE - normal length of returned string.
644 0 - If zero is returned just after select(),
645 end-of-file condition has occurred.
646 Otherwise string is not completed yet.
647 Make sure you call select() (or use non-
648 blocking IO) if you don't want next call
651 -1 - if rl_Line field of lineread structure
652 is NULL, it indicates error condition.
653 If rl_Line points to start of string
654 buffer, input string has been longer
655 than buffer. In this case rl_Line points
656 to zero terminated string of length
659 You may modify the zero terminated string returned by lineRead() in
660 any way, but memory around the string is private lineread memory.
664 * The following code shows how to use lineread with select()
666 #ifdef USE_LOW_MEMORY_BUFFER
667 #define RL_BUFSIZE 256
670 #include <sys/types.h>
672 #include <bsdsocket.h>
674 #include <lineread.h>
682 struct LineRead * rl;
686 if (rl = (struct LineRead *)AllocMem(sizeof (*rl), 0)) {
688 initLineRead(rl, sock, LF_REQLF, RL_BUFSIZE);
693 FD_SET(sock, &readfds);
695 if (select(sock + 1, &readfds, NULL, NULL, NULL)) < 0) {
699 if (FD_ISSET(sock, &readfds))
700 if ((length = lineRead(rl)) == 0) /* EOF */
704 write(1, rl->rl_Line, length); /* stdout. write() for */
705 /* speed demonstration */
706 else { /* length == -1 */
707 if (rl->rl_Line == NULL); {
712 fprintf(stderr, "lineread input buffer overflow!\n");
713 write(1, rl->rl_Line, RL_BUFSIZE);
717 } while ((length = lineRead(rl)) != 0); /* 0 -> do select() */
719 FreeMem(rl, sizeof (*rl);
722 fprintf("AllocMem: Out Of memory\n");
726 The source modules lineread.c and lineread.h should compile
727 in UNIX machines as is.
730 charRead(), bsdsocket.library/recv()
732 \fnet.lib/lstat net.lib/lstat
737 \fnet.lib/perror net.lib/perror
740 perror - socket error messages
748 void perror(const char *)
751 The perror() function finds the error message corresponding to the
752 current value of the global variable errno and writes it, followed
753 by a newline, to the stderr. If the argument string is non-NULL it
754 is preappended to the message string and separated from it by a
755 colon and space (`: '). If string is NULL only the error message
759 The perror() function requires the stdio functions to be linked.
762 strerror(), PrintNetFault(), <netinclude:sys/errno.h>
764 \fnet.lib/popen net.lib/popen
766 popen, pclose - initiate I/O to/from a process
771 FILE *popen(command, type)
772 char *command, *type;
778 The arguments to popen are pointers to null-terminated
779 strings containing respectively a command line and an
780 I/O mode, either "r" for reading or "w" for writing. It
781 creates a pipe between the calling process and the command
782 to be executed. The value returned is a stream pointer that
783 can be used (as appropriate) to write to the standard input
784 of the command or read from its standard output.
786 A stream opened by popen **MUST** be closed by pclose, which
787 waits for the associated process to terminate and returns
788 the exit status of the command.
790 Because stdio files are shared, a type "r" command may be
791 used as an input filter, and a type "w" as an output filter.
794 Popen returns a null pointer if files or processes cannot be
797 Pclose returns -1 if stream is not associated with a
801 Original version by Rick Schaeffer <ricks@isc-br.isc-br.com>
809 include <exec/types.h>
810 include <exec/memory.h>
812 include <dos/dosextens.h>
813 include <dos/record.h>
814 include <dos/dostags.h>
816 include <proto/exec.h>
817 include <proto/dos.h>
818 include <clib/alib_protos.h>
824 xtern char *mktemp(char *);
830 struct Library *DOSBase;
836 struct POmsg childmsg;
840 tatic struct pstruct poarray[MAXPIPES] = { 0 };
842 tatic int childprocess(void);
844 ILE *popen(const char *cmd, const char *mode)
846 static char tempname[] = "pipe:pXXX.XXX";
847 char *pname,redir[20];
850 struct pstruct *poptr;
851 struct Process *child;
852 struct CommandLineInterface *cli;
854 struct Process *thistask;
857 /* First, get pointers to our process and cli structs */
858 thistask = (struct Process *) FindTask(NULL);
862 /* now find an open pipe (we currently only allow 6 simultaneously
864 for (i=0; i<MAXPIPES; i++) {
865 if (poarray[i].fptr == NULL) {
871 fprintf(stderr,"popen: Unable to find an open pipe\n");
875 if (strcmp(mode,"r") == 0)
876 pmode = MODE_NEWFILE;
877 else if (strcmp(mode,"w") == 0)
878 pmode = MODE_OLDFILE;
880 fprintf(stderr,"popen: Mode must be 'r' or 'w'\n");
885 /* Try to make a guaranteed unique file name for the pipe */
886 strcpy(redir,tempname);
889 pname = mktemp(redir); /* set up a pipe: file name */
891 /* Now get the child's stack and priority set up */
893 stacksize = cli->cli_DefaultStack << 2;
895 stacksize = thistask->pr_StackSize;
897 /* Now open our side of the pipe */
898 fptr = fopen(pname,mode);
900 fprintf(stderr,"popen: Unable to open pipe file %s\n",pname);
904 /* create the command. since the "System" function runs through
905 the default shell, we need to tell it not to fail so that we
906 ALWAYS get back the exit status. This wouldn't be necessary
907 if the CLI created by the System function inherited the parent's
909 The pipe file is passed as redirection to shell, which the
910 SystemTags() will parse. For some reason the default "more"
911 could not get it's input properly if redirection was not used.
913 poptr->childmsg.cmd = malloc(strlen(cmd) + 15 + 20);
914 sprintf(poptr->childmsg.cmd, "failat 9999\n%s %c%s\n",
915 cmd, (pmode == MODE_NEWFILE) ? '>' : '<', pname);
917 /* Create a port that we can get the child's exit status through */
918 poptr->childmsg.POm.mn_ReplyPort = CreateMsgPort();
919 poptr->childmsg.POm.mn_Node.ln_Type = NT_MESSAGE;
920 poptr->childmsg.POm.mn_Node.ln_Pri = 0;
921 if (poptr->childmsg.POm.mn_ReplyPort == 0) {
923 fprintf(stderr,"popen: Couldn't create message port\n");
928 /* Now we can start the new process. NOTE: this is actually going
929 to create a process consisting ONLY of the function "childprocess"
930 which can be seen below. childprocess() then runs the command
931 passed in the startup message.
933 child = CreateNewProcTags(
934 NP_Entry, (Tag) childprocess,
937 NP_CloseInput, FALSE,
938 NP_CloseOutput, FALSE,
939 NP_StackSize, stacksize,
944 poptr->childmsg.DOSBase = (struct Library *)DOSBase;
946 /* now pass the child the startup message */
947 PutMsg(&child->pr_MsgPort,(struct Message *) &poptr->childmsg);
949 return(poptr->fptr = fptr);
952 ILE *popenl(const char *arg0, ...)
955 char argbuf[512], *mode;
957 strcpy(argbuf, arg0);
961 char *s = va_arg(ap, char *);
965 strcat(argbuf, "\n");
973 strcat(argbuf, "\"");
975 strcat(argbuf, "\"");
982 mode = va_arg(ap, char *);
985 return(popen(argbuf, mode));
989 nt pclose(FILE *fptr)
993 /* Figure out which pipe we used for this file */
994 for (i=0; i<MAXPIPES; i++)
995 if (poarray[i].fptr == fptr)
998 fprintf(stderr,"popen: DISASTER...couldn't find file pointer in pclose
1003 /* close the file */
1006 /* now wait for the exit status */
1007 WaitPort(poarray[i].childmsg.POm.mn_ReplyPort);
1008 poarray[i].fptr = NULL;
1010 /* clean things up */
1011 DeletePort(poarray[i].childmsg.POm.mn_ReplyPort);
1012 free(poarray[i].childmsg.cmd);
1013 return(poarray[i].childmsg.rc);
1016 * SAS/C autoinitialization for cleanup! */
1017 oid __stdargs _STD_4000_popen(void)
1021 /* Close all the open pipes! */
1022 for(i=0; i<MAXPIPES; i++)
1026 pclose(poarray[i].fptr);
1030 /* _STD_4000_popen */
1034 har *mktemp(char * template)
1037 register unsigned long val;
1041 for (val = (unsigned long) FindTask(0L) ; ; )
1045 } else if (*cp != '.')
1050 while (access(template, 0) == 0) {
1058 if (access(template, 0) == 0)
1066 * WATCH OUT! This only works without __saveds because of the special
1067 SAS/C 6.1 tricks I use! Check the output with omd! */
1068 tatic int __interrupt childprocess(void)
1070 struct ExecBase *SysBase = *((struct ExecBase **)4);
1071 struct Library *DOSBase;
1073 struct POmsg *startupmsg;
1074 int i = RETURN_FAIL;
1076 /* find our process structure */
1077 me = (struct Process *) FindTask(NULL);
1079 /* Wait for the parent to kick us off */
1080 WaitPort(&me->pr_MsgPort);
1082 /* Get the command to execute */
1083 startupmsg = (struct POmsg *) GetMsg(&me->pr_MsgPort);
1085 DOSBase = startupmsg->DOSBase;
1089 /* Now run the command. stdin and stdout are already set up */
1090 i = SystemTags(startupmsg->cmd,
1097 /* UNIX compatibility ... */
1102 /* pass the exit code back to the parent */
1103 ReplyMsg((struct Message *) startupmsg);
1106 \fnet.lib/PrintNetFault net.lib/PrintNetFault
1109 PrintNetFault - socket error messages
1112 PrintNetFault(code, banner)
1113 void PrintNetFault(LONG, const UBYTE *)
1116 The PrintNetFault() function finds the error message corresponding
1117 to the code and writes it, followed by a newline, to the standard
1118 error or Output() filehandle. If the argument string is non-NULL it
1119 is preappended to the message string and separated from it by a
1120 colon and space (`: '). If string is NULL only the error message
1124 The PrintNetFault() function uses the DOS IO functions.
1127 strerror(), perror(), <netinclude:sys/errno.h>
1129 \fnet.lib/PrintUserFault net.lib/PrintUserFault
1132 PrintUserFault - socket error messages
1135 PrintUserFault(code, banner)
1136 void PrintUserFault(LONG, const UBYTE *)
1139 The PrintUserFault() function finds the error message corresponding to
1140 the code and writes it, followed by a newline, to the standard error
1141 or Output() filehandle. If the argument string is non-NULL it is
1142 preappended to the message string and separated from it by a colon and
1143 space (`: '). If string is NULL only the error message string is
1147 The PrintUserFault() function used the DOS io functions. It is
1148 recommended to use PrintUserFault() when the standard C IO functions
1149 are not otherwise in use.
1152 strerror(), perror(), <netinclude:sys/errno.h>
1154 \fnet.lib/random net.lib/random
1157 random - random number generator;
1163 The random() function uses a non-linear additive feedback random number
1164 generator employing a default table of size 31 long integers to return
1165 successive pseudo-random numbers in the range from 0 to (2**31)-1. The
1166 period of this random number generator is very large, approximately
1169 All the bits generated by random() are usable. For example,
1170 `random()&01' will produce a random binary value.
1173 A long integer random value.
1179 \fnet.lib/rcmd net.lib/rcmd
1182 rcmd, rresvport - routines for returning a stream to a remote command
1185 #include <clib/socket_protos.h>
1187 int rcmd(char **ahost, int inport, const char *locuser,
1188 const char *remuser, const char *cmd, int *fd2p);
1190 int rresvport(int *port);
1193 The rcmd() function is used by the super-user to execute a command on
1194 a remote machine using an authentication scheme based on reserved port
1195 numbers. The rresvport() function returns a descriptor to a socket
1196 with an address in the privileged port space. Both functions are
1197 present in the same file and are used by the rsh command (among
1200 The rcmd() function looks up the host *ahost using gethostbyname(),
1201 returning -1 if the host does not exist. Otherwise *ahost is set to
1202 the standard name of the host and a connection is established to a
1203 server residing at the well-known Internet port inport.
1205 If the connection succeeds, a socket in the Internet domain of type
1206 SOCK_STREAM is returned to the caller, and given to the remote command
1207 as stdin and stdout. If fd2p is non-zero, then an auxiliary channel to
1208 a control process will be set up, and a descriptor for it will be
1209 placed in *fd2p. The control process will return diagnostic output
1210 from the command (unit 2) on this channel, and will also accept bytes
1211 on this channel as being UNIX signal numbers, to be forwarded to the
1212 process group of the command. If fd2p is 0, then the stderr (unit 2
1213 of the remote command) will be made the same as the stdout and no
1214 provision is made for sending arbitrary signals to the remote process,
1215 although you may be able to get its attention by using out-of-band
1218 The protocol is described in detail in netutil/rshd.
1220 The rresvport() function is used to obtain a socket with a privileged
1221 address bound to it. This socket is suitable for use by rcmd() and
1222 several other functions. Privileged Internet ports are those in the
1223 range 0 to 1023. Only the super-user is allowed to bind an address of
1224 this sort to a socket.
1227 The rcmd() function returns a valid socket descriptor on success. It
1228 returns -1 on error and prints a diagnostic message on the standard
1231 The rresvport() function returns a valid, bound socket descriptor on
1232 success. It returns -1 on error with the global value errno set
1233 according to the reason for failure. The error code EAGAIN is
1234 overloaded to mean `All network ports in use.'
1237 netutil/rlogin, netutil/rsh, rexec(), netutil/rexecd,
1238 netutil/rlogind, netutil/rshd
1240 \fnet.lib/select net.library/select
1243 select -- synchronous I/O multiplexing
1246 n = select( nfds, readfds, writefds, exceptfds, timeout );
1248 long select( long nfds, fd_set *readfds, fd_set *writefds, fd_set
1249 *exceptfds, struct timeval *timeout );
1252 select() examines the I/O descriptor sets whose addresses are
1253 passed in readfds, writefds, and exceptfds to see if some of their
1254 descriptors are ready for reading, are ready for writing, or have an
1255 exceptional condition pending, respectively. The first nfds
1256 descriptors are checked in each set; i.e., the descriptors from 0
1257 through nfds-1 in the descriptor sets are examined. On return,
1258 select() replaces the given descriptor sets with subsets consisting
1259 of those descriptors that are ready for the requested operation.
1260 Select() returns the total number of ready descriptors in all the
1263 The descriptor sets are stored as bit fields in arrays of integers.
1264 The following macros are provided for manipulating such descriptor
1265 sets: FD_ZERO(&fdsetx) initializes a descriptor set fdset to the null
1266 set. FD_SET(fd, &fdset) includes a particular descriptor fd in
1267 fdset. FD_CLR(fd, &fdset) removes fd from fdset. FD_ISSET(fd,
1268 &fdset) is non-zero if fd is a member of fdset, zero otherwise. The
1269 behavior of these macros is undefined if a descriptor value is less
1270 than zero or greater than or equal to FD_SETSIZE, which is normally
1271 at least equal to the maximum number of descriptors supported by the
1274 If timeout is a non-nil pointer, it specifies a maximum interval to
1275 wait for the selection to complete. If timeout is a nil pointer, the
1276 select blocks indefinitely. To affect a poll, the timeout argument
1277 should be non-nil, pointing to a zero-valued timeval structure.
1279 Any of readfds, writefds, and exceptfds may be given as nil pointers
1280 if no descriptors are of interest.
1282 select() returns the number of ready descriptors that are contained
1283 in the descriptor sets, or -1 if an error occurred. If the time
1284 limit expires, select() returns 0. If select() returns with an
1285 error, the descriptor sets will be unmodified.
1287 An error return from select() indicates:
1289 [EBADF] One of the descriptor sets specified an invalid descriptor.
1291 [EINTR] select() was interrupted, usually by Ctrl-C.
1293 [EINVAL] The specified time limit is invalid. One of its components
1294 is negative or too large.
1297 nfds - number of I/O descriptors
1299 readfds - read fd set
1301 writefds - write fd set
1303 exceptfds - exception fd set
1308 n (D0) - number of I/O descriptors
1311 In current netlib version this function can be used only on network
1312 sockets. In fact it is the same as
1313 WaitSelect(nfds, readfds, writefds, exceptfds, timeout, NULL).
1316 bsdsocket.library/WaitSelect()
1318 \fnet.lib/serveraccept net.lib/serveraccept
1321 serveraccept - Accept a server connection on named port
1324 socket = serveraccept(name, peer);
1326 long serveraccept(char *, struct sockaddr_in *);
1329 The serveraccept() library call binds a socket to the named Internet
1330 TCP port. Then it listens the socket and accepts the connection to
1331 the port. The peer's socket address is returned in sockaddr pointed
1332 by sockaddr argument.
1334 The port name is resolved by getservbyname() call. A numeric value
1335 for port name is also accepted.
1337 This module is meant for daemon developing.
1340 name - port name or numeric string.
1341 peer - pointer to struct sockaddr_in
1344 socket - positive socket id for success or -1 for failure.
1346 peer - sockaddr_in structure containing peer's internet address.
1347 Note that on error, the structure containing peer address
1348 is not necessarily updated.
1351 bsdsocket/accept, bsdsocket/getservbyname
1353 \fnet.lib/set_socket_stdio net.lib/set_socket_stdio
1356 set_socket_stdio - redirect stdio to/from a socket
1359 int set_socket_stdio(int sock);
1362 Redirect stdio (stdin, stdout and stderr) to/from socket 'sock'.
1363 This is done by dup2()'ing 'sock' to the level 1 files underneath
1364 the stdin, stdout and stderr.
1366 The original 'sock' reference is closed on successful return, so
1367 the socket descriptor given as argument should not be used after
1368 this function returns (successfully).
1371 0 if successful, -1 on error. Global variable 'errno' contains
1372 the specific error code set by the failing function.
1375 This module pulls in the link library stdio modules.
1379 \fnet.lib/sleep net.lib/sleep
1382 sleep - suspend process execution for the specified time
1385 void sleep(unsigned int seconds);
1388 Process execution is suspended for number of seconds specified in
1389 'seconds'. The sleep will be aborted if any of the break signals
1390 specified for the process is received (only CTRL-C by default).
1396 'seconds' - number of seconds to sleep.
1399 Does not return a value.
1402 The sleep is implemented as a single select() call with all other
1403 than time out argument as NULL.
1406 bsdsocket.library/select()
1408 \fnet.lib/SPrintf net.lib/SPrintf
1411 SPrintf -- formatted print to a buffer
1414 len = SPrintf(Buffer, FormatString, Arguments...)
1415 len = VSPrintf(Buffer, FormatString, ap)
1417 ULONG SPrintf(STRPTR, const char *, ...)
1418 ULONG VSPrintf(STRPTR, const char *, va_list)
1421 Prints to a simple buffer or to a CSource buffer. These functions
1422 are similar to C-library sprintf() with RawDoFmt() formatting.
1425 Buffer - Pointer to buffer.
1426 FormatString - This is a printf()-style format string as defined
1427 in exec.library/RawDoFmt().
1428 Arguments - as in printf() .
1430 Result - Pointer to CSource structure.
1433 Number of characters printed.
1436 SPrintf(mybuf, "line=%ld, val=%lx\n",
1437 __LINE__, very.interesting->value);
1440 Function SPrintf() assumes that no print is longer than 1024 chars.
1441 It does not check for buffer owerflow (there no way to check, the
1442 definition of sprintf misses it).
1444 SPrintf strings are truncated to maximum of 1024 chars (including
1448 exec.library/RawDoFmt()
1450 \fnet.lib/srandom net.lib/srandom
1453 srandom - initialize a seed value for the random number generator
1456 void srandom(unsigned seed)
1459 The srandom() function sets a seed value used by random() function
1460 to produce random numbers.
1462 srandom() does not return the old seed; the reason for this is that
1463 the amount of state information used is much more than a single
1464 word. However, random() by defalut will produce a sequence of
1465 numbers that can be duplicated by calling srandom() with `1' as the
1471 \fnet.lib/stat net.lib/stat
1474 stat, lstat, fstat - get file status
1477 #include <sys/types.h>
1478 #include <sys/stat.h>
1480 success = stat(path, buf)
1482 int stat(const char *, struct stat *);
1484 success = lstat(path, buf);
1486 int lstat(const char *, struct stat *);
1488 success = fstat(fd, buf);
1490 int fstat(int, struct stat *);
1493 The stat() function obtains information about the file pointed to by
1494 path. Read, write or execute permission of the named file is not
1495 required, but all directories listed in the path name leading to the
1496 file must be seachable.
1498 Lstat() is like stat() except in the case where the named file is a
1499 symbolic link, in which case lstat() returns information about the
1500 link, while stat() returns information about the file the link
1503 The fstat() obtains the same information about an open file known by
1504 the file descriptor fd, such as would be obtained by an open call.
1506 Buf is a pointer to a stat() structure as defined by <sys/stat.h>
1507 (shown below) and into which information is placed concerning the
1512 dev_t st_dev; /* unique device id */
1513 ino_t st_ino; /* inode of file (key block) */
1514 mode_t st_mode; /* Unix style mode */
1515 ushort st_nlink; /* number of links (unimplemented) */
1516 uid_t st_uid; /* owner's user ID */
1517 gid_t st_gid; /* owner's group ID */
1518 dev_t st_rdev; /* special file ID (unimplemented) */
1519 off_t st_size; /* file size */
1520 time_t st_atime; /* Time of last access */
1521 time_t st_mtime; /* Last modification time */
1522 time_t st_ctime; /* Last file status change time */
1523 long st_blksize; /* Size of disk block */
1524 long st_blocks; /* Size in blocks */
1525 long st_dosmode; /* DOS protection bits */
1526 short st_type; /* DOS file type */
1527 char *st_comment; /* DOS file comment */
1530 The time-related fields of struct stat have same contents, time when
1531 file data last modified.
1533 The status information word st_mode has bits as follows:
1535 #define S_ISUID 0004000 /* set user id on execution */
1536 #define S_ISGID 0002000 /* set group id on execution */
1537 #define S_ISVTX 0001000 /* save swapped text even after use */
1538 #define S_IRUSR 0000400 /* read permission for owner */
1539 #define S_IWUSR 0000200 /* write permission for owner */
1540 #define S_IXUSR 0000100 /* execute permission for owner */
1541 #define S_IRGRP 0000040 /* read permission for group */
1542 #define S_IWGRP 0000020 /* write permission for group */
1543 #define S_IXGRP 0000010 /* execute permission for group */
1544 #define S_IROTH 0000004 /* read permission for other */
1545 #define S_IWOTH 0000002 /* write permission for other */
1546 #define S_IXOTH 0000001 /* execute permission for other */
1547 #define S_IFCHR 0020000 /* character special */
1548 #define S_IFDIR 0040000 /* directory */
1549 #define S_IFBLK 0060000 /* block special */
1550 #define S_IFREG 0100000 /* regular */
1551 #define S_IFLNK 0120000 /* symbolic link */
1552 #define S_IFSOCK 0140000 /* socket */
1553 #define S_IFIFO 0010000 /* named pipe (fifo) */
1555 For a list of access modes, see <sys/stat.h>, access(2) and chmod(2).
1558 Upon successful completion a value of 0 is returned. Otherwise, a
1559 value of -1 is returned and errno is set to indicate the error.
1562 The functions stat() and lstat() will fail if:
1564 [ENOTDIR] A component of the path prefix is not a directory.
1566 [ENAMETOOLONG] A component of a pathname exceeded 255 characters,
1567 or an entire path name exceeded 1023 characters.
1569 [ENOENT] The named file does not exist.
1571 [ELOOP] Too many symbolic links were encountered in
1572 translating the pathname.
1574 [EACCES] Search permission is denied for a component of the
1577 [EFAULT] Buf or name points to an invalid address.
1579 [EIO] An I/O error occurred while reading from or writing
1582 The function fstat() will fail if:
1584 [EBADF] fd is not a valid open file descriptor.
1586 [EFAULT] Buf points to an invalid address.
1588 [EIO] An I/O error occurred while reading from or writing to the
1595 Applying fstat to a socket returns a zero'd buffer.
1597 \fnet.lib/strerror net.lib/strerror
1600 strerror -- return the text for given error number
1603 string = strerror(error);
1605 char * strerror(int);
1608 This function returns pointer to the (English) string describing the
1609 error code given as argument. The error strings are defined for the
1610 error codes defined in <sys/errno.h>.
1613 The string pointed to by the return value should not be modified by
1614 the program, but may be overwritten by a subsequent call to this
1618 The strerror() prototype should be
1619 const char *strerror(unsigned int);
1620 However, the SAS C includes define it differently.
1623 <netinclude:sys/errno.h>, perror(), PrintNetFault()
1624 \fnet.lib/syslog net.lib/syslog
1627 openlog(), closelog(), setlogmask() -- syslog utility functions
1632 openlog(ident, logopt, facility);
1634 void openlog(const char *, int, int);
1638 void closelog(void);
1640 oldmask = setlogmask(maskpri);
1642 int setlogmask(int);
1645 openlog() can be called to initialize the log file, if special
1646 processing is needed. ident is a string that precedes every
1647 message. logopt is a mask of bits, logically OR'ed together,
1648 indicating logging options. The values for logopt are:
1650 LOG_PID Log the process ID with each message;
1651 useful for identifying instantiations
1654 LOG_CONS Force writing messages to the console
1655 if unable to send it to syslogd.
1656 This option is safe to use in daemon
1657 processes that have no controlling
1658 terminal because syslog() forks
1659 before opening the console.
1661 LOG_NDELAY Open the connection to syslogd
1662 immediately. Normally, the open is
1663 delayed until the first message is
1664 logged. This is useful for programs
1665 that need to manage the order in
1666 which file descriptors are allocated.
1668 LOG_NOWAIT Do not wait for children forked to
1669 log messages on the console. Obsolete
1670 in AmiTCP/IP, since AmiTCP/IP does
1673 facility encodes a default facility to be assigned to all
1674 messages written subsequently by syslog() with no explicit
1675 facility encoded. The facility codes are:
1677 LOG_KERN Messages generated by the kernel.
1678 These cannot be generated by any user
1681 LOG_USER Messages generated by random user
1682 processes. This is the default
1683 facility identifier if none is
1686 LOG_MAIL The mail system.
1688 LOG_DAEMON System daemons, such as inetd, ftpd,
1691 LOG_AUTH The authorization system: login, su,
1694 LOG_LPR The line printer spooling system: lp,
1697 LOG_LOCAL0 Reserved for local use. Similarly for
1698 LOG_LOCAL1 through LOG_LOCAL7.
1701 closelog() closes the log file.
1703 setlogmask() sets the log priority mask to maskpri and returns
1704 the previous mask. Calls to syslog() with a priority not set
1705 in maskpri are rejected. The mask for an individual priority
1706 pri is calculated by the macro LOG_MASK(pri); the mask for all
1707 priorities up to and including toppri is given by the macro
1708 LOG_UPTO(toppri). By default, all priorities are logged.
1711 who logs a message regarding some sort of unexpected and
1714 syslog(LOG_ALERT, "who: internal error 23");
1716 ftpd uses openlog() to arrange to log its process ID, to log
1717 to the console if necessary, and to log in the name of the
1720 openlog("ftpd", LOG_PID|LOG_CONS, LOG_DAEMON);
1722 Arrange to log messages only at levels LOG_ERR and lower:
1724 setlogmask(LOG_UPTO(LOG_ERR));
1726 Typical usage of syslog() to log a connection:
1728 syslog(LOG_INFO, "Connection from host %d", CallingHost);
1730 If the facility has not been set with openlog(), it defaults
1733 Explicitly set the facility for this message:
1735 syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m");
1738 openlog() does not copy and store the ident string internally;
1739 it stores only the character pointer. Therefore it is the
1740 responsibility of the programmer to make sure that the ident
1741 argument points to the correct string while syslog() is being
1745 Most of the logopt and facility codes are currently being
1746 ignored by AmiTCP/IP, but they should be used for future
1749 The autoinit module of the net.lib tells the program name
1750 to the AmiTCP/IP at program startup, so use of the openlog()
1751 for that purpose only is not necessary.
1754 syslog() was developed by the University of California,
1758 bsdsocket.library/syslog(), bsdsocket.library/SocketBaseTagList()
1759 \fnet.lib/usleep net.lib/usleep
1762 usleep - suspend process execution for the specified time
1765 void usleep(unsigned int microseconds);
1768 Process execution is suspended for number of microseconds
1769 specified in 'microseconds'. The sleep will be aborted if any
1770 of the break signals specified for the process is received
1771 (only CTRL-C by default).
1777 'microseconds' - number of microseconds to sleep.
1780 Does not return a value.
1783 The sleep is implemented as a single select() call with all other
1784 than time out argument as NULL.
1787 bsdsocket.library/select()
1789 \fnet.lib/utime net.lib/utime
1792 utime - set file access and modification times
1797 int error = utime(const char *name, const struct utimbuf *times)
1800 The access and modification times for the file 'name' are modified
1801 according to the 'times'. If 'times' is NULL, the times are set to
1802 systems current time.
1808 'name' - the name of the file to be affected.
1810 'times' - pointer to a structure containing the time values,
1811 defined in <utime.h> as:
1814 time_t actime; /* Access time */
1815 time_t modtime; /* Modification time */
1818 Both times are in units of seconds since Jan. 1, 1970,
1819 Greenwich Mean Time.
1821 If the 'times' is given as the NULL pointer, the current
1825 Returns 0 when successful and -1 with specific error code in errno in
1829 Since AmigaDOS files have only one time stamp, both access and
1830 modification times cannot be supported. Since the AmigaDOS file date
1831 is the modification time, only the 'modtime' field of the 'times' is
1834 The conversion from 1.1.1970 based GMT to 1.1.1978 based local time is
1835 done with external long __local_to_GMT, which is defined and
1836 initialized by the timerinit.c module included in the net.lib.
1839 dos.library/DateStamp(), dos.library/SetFileDate(), net.lib/timerinit
1841 \fnet.lib/writev net.lib/writev
1844 writev - write output
1847 ssize_t writev(int d, const struct iovec *iov, int iovcnt)
1850 writev() attempts to write nbytes of data to the object referenced by
1851 the descriptor d from the iovcnt buffers specified by the members of
1852 the iov array: iov[0], iov[1], ..., iov[iovcnt-1].
1854 The iovec structure is defined as:
1861 Each iovec entry specifies the base address and length of an area in
1862 memory from which data should be written. writev() will always write
1863 a complete area before proceeding to the next.
1865 On objects capable of seeking, the writev() starts at a position
1866 given by the pointer associated with d (set using libc function
1867 lseek()). Upon return from writev(), the pointer is incremented by the
1868 number of bytes which were written.
1870 Objects that are not capable of seeking always write from the current
1871 position. The value of the pointer associated with such an object is
1874 When using non-blocking I/O on objects such as sockets that are subject
1875 to flow control, writev() may write fewer bytes than requested; the
1876 return value must be noted, and the remainder of the operation should
1877 be retried when possible.
1880 Upon successful completion the number of bytes which were written is
1881 returned. Otherwise a -1 is returned and the global variable errno is
1882 set to indicate the error.
1885 writev() will fail and the file pointer will remain unchanged if:
1887 [EBADF] D is not a valid descriptor open for writing.
1889 [EPIPE] An attempt is made to write to a socket of type that is
1890 not connected to a peer socket.
1892 [EFBIG] An attempt was made to write a file that exceeds the
1895 [EINVAL] The pointer associated with d was negative.
1897 [EINVAL] Iovcnt was less than or equal to 0, or greater than
1900 [EINVAL] One of the iov_len values in the iov array was negative.
1902 [EINVAL] The sum of the iov_len values in the iov array overflowed
1905 [ENOSPC] There is no free space remaining on the file system
1906 containing the file.
1908 [EIO] An I/O error occurred while reading from or writing to
1911 [EAGAIN] The file was marked for non-blocking I/O, and no data
1912 could be written immediately.
1915 In this netlib version Level-1 I/O on sockets is not implemented, use
1916 these function only on regular files created by libc functions like