os: if inet_ntop() is available, use it for IPv4 addresses as well
[xserver.git] / Xext / xcmisc.c
blobb70e54ed4e8bd18d266e16f2824b12e941e0a380
1 /*
3 Copyright 1993, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of The Open Group shall
23 not be used in advertising or otherwise to promote the sale, use or
24 other dealings in this Software without prior written authorization
25 from The Open Group.
29 #include <dix-config.h>
31 #include <X11/X.h>
32 #include <X11/Xproto.h>
33 #include "misc.h"
34 #include "os.h"
35 #include "dixstruct.h"
36 #include "extnsionst.h"
37 #include "swaprep.h"
38 #include <X11/extensions/xcmiscproto.h>
39 #include "extinit_priv.h"
41 #include <stdint.h>
43 static int
44 ProcXCMiscGetVersion(ClientPtr client)
46 xXCMiscGetVersionReply rep = {
47 .type = X_Reply,
48 .sequenceNumber = client->sequence,
49 .length = 0,
50 .majorVersion = XCMiscMajorVersion,
51 .minorVersion = XCMiscMinorVersion
54 REQUEST_SIZE_MATCH(xXCMiscGetVersionReq);
56 if (client->swapped) {
57 swaps(&rep.sequenceNumber);
58 swaps(&rep.majorVersion);
59 swaps(&rep.minorVersion);
61 WriteToClient(client, sizeof(xXCMiscGetVersionReply), &rep);
62 return Success;
65 static int
66 ProcXCMiscGetXIDRange(ClientPtr client)
68 xXCMiscGetXIDRangeReply rep;
69 XID min_id, max_id;
71 REQUEST_SIZE_MATCH(xXCMiscGetXIDRangeReq);
72 GetXIDRange(client->index, FALSE, &min_id, &max_id);
73 rep = (xXCMiscGetXIDRangeReply) {
74 .type = X_Reply,
75 .sequenceNumber = client->sequence,
76 .length = 0,
77 .start_id = min_id,
78 .count = max_id - min_id + 1
80 if (client->swapped) {
81 swaps(&rep.sequenceNumber);
82 swapl(&rep.start_id);
83 swapl(&rep.count);
85 WriteToClient(client, sizeof(xXCMiscGetXIDRangeReply), &rep);
86 return Success;
89 static int
90 ProcXCMiscGetXIDList(ClientPtr client)
92 REQUEST(xXCMiscGetXIDListReq);
93 xXCMiscGetXIDListReply rep;
94 XID *pids;
95 unsigned int count;
97 REQUEST_SIZE_MATCH(xXCMiscGetXIDListReq);
99 if (stuff->count > UINT32_MAX / sizeof(XID))
100 return BadAlloc;
102 pids = xallocarray(stuff->count, sizeof(XID));
103 if (!pids) {
104 return BadAlloc;
106 count = GetXIDList(client, stuff->count, pids);
107 rep = (xXCMiscGetXIDListReply) {
108 .type = X_Reply,
109 .sequenceNumber = client->sequence,
110 .length = count,
111 .count = count
113 if (client->swapped) {
114 swaps(&rep.sequenceNumber);
115 swapl(&rep.length);
116 swapl(&rep.count);
118 WriteToClient(client, sizeof(xXCMiscGetXIDListReply), &rep);
119 if (count) {
120 client->pSwapReplyFunc = (ReplySwapPtr) Swap32Write;
121 WriteSwappedDataToClient(client, count * sizeof(XID), pids);
123 free(pids);
124 return Success;
127 static int
128 ProcXCMiscDispatch(ClientPtr client)
130 REQUEST(xReq);
131 switch (stuff->data) {
132 case X_XCMiscGetVersion:
133 return ProcXCMiscGetVersion(client);
134 case X_XCMiscGetXIDRange:
135 return ProcXCMiscGetXIDRange(client);
136 case X_XCMiscGetXIDList:
137 return ProcXCMiscGetXIDList(client);
138 default:
139 return BadRequest;
143 static int _X_COLD
144 SProcXCMiscGetVersion(ClientPtr client)
146 REQUEST(xXCMiscGetVersionReq);
148 swaps(&stuff->length);
149 REQUEST_SIZE_MATCH(xXCMiscGetVersionReq);
150 swaps(&stuff->majorVersion);
151 swaps(&stuff->minorVersion);
152 return ProcXCMiscGetVersion(client);
155 static int _X_COLD
156 SProcXCMiscGetXIDRange(ClientPtr client)
158 REQUEST(xReq);
160 swaps(&stuff->length);
161 return ProcXCMiscGetXIDRange(client);
164 static int _X_COLD
165 SProcXCMiscGetXIDList(ClientPtr client)
167 REQUEST(xXCMiscGetXIDListReq);
168 REQUEST_SIZE_MATCH(xXCMiscGetXIDListReq);
170 swaps(&stuff->length);
171 swapl(&stuff->count);
172 return ProcXCMiscGetXIDList(client);
175 static int _X_COLD
176 SProcXCMiscDispatch(ClientPtr client)
178 REQUEST(xReq);
179 switch (stuff->data) {
180 case X_XCMiscGetVersion:
181 return SProcXCMiscGetVersion(client);
182 case X_XCMiscGetXIDRange:
183 return SProcXCMiscGetXIDRange(client);
184 case X_XCMiscGetXIDList:
185 return SProcXCMiscGetXIDList(client);
186 default:
187 return BadRequest;
191 void
192 XCMiscExtensionInit(void)
194 AddExtension(XCMiscExtensionName, 0, 0,
195 ProcXCMiscDispatch, SProcXCMiscDispatch,
196 NULL, StandardMinorOpcode);