home *** CD-ROM | disk | FTP | other *** search
/ vsiftp.vmssoftware.com / VSIPUBLIC@vsiftp.vmssoftware.com.tar / FREEWARE / FREEWARE40.ZIP / pine / c-client / os_aux.c < prev    next >
C/C++ Source or Header  |  1994-01-09  |  18KB  |  669 lines

  1. /*
  2.  * Program:    Operating-system dependent routines -- A/UX version
  3.  *
  4.  * Author:    Mark Crispin
  5.  *        Networks and Distributed Computing
  6.  *        Computing & Communications
  7.  *        University of Washington
  8.  *        Administration Building, AG-44
  9.  *        Seattle, WA  98195
  10.  *
  11.  * Date:    11 May 1989
  12.  * Last Edited:    13 October 1993
  13.  *
  14.  * Copyright 1993 by the University of Washington
  15.  *
  16.  *  Permission to use, copy, modify, and distribute this software and its
  17.  * documentation for any purpose and without fee is hereby granted, provided
  18.  * that the above copyright notice appears in all copies and that both the
  19.  * above copyright notice and this permission notice appear in supporting
  20.  * documentation, and that the name of the University of Washington not be
  21.  * used in advertising or publicity pertaining to distribution of the software
  22.  * without specific, written prior permission.  This software is made
  23.  * available "as is", and
  24.  * THE UNIVERSITY OF WASHINGTON DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED,
  25.  * WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT LIMITATION ALL IMPLIED
  26.  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, AND IN
  27.  * NO EVENT SHALL THE UNIVERSITY OF WASHINGTON BE LIABLE FOR ANY SPECIAL,
  28.  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  29.  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, TORT
  30.  * (INCLUDING NEGLIGENCE) OR STRICT LIABILITY, ARISING OUT OF OR IN CONNECTION
  31.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  32.  *
  33.  */
  34.  
  35. /* TCP input buffer */
  36.  
  37. #define BUFLEN 8192
  38.  
  39.  
  40. /* TCP I/O stream (must be before osdep.h is included) */
  41.  
  42. #define TCPSTREAM struct tcp_stream
  43. TCPSTREAM {
  44.   char *host;            /* host name */
  45.   char *localhost;        /* local host name */
  46.   int tcpsi;            /* input socket */
  47.   int tcpso;            /* output socket */
  48.   int ictr;            /* input counter */
  49.   char *iptr;            /* input pointer */
  50.   char ibuf[BUFLEN];        /* input buffer */
  51. };
  52.  
  53. #include "osdep.h"
  54. #include <ctype.h>
  55. #include <sys/time.h>
  56. #include <time.h>
  57. #include <sys/socket.h>
  58. #include <netinet/in.h>
  59. #include <netdb.h>
  60. #include <errno.h>
  61. #include <pwd.h>
  62. #include <syslog.h>
  63. #include "mail.h"
  64. #include "misc.h"
  65.  
  66. extern char *sys_errlist[];
  67. extern int sys_nerr;
  68.  
  69. /*
  70. #define toint(c)    ((c)-'0')
  71. #define isodigit(c)    (((unsigned)(c)>=060)&((unsigned)(c)<=067))
  72. */
  73.  
  74. /* Write current time in RFC 822 format
  75.  * Accepts: destination string
  76.  */
  77.  
  78. char *days[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
  79.  
  80. void rfc822_date (date)
  81.     char *date;
  82. {
  83.   int zone;
  84.   char *zonename;
  85.   struct tm *t;
  86.   struct timeval tv;
  87.   struct timezone tz;
  88.  
  89.   gettimeofday (&tv,&tz);    /* get time and timezone poop */
  90.   t = localtime (&tv.tv_sec);    /* convert to individual items */
  91.                 /* use this for older systems */
  92.   zone = (t->tm_isdst ? 60 : 0) -tz.tz_minuteswest;
  93.   sprintf (date,"%s, %d %s %d %02d:%02d:%02d %+03d%02d (%s)",
  94.        days[t->tm_wday],t->tm_mday,months[t->tm_mon],t->tm_year+1900,
  95.        t->tm_hour,t->tm_min,t->tm_sec,zone/60,abs (zone) % 60,
  96.        tzname[t->tm_isdst ? 1 : 0]);
  97. }
  98.  
  99. /* Get a block of free storage
  100.  * Accepts: size of desired block
  101.  * Returns: free storage block
  102.  */
  103.  
  104. void *fs_get (size)
  105.     size_t size;
  106. {
  107.   void *block = malloc (size);
  108.   if (!block) fatal ("Out of free storage");
  109.   return (block);
  110. }
  111.  
  112.  
  113. /* Resize a block of free storage
  114.  * Accepts: ** pointer to current block
  115.  *        new size
  116.  */
  117.  
  118. void fs_resize (block,size)
  119.     void **block;
  120.     size_t size;
  121. {
  122.   if (!(*block = realloc (*block,size))) fatal ("Can't resize free storage");
  123. }
  124.  
  125.  
  126. /* Return a block of free storage
  127.  * Accepts: ** pointer to free storage block
  128.  */
  129.  
  130. void fs_give (block)
  131.     void **block;
  132. {
  133.   free (*block);
  134.   *block = NIL;
  135. }
  136.  
  137.  
  138. /* Report a fatal error
  139.  * Accepts: string to output
  140.  */
  141.  
  142. void fatal (string)
  143.     char *string;
  144. {
  145.   mm_fatal (string);        /* output the string */
  146.   syslog (LOG_ALERT,"IMAP C-Client crash: %s",string);
  147.   abort ();            /* die horribly */
  148. }
  149.  
  150. /* Copy string with CRLF newlines
  151.  * Accepts: destination string
  152.  *        pointer to size of destination string
  153.  *        source string
  154.  *        length of source string
  155.  * Returns: length of copied string
  156.  */
  157.  
  158. unsigned long strcrlfcpy (dst,dstl,src,srcl)
  159.     char **dst;
  160.     unsigned long *dstl;
  161.     char *src;
  162.     unsigned long srcl;
  163. {
  164.   long i,j;
  165.   char *d = src;
  166.                 /* count number of LF's in source string(s) */
  167.   for (i = srcl,j = 0; j < srcl; j++) if (*d++ == '\012') i++;
  168.   if (i > *dstl) {        /* resize if not enough space */
  169.     fs_give ((void **) dst);    /* fs_resize does an unnecessary copy */
  170.     *dst = (char *) fs_get ((*dstl = i) + 1);
  171.   }
  172.   d = *dst;            /* destination string */
  173.                 /* copy strings, inserting CR's before LF's */
  174.   while (srcl--) switch (*src) {
  175.   case '\015':            /* unlikely carriage return */
  176.     *d++ = *src++;        /* copy it and any succeeding linefeed */
  177.     if (srcl && *src == '\012') {
  178.       *d++ = *src++;
  179.       srcl--;
  180.     }
  181.     break;
  182.   case '\012':            /* line feed? */
  183.     *d++ ='\015';        /* yes, prepend a CR, drop into default case */
  184.   default:            /* ordinary chararacter */
  185.     *d++ = *src++;        /* just copy character */
  186.     break;
  187.   }
  188.   *d = '\0';            /* tie off destination */
  189.   return d- *dst;        /* return length */
  190. }
  191.  
  192.  
  193. /* Length of string after strcrlfcpy applied
  194.  * Accepts: source string
  195.  * Returns: length of string
  196.  */
  197.  
  198. unsigned long strcrlflen (s)
  199.     STRING *s;
  200. {
  201.   unsigned long pos = GETPOS (s);
  202.   unsigned long i = SIZE (s);
  203.   unsigned long j = i;
  204.   while (j--) switch (SNX (s)) {/* search for newlines */
  205.   case '\015':            /* unlikely carriage return */
  206.     if (j && (CHR (s) == '\012')) {
  207.       SNX (s);            /* eat the line feed */
  208.       j--;
  209.     }
  210.     break;
  211.   case '\012':            /* line feed? */
  212.     i++;
  213.   default:            /* ordinary chararacter */
  214.     break;
  215.   }
  216.   SETPOS (s,pos);        /* restore old position */
  217.   return i;
  218. }
  219.  
  220. /* Server log in
  221.  * Accepts: user name string
  222.  *        password string
  223.  *        optional place to return home directory
  224.  * Returns: T if password validated, NIL otherwise
  225.  */
  226.  
  227. long server_login (user,pass,home,argc,argv)
  228.     char *user;
  229.     char *pass;
  230.     char **home;
  231.     int argc;
  232.     char *argv[];
  233. {
  234.   struct passwd *pw = getpwnam (lcase (user));
  235.                 /* no entry for this user or root */
  236.   if (!(pw && pw->pw_uid)) return NIL;
  237.                 /* validate password */
  238.   if (strcmp (pw->pw_passwd,(char *) crypt (pass,pw->pw_passwd))) return NIL;
  239.   setgid (pw->pw_gid);        /* all OK, login in as that user */
  240.   initgroups (user,pw->pw_gid);    /* initialize groups */
  241.   setuid (pw->pw_uid);
  242.                 /* note home directory */
  243.   if (home) *home = cpystr (pw->pw_dir);
  244.   return T;
  245. }
  246.  
  247. /* Return my user name
  248.  * Returns: my user name
  249.  */
  250.  
  251. char *uname = NIL;
  252.  
  253. char *myusername ()
  254. {
  255.   return uname ? uname : (uname = cpystr (getpwuid (geteuid ())->pw_name));
  256. }
  257.  
  258.  
  259. /* Return my home directory name
  260.  * Returns: my home directory name
  261.  */
  262.  
  263. char *hdname = NIL;
  264.  
  265. char *myhomedir ()
  266. {
  267.   return hdname ? hdname : (hdname = cpystr (getpwuid (geteuid ())->pw_dir));
  268. }
  269.  
  270.  
  271. /* Build status lock file name
  272.  * Accepts: scratch buffer
  273.  *        file name
  274.  * Returns: name of file to lock
  275.  */
  276.  
  277. char *lockname (tmp,fname)
  278.     char *tmp;
  279.     char *fname;
  280. {
  281.   int i;
  282.   sprintf (tmp,"/tmp/.%s",fname);
  283.   for (i = 6; i < strlen (tmp); ++i) if (tmp[i] == '/') tmp[i] = '\\';
  284.   return tmp;            /* note name for later */
  285. }
  286.  
  287. /* TCP/IP open
  288.  * Accepts: host name
  289.  *        contact port number
  290.  * Returns: TCP/IP stream if success else NIL
  291.  */
  292.  
  293. TCPSTREAM *tcp_open (host,port)
  294.     char *host;
  295.     long port;
  296. {
  297.   TCPSTREAM *stream = NIL;
  298.   int sock;
  299.   char *s;
  300.   struct sockaddr_in sin;
  301.   struct hostent *host_name;
  302.   char hostname[MAILTMPLEN];
  303.   char tmp[MAILTMPLEN];
  304.   /* The domain literal form is used (rather than simply the dotted decimal
  305.      as with other Unix programs) because it has to be a valid "host name"
  306.      in mailsystem terminology. */
  307.                 /* look like domain literal? */
  308.   if (host[0] == '[' && host[(strlen (host))-1] == ']') {
  309.     strcpy (hostname,host+1);    /* yes, copy number part */
  310.     hostname[(strlen (hostname))-1] = '\0';
  311.     if ((sin.sin_addr.s_addr = inet_addr (hostname)) != -1) {
  312.       sin.sin_family = AF_INET;    /* family is always Internet */
  313.       strcpy (hostname,host);    /* hostname is user's argument */
  314.     }
  315.     else {
  316.       sprintf (tmp,"Bad format domain-literal: %.80s",host);
  317.       mm_log (tmp,ERROR);
  318.       return NIL;
  319.     }
  320.   }
  321.  
  322.   else {            /* lookup host name, note that brain-dead Unix
  323.                    requires lowercase! */
  324.     strcpy (hostname,host);    /* in case host is in write-protected memory */
  325.     if ((host_name = gethostbyname (lcase (hostname)))) {
  326.                 /* copy address type */
  327.       sin.sin_family = host_name->h_addrtype;
  328.                 /* copy host name */
  329.       strcpy (hostname,host_name->h_name);
  330.                 /* copy host addresses */
  331.       memcpy (&sin.sin_addr,host_name->h_addr,host_name->h_length);
  332.     }
  333.     else {
  334.       sprintf (tmp,"No such host as %.80s",host);
  335.       mm_log (tmp,ERROR);
  336.       return NIL;
  337.     }
  338.   }
  339.  
  340.                 /* copy port number in network format */
  341.   if (!(sin.sin_port = htons (port))) fatal ("Bad port argument to tcp_open");
  342.                 /* get a TCP stream */
  343.   if ((sock = socket (sin.sin_family,SOCK_STREAM,0)) < 0) {
  344.     sprintf (tmp,"Unable to create TCP socket: %s",strerror (errno));
  345.     mm_log (tmp,ERROR);
  346.     return NIL;
  347.   }
  348.                 /* open connection */
  349.   if (connect (sock,(struct sockaddr *)&sin,sizeof (sin)) < 0) {
  350.     sprintf (tmp,"Can't connect to %.80s,%d: %s",hostname,port,
  351.          strerror (errno));
  352.     mm_log (tmp,ERROR);
  353.     return NIL;
  354.   }
  355.                 /* create TCP/IP stream */
  356.   stream = (TCPSTREAM *) fs_get (sizeof (TCPSTREAM));
  357.                 /* copy official host name */
  358.   stream->host = cpystr (hostname);
  359.                 /* get local name */
  360.   gethostname (tmp,MAILTMPLEN-1);
  361.   stream->localhost = cpystr ((host_name = gethostbyname (tmp)) ?
  362.                   host_name->h_name : tmp);
  363.                 /* init sockets */
  364.   stream->tcpsi = stream->tcpso = sock;
  365.   stream->ictr = 0;        /* init input counter */
  366.   return stream;        /* return success */
  367. }
  368.  
  369. /* TCP/IP authenticated open
  370.  * Accepts: host name
  371.  *        service name
  372.  * Returns: TCP/IP stream if success else NIL
  373.  */
  374.  
  375. TCPSTREAM *tcp_aopen (host,service)
  376.     char *host;
  377.     char *service;
  378. {
  379.   TCPSTREAM *stream = NIL;
  380.   struct hostent *host_name;
  381.   char hostname[MAILTMPLEN];
  382.   int i;
  383.   int pipei[2],pipeo[2];
  384.   /* The domain literal form is used (rather than simply the dotted decimal
  385.      as with other Unix programs) because it has to be a valid "host name"
  386.      in mailsystem terminology. */
  387.                 /* look like domain literal? */
  388.   if (host[0] == '[' && host[i = (strlen (host))-1] == ']') {
  389.     strcpy (hostname,host+1);    /* yes, copy without brackets */
  390.     hostname[i-1] = '\0';
  391.   }
  392.                 /* note that Unix requires lowercase! */
  393.   else if (host_name = gethostbyname (lcase (strcpy (hostname,host))))
  394.     strcpy (hostname,host_name->h_name);
  395.                 /* make command pipes */
  396.   if (pipe (pipei) < 0) return NIL;
  397.   if (pipe (pipeo) < 0) {
  398.     close (pipei[0]); close (pipei[1]);
  399.     return NIL;
  400.   }
  401.   if ((i = fork ()) < 0) {    /* make inferior process */
  402.     close (pipei[0]); close (pipei[1]);
  403.     close (pipeo[0]); close (pipeo[1]);
  404.     return NIL;
  405.   }
  406.   if (i) {            /* parent? */
  407.     close (pipei[1]);        /* close child's side of the pipes */
  408.     close (pipeo[0]);
  409.   }
  410.   else {            /* child */
  411.     dup2 (pipei[1],1);        /* parent's input is my output */
  412.     dup2 (pipei[1],2);        /* parent's input is my error output too */
  413.     close (pipei[0]); close (pipei[1]);
  414.     dup2 (pipeo[0],0);        /* parent's output is my input */
  415.     close (pipeo[0]); close (pipeo[1]);
  416.                 /* now run it */
  417.     execl ("/usr/bin/remsh","remsh",hostname,"exec",service,0);
  418.     _exit (1);            /* spazzed */
  419.   }
  420.  
  421.                 /* create TCP/IP stream */
  422.   stream = (TCPSTREAM *) fs_get (sizeof (TCPSTREAM));
  423.                 /* copy official host name */
  424.   stream->host = cpystr (hostname);
  425.                 /* get local name */
  426.   gethostname (hostname,MAILTMPLEN-1);
  427.   stream->localhost = cpystr ((host_name = gethostbyname (hostname)) ?
  428.                   host_name->h_name : hostname);
  429.   stream->tcpsi = pipei[0];    /* init sockets */
  430.   stream->tcpso = pipeo[1];
  431.   stream->ictr = 0;        /* init input counter */
  432.   return stream;        /* return success */
  433. }
  434.  
  435. /* TCP/IP receive line
  436.  * Accepts: TCP/IP stream
  437.  * Returns: text line string or NIL if failure
  438.  */
  439.  
  440. char *tcp_getline (stream)
  441.     TCPSTREAM *stream;
  442. {
  443.   int n,m;
  444.   char *st,*ret,*stp;
  445.   char c = '\0';
  446.   char d;
  447.                 /* make sure have data */
  448.   if (!tcp_getdata (stream)) return NIL;
  449.   st = stream->iptr;        /* save start of string */
  450.   n = 0;            /* init string count */
  451.   while (stream->ictr--) {    /* look for end of line */
  452.     d = *stream->iptr++;    /* slurp another character */
  453.     if ((c == '\015') && (d == '\012')) {
  454.       ret = (char *) fs_get (n--);
  455.       memcpy (ret,st,n);    /* copy into a free storage string */
  456.       ret[n] = '\0';        /* tie off string with null */
  457.       return ret;
  458.     }
  459.     n++;            /* count another character searched */
  460.     c = d;            /* remember previous character */
  461.   }
  462.                 /* copy partial string from buffer */
  463.   memcpy ((ret = stp = (char *) fs_get (n)),st,n);
  464.                 /* get more data from the net */
  465.   if (!tcp_getdata (stream)) return NIL;
  466.                 /* special case of newline broken by buffer */
  467.   if ((c == '\015') && (*stream->iptr == '\012')) {
  468.     stream->iptr++;        /* eat the line feed */
  469.     stream->ictr--;
  470.     ret[n - 1] = '\0';        /* tie off string with null */
  471.   }
  472.                 /* else recurse to get remainder */
  473.   else if (st = tcp_getline (stream)) {
  474.     ret = (char *) fs_get (n + 1 + (m = strlen (st)));
  475.     memcpy (ret,stp,n);        /* copy first part */
  476.     memcpy (ret + n,st,m);    /* and second part */
  477.     fs_give ((void **) &stp);    /* flush first part */
  478.     fs_give ((void **) &st);    /* flush second part */
  479.     ret[n + m] = '\0';        /* tie off string with null */
  480.   }
  481.   return ret;
  482. }
  483.  
  484. /* TCP/IP receive buffer
  485.  * Accepts: TCP/IP stream
  486.  *        size in bytes
  487.  *        buffer to read into
  488.  * Returns: T if success, NIL otherwise
  489.  */
  490.  
  491. long tcp_getbuffer (stream,size,buffer)
  492.     TCPSTREAM *stream;
  493.     unsigned long size;
  494.     char *buffer;
  495. {
  496.   unsigned long n;
  497.   char *bufptr = buffer;
  498.   while (size > 0) {        /* until request satisfied */
  499.     if (!tcp_getdata (stream)) return NIL;
  500.     n = min (size,stream->ictr);/* number of bytes to transfer */
  501.                 /* do the copy */
  502.     memcpy (bufptr,stream->iptr,n);
  503.     bufptr += n;        /* update pointer */
  504.     stream->iptr +=n;
  505.     size -= n;            /* update # of bytes to do */
  506.     stream->ictr -=n;
  507.   }
  508.   bufptr[0] = '\0';        /* tie off string */
  509.   return T;
  510. }
  511.  
  512.  
  513.  
  514. long tcp_abort ();
  515.  
  516. /* TCP/IP receive data
  517.  * Accepts: TCP/IP stream
  518.  * Returns: T if success, NIL otherwise
  519.  */
  520.  
  521. long tcp_getdata (stream)
  522.     TCPSTREAM *stream;
  523. {
  524.   int i;
  525.   fd_set fds;
  526.   FD_ZERO (&fds);        /* initialize selection vector */
  527.   if (stream->tcpsi < 0) return NIL;
  528.   while (stream->ictr < 1) {    /* if nothing in the buffer */
  529.     FD_SET (stream->tcpsi,&fds);/* set bit in selection vector */
  530.     errno = NIL;        /* block and read */
  531.     while (((i = select (stream->tcpsi+1,&fds,0,0,0)) < 0) &&
  532.        (errno == EINTR));
  533.     if (i < 0) return tcp_abort (stream);
  534.     while (((i = read (stream->tcpsi,stream->ibuf,BUFLEN)) < 1) &&
  535.        (errno == EINTR));
  536.     if (i < 1) return tcp_abort (stream);
  537.     stream->ictr = i;        /* set new byte count */
  538.     stream->iptr = stream->ibuf;/* point at TCP buffer */
  539.   }
  540.   return T;
  541. }
  542.  
  543. /* TCP/IP send string as record
  544.  * Accepts: TCP/IP stream
  545.  *        string pointer
  546.  * Returns: T if success else NIL
  547.  */
  548.  
  549. long tcp_soutr (stream,string)
  550.     TCPSTREAM *stream;
  551.     char *string;
  552. {
  553.   return tcp_sout (stream,string,(unsigned long) strlen (string));
  554. }
  555.  
  556.  
  557. /* TCP/IP send string
  558.  * Accepts: TCP/IP stream
  559.  *        string pointer
  560.  *        byte count
  561.  * Returns: T if success else NIL
  562.  */
  563.  
  564. long tcp_sout (stream,string,size)
  565.     TCPSTREAM *stream;
  566.     char *string;
  567.     unsigned long size;
  568. {
  569.   int i;
  570.   fd_set fds;
  571.   FD_ZERO (&fds);        /* initialize selection vector */
  572.   if (stream->tcpso < 0) return NIL;
  573.   while (size > 0) {        /* until request satisfied */
  574.     FD_SET (stream->tcpso,&fds);/* set bit in selection vector */
  575.     errno = NIL;        /* block and wrtie */
  576.     while (((i = select (stream->tcpso+1,0,&fds,0,0)) < 0) &&
  577.        (errno == EINTR));
  578.     if (i < 0) return tcp_abort (stream);
  579.     while (((i = write (stream->tcpso,string,size)) < 0) &&
  580.        (errno == EINTR));
  581.     if (i < 0) return tcp_abort (stream);
  582.     size -= i;            /* how much we sent */
  583.     string += i;
  584.   }
  585.   return T;            /* all done */
  586. }
  587.  
  588. /* TCP/IP close
  589.  * Accepts: TCP/IP stream
  590.  */
  591.  
  592. void tcp_close (stream)
  593.     TCPSTREAM *stream;
  594. {
  595.   tcp_abort (stream);        /* nuke the stream */
  596.                 /* flush host names */
  597.   fs_give ((void **) &stream->host);
  598.   fs_give ((void **) &stream->localhost);
  599.   fs_give ((void **) &stream);    /* flush the stream */
  600. }
  601.  
  602.  
  603. /* TCP/IP abort stream
  604.  * Accepts: TCP/IP stream
  605.  * Returns: NIL always
  606.  */
  607.  
  608. long tcp_abort (stream)
  609.      TCPSTREAM *stream;
  610. {
  611.   if (stream->tcpsi >= 0) {    /* no-op if no socket */
  612.     close (stream->tcpsi);    /* nuke the socket */
  613.     if (stream->tcpsi != stream->tcpso) close (stream->tcpso);
  614.     stream->tcpsi = stream->tcpso = -1;
  615.   }
  616.   return NIL;
  617. }
  618.  
  619. /* TCP/IP get host name
  620.  * Accepts: TCP/IP stream
  621.  * Returns: host name for this stream
  622.  */
  623.  
  624. char *tcp_host (stream)
  625.     TCPSTREAM *stream;
  626. {
  627.   return stream->host;        /* return host name */
  628. }
  629.  
  630.  
  631. /* TCP/IP get local host name
  632.  * Accepts: TCP/IP stream
  633.  * Returns: local host name
  634.  */
  635.  
  636. char *tcp_localhost (stream)
  637.     TCPSTREAM *stream;
  638. {
  639.   return stream->localhost;    /* return local host name */
  640. }
  641.  
  642. /* Return implementation-defined string corresponding to error
  643.  * Accepts: error number
  644.  * Returns: string for that error
  645.  */
  646.  
  647. char *strerror (n)
  648.      int n;
  649. {
  650.   return (n >= 0 && n < sys_nerr) ? sys_errlist[n] : NIL;
  651. }
  652.  
  653.  
  654. /* Copy memory block
  655.  * Accepts: destination pointer
  656.  *        source pointer
  657.  *        length
  658.  * Returns: destination pointer
  659.  */
  660.  
  661. char *memmove (s,ct,n)
  662.      char *s;
  663.      char *ct;
  664.      int n;
  665. {
  666.   bcopy (ct,s,n);        /* they should have this one */
  667.   return ct;
  668. }
  669.