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

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