]> git.sesse.net Git - rdpsrv/blob - Xserver/lib/Xdmcp/Fill.c
Support RDP5 logon packets.
[rdpsrv] / Xserver / lib / Xdmcp / Fill.c
1 /*
2  * $XConsortium: Fill.c /main/11 1996/11/13 14:44:18 lehors $
3  * $XFree86: xc/lib/Xdmcp/Fill.c,v 3.4 1997/01/18 06:52:06 dawes Exp $
4  *
5  * 
6 Copyright (c) 1989  X Consortium
7
8 Permission is hereby granted, free of charge, to any person obtaining a copy
9 of this software and associated documentation files (the "Software"), to deal
10 in the Software without restriction, including without limitation the rights
11 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the Software is
13 furnished to do so, subject to the following conditions:
14
15 The above copyright notice and this permission notice shall be included in
16 all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
21 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24
25 Except as contained in this notice, the name of the X Consortium shall not be
26 used in advertising or otherwise to promote the sale, use or other dealings
27 in this Software without prior written authorization from the X Consortium.
28  * *
29  * Author:  Keith Packard, MIT X Consortium
30  */
31
32 #ifdef WIN32
33 #define _WILLWINSOCK_
34 #endif
35 #include <X11/Xos.h>
36 #include <X11/X.h>
37 #include <X11/Xmd.h>
38 #include <X11/Xdmcp.h>
39
40 #ifdef STREAMSCONN
41 #include <tiuser.h>
42 #else
43 #ifdef WIN32
44 #include <X11/Xwinsock.h>
45 #else
46 #ifndef MINIX
47 #ifndef Lynx
48 #include <sys/socket.h>
49 #else
50 #include <socket.h>
51 #endif /* !Lynx */
52 #endif /* !MINIX */
53 #endif
54 #endif
55
56 #ifndef MINIX
57 int
58 XdmcpFill (fd, buffer, from, fromlen)
59     int             fd;
60     XdmcpBufferPtr  buffer;
61     XdmcpNetaddr    from;       /* return */
62     int             *fromlen;   /* return */
63 {
64     BYTE    *newBuf;
65 #ifdef STREAMSCONN
66     struct t_unitdata dataunit;
67     int gotallflag, result;
68 #endif
69
70     if (buffer->size < XDM_MAX_MSGLEN)
71     {
72         newBuf = (BYTE *) Xalloc (XDM_MAX_MSGLEN);
73         if (newBuf)
74         {
75             Xfree (buffer->data);
76             buffer->data = newBuf;
77             buffer->size = XDM_MAX_MSGLEN;
78         }
79     }
80     buffer->pointer = 0;
81 #ifdef STREAMSCONN
82     dataunit.addr.buf = from;
83     dataunit.addr.maxlen = *fromlen;
84     dataunit.opt.maxlen = 0;    /* don't care to know about options */
85     dataunit.udata.buf = (char *)buffer->data;
86     dataunit.udata.maxlen = buffer->size;
87     result = t_rcvudata (fd, &dataunit, &gotallflag);
88     if (result < 0) {
89         return FALSE;
90     }
91     buffer->count = dataunit.udata.len;
92     *fromlen = dataunit.addr.len;
93 #else
94     buffer->count = recvfrom (fd, (char*)buffer->data, buffer->size, 0,
95                               (struct sockaddr *)from, fromlen);
96 #endif
97     if (buffer->count < 6) {
98         buffer->count = 0;
99         return FALSE;
100     }
101     return TRUE;
102 }
103 #else /* MINIX */
104 int
105 MNX_XdmcpFill (fd, buffer, from, fromlen, data, datalen)
106     int             fd;
107     XdmcpBufferPtr  buffer;
108     XdmcpNetaddr    from;       /* return */
109     int             *fromlen;   /* return */
110     char            *data;
111     int             datalen;
112 {
113     BYTE    *newBuf;
114     struct sockaddr_in *from_addr;
115     udp_io_hdr_t *udp_io_hdr;
116
117     if (buffer->size < XDM_MAX_MSGLEN)
118     {
119         newBuf = (BYTE *) Xalloc (XDM_MAX_MSGLEN);
120         if (newBuf)
121         {
122             Xfree (buffer->data);
123             buffer->data = newBuf;
124             buffer->size = XDM_MAX_MSGLEN;
125         }
126     }
127     buffer->pointer = 0;
128     udp_io_hdr= (udp_io_hdr_t *)data;
129     data += sizeof(udp_io_hdr_t) + udp_io_hdr->uih_ip_opt_len;
130     datalen -= sizeof(udp_io_hdr_t) + udp_io_hdr->uih_ip_opt_len;
131     buffer->count= udp_io_hdr->uih_data_len;
132     if (buffer->count > datalen)
133     {
134         buffer->count= 0;
135         return FALSE;
136     }
137     bcopy(data, (char *)buffer->data, buffer->count);
138     from_addr= (struct sockaddr_in *)from;
139     from_addr->sin_family= AF_INET;
140     from_addr->sin_addr.s_addr= udp_io_hdr->uih_src_addr;
141     from_addr->sin_port= udp_io_hdr->uih_src_port;
142     if (buffer->count < 6) {
143         buffer->count = 0;
144         return FALSE;
145     }
146     return TRUE;
147 }
148 #endif /* !MINIX */