Fill.c revision 44dda7b2
1ff559fabSmrg/*
2ff559fabSmrgCopyright 1989, 1998  The Open Group
3ff559fabSmrg
4ff559fabSmrgPermission to use, copy, modify, distribute, and sell this software and its
5ff559fabSmrgdocumentation for any purpose is hereby granted without fee, provided that
6ff559fabSmrgthe above copyright notice appear in all copies and that both that
7ff559fabSmrgcopyright notice and this permission notice appear in supporting
8ff559fabSmrgdocumentation.
9ff559fabSmrg
10ff559fabSmrgThe above copyright notice and this permission notice shall be included in
11ff559fabSmrgall copies or substantial portions of the Software.
12ff559fabSmrg
13ff559fabSmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14ff559fabSmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15ff559fabSmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
16ff559fabSmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
17ff559fabSmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18ff559fabSmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19ff559fabSmrg
20ff559fabSmrgExcept as contained in this notice, the name of The Open Group shall not be
21ff559fabSmrgused in advertising or otherwise to promote the sale, use or other dealings
22ff559fabSmrgin this Software without prior written authorization from The Open Group.
23ff559fabSmrg * *
24ff559fabSmrg * Author:  Keith Packard, MIT X Consortium
25ff559fabSmrg */
26ff559fabSmrg
27ff559fabSmrg#ifdef WIN32
28ff559fabSmrg#define _WILLWINSOCK_
29ff559fabSmrg#endif
30ff559fabSmrg#ifdef HAVE_CONFIG_H
31ff559fabSmrg#include <config.h>
32ff559fabSmrg#endif
33ff559fabSmrg#include <X11/Xos.h>
34ff559fabSmrg#include <X11/X.h>
35ff559fabSmrg#include <X11/Xmd.h>
36ff559fabSmrg#include <X11/Xdmcp.h>
3744dda7b2Smrg#include <stdlib.h>
38ff559fabSmrg
39ff559fabSmrg#ifdef STREAMSCONN
40ff559fabSmrg#include <tiuser.h>
41ff559fabSmrg#else
42ff559fabSmrg#ifdef WIN32
43ff559fabSmrg#include <X11/Xwinsock.h>
44ff559fabSmrg#else
45ff559fabSmrg#include <sys/socket.h>
46ff559fabSmrg#endif
47ff559fabSmrg#endif
48ff559fabSmrg
49ff559fabSmrgint
507a3b38f7SmrgXdmcpFill (int fd, XdmcpBufferPtr buffer, XdmcpNetaddr from, int *fromlen)
51ff559fabSmrg{
52ff559fabSmrg    BYTE    *newBuf;
53ff559fabSmrg#ifdef STREAMSCONN
54ff559fabSmrg    struct t_unitdata dataunit;
55ff559fabSmrg    int gotallflag, result;
56ff559fabSmrg#endif
57ff559fabSmrg
58ff559fabSmrg    if (buffer->size < XDM_MAX_MSGLEN)
59ff559fabSmrg    {
6044dda7b2Smrg	newBuf = (BYTE *) malloc(XDM_MAX_MSGLEN);
61ff559fabSmrg	if (newBuf)
62ff559fabSmrg	{
6344dda7b2Smrg	    free(buffer->data);
64ff559fabSmrg	    buffer->data = newBuf;
65ff559fabSmrg	    buffer->size = XDM_MAX_MSGLEN;
66ff559fabSmrg	}
67ff559fabSmrg    }
68ff559fabSmrg    buffer->pointer = 0;
69ff559fabSmrg#ifdef STREAMSCONN
70ff559fabSmrg    dataunit.addr.buf = from;
71ff559fabSmrg    dataunit.addr.maxlen = *fromlen;
72ff559fabSmrg    dataunit.opt.maxlen = 0;	/* don't care to know about options */
73ff559fabSmrg    dataunit.udata.buf = (char *)buffer->data;
74ff559fabSmrg    dataunit.udata.maxlen = buffer->size;
75ff559fabSmrg    result = t_rcvudata (fd, &dataunit, &gotallflag);
76ff559fabSmrg    if (result < 0) {
77ff559fabSmrg	return FALSE;
78ff559fabSmrg    }
79ff559fabSmrg    buffer->count = dataunit.udata.len;
80ff559fabSmrg    *fromlen = dataunit.addr.len;
81ff559fabSmrg#else
82ff559fabSmrg    buffer->count = recvfrom (fd, (char*)buffer->data, buffer->size, 0,
83ff559fabSmrg			      (struct sockaddr *)from, (void *)fromlen);
84ff559fabSmrg#endif
85ff559fabSmrg    if (buffer->count < 6) {
86ff559fabSmrg	buffer->count = 0;
87ff559fabSmrg	return FALSE;
88ff559fabSmrg    }
89ff559fabSmrg    return TRUE;
90ff559fabSmrg}
91