]> git.sesse.net Git - rdpsrv/blob - Xserver/lib/Xdmcp/Flush.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / lib / Xdmcp / Flush.c
1 /*
2  * $XConsortium: Flush.c /main/11 1996/11/13 14:44:22 lehors $
3  * $XFree86: xc/lib/Xdmcp/Flush.c,v 3.4 1997/01/18 06:52:07 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 int
57 XdmcpFlush (fd, buffer, to, tolen)
58     int             fd;
59     XdmcpBufferPtr  buffer;
60     XdmcpNetaddr    to;
61     int             tolen;
62 {
63     int result;
64 #ifdef MINIX
65     struct sockaddr_in *to_addr;
66     char *b;
67     udp_io_hdr_t *udp_io_hdr;
68     int flags, s_errno;
69 #endif /* MINIX */
70
71 #ifdef STREAMSCONN
72     struct t_unitdata dataunit;
73
74     dataunit.addr.buf = to;
75     dataunit.addr.len = tolen;
76     dataunit.opt.len = 0;       /* default options */
77     dataunit.udata.buf = (char *)buffer->data;
78     dataunit.udata.len = buffer->pointer;
79     result = t_sndudata(fd, &dataunit);
80     if (result < 0)
81         return FALSE;
82 #else
83 #ifndef MINIX
84     result = sendto (fd, (char *)buffer->data, buffer->pointer, 0,
85                      (struct sockaddr *)to, tolen);
86     if (result != buffer->pointer)
87         return FALSE;
88 #else /* MINIX */
89     to_addr= (struct sockaddr_in *)to;
90     b= (char *)Xalloc(buffer->pointer + sizeof(udp_io_hdr_t));
91     if (b == NULL)
92         return FALSE;
93     udp_io_hdr= (udp_io_hdr_t *)b;
94     bcopy((char *)buffer->data, b+sizeof(udp_io_hdr_t), buffer->pointer);
95     udp_io_hdr->uih_dst_addr= to_addr->sin_addr.s_addr;
96     udp_io_hdr->uih_dst_port= to_addr->sin_port;
97     udp_io_hdr->uih_ip_opt_len= 0;
98     udp_io_hdr->uih_data_len= buffer->pointer;
99
100     /* Make the write synchronous by turning of asynch I/O */
101     flags= fcntl(fd, F_GETFD);
102     fcntl(fd, F_SETFD, flags & ~FD_ASYNCHIO);
103     result= write(fd, b, buffer->pointer + sizeof(udp_io_hdr_t));
104     s_errno= errno;
105     Xfree(b);
106     fcntl(fd, F_SETFD, flags);
107     if (result != buffer->pointer + sizeof(udp_io_hdr_t))
108         return FALSE;
109 #endif /* MINIX */
110 #endif
111     return TRUE;
112 }