home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / lib / Xdmcp / Fill.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-16  |  2.5 KB  |  83 lines

  1. /*
  2.  * $XConsortium: Fill.c,v 1.4 91/07/16 20:33:50 gildea Exp $
  3.  *
  4.  * Copyright 1989 Massachusetts Institute of Technology
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software and its
  7.  * documentation for any purpose and without fee is hereby granted, provided
  8.  * that the above copyright notice appear in all copies and that both that
  9.  * copyright notice and this permission notice appear in supporting
  10.  * documentation, and that the name of M.I.T. not be used in advertising
  11.  * or publicity pertaining to distribution of the software without specific,
  12.  * written prior permission.  M.I.T. makes no representations about the
  13.  * suitability of this software for any purpose.  It is provided "as is"
  14.  * without express or implied warranty.
  15.  *
  16.  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
  18.  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20.  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 
  21.  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22.  *
  23.  * Author:  Keith Packard, MIT X Consortium
  24.  */
  25.  
  26. #include <X11/Xos.h>
  27. #include <X11/X.h>
  28. #include <X11/Xmd.h>
  29. #include <X11/Xdmcp.h>
  30.  
  31. #ifdef STREAMSCONN
  32. #include <tiuser.h>
  33. #else
  34. #include <sys/socket.h>
  35. #endif
  36.  
  37. int
  38. XdmcpFill (fd, buffer, from, fromlen)
  39.     int            fd;
  40.     XdmcpBufferPtr  buffer;
  41.     XdmcpNetaddr    from;    /* return */
  42.     int            *fromlen;    /* return */
  43. {
  44.     BYTE    *newBuf;
  45. #ifdef STREAMSCONN
  46.     struct t_unitdata dataunit;
  47.     int gotallflag, result;
  48. #endif
  49.  
  50.     if (buffer->size < XDM_MAX_MSGLEN)
  51.     {
  52.     newBuf = (BYTE *) Xalloc (XDM_MAX_MSGLEN);
  53.     if (newBuf)
  54.     {
  55.         Xfree (buffer->data);
  56.         buffer->data = newBuf;
  57.         buffer->size = XDM_MAX_MSGLEN;
  58.     }
  59.     }
  60.     buffer->pointer = 0;
  61. #ifdef STREAMSCONN
  62.     dataunit.addr.buf = from;
  63.     dataunit.addr.maxlen = *fromlen;
  64.     dataunit.opt.maxlen = 0;    /* don't care to know about options */
  65.     dataunit.udata.buf = (char *)buffer->data;
  66.     dataunit.udata.maxlen = buffer->size;
  67.     result = t_rcvudata (fd, &dataunit, &gotallflag);
  68.     if (result < 0) {
  69.     return FALSE;
  70.     }
  71.     buffer->count = dataunit.udata.len;
  72.     *fromlen = dataunit.addr.len;
  73. #else
  74.     buffer->count = recvfrom (fd, buffer->data, buffer->size, 0,
  75.                   (struct sockaddr *)from, fromlen);
  76. #endif
  77.     if (buffer->count < 6) {
  78.     buffer->count = 0;
  79.     return FALSE;
  80.     }
  81.     return TRUE;
  82. }
  83.