Host.c revision e9fcaa8a
1/* 2 3Copyright 1986, 1998 The Open Group 4 5All rights reserved. 6 7Permission is hereby granted, free of charge, to any person obtaining a 8copy of this software and associated documentation files (the 9"Software"), to deal in the Software without restriction, including 10without limitation the rights to use, copy, modify, merge, publish, 11distribute, and/or sell copies of the Software, and to permit persons 12to whom the Software is furnished to do so, provided that the above 13copyright notice(s) and this permission notice appear in all copies of 14the Software and that both the above copyright notice(s) and this 15permission notice appear in supporting documentation. 16 17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 20OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 21HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL 22INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING 23FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 24NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 25WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 26 27Except as contained in this notice, the name of a copyright holder 28shall not be used in advertising or otherwise to promote the sale, use 29or other dealings in this Software without prior written authorization 30of the copyright holder. 31 32X Window System is a trademark of The Open Group. 33 34*/ 35 36/* 37 * Copyright 2004 Oracle and/or its affiliates. All rights reserved. 38 * 39 * Permission is hereby granted, free of charge, to any person obtaining a 40 * copy of this software and associated documentation files (the "Software"), 41 * to deal in the Software without restriction, including without limitation 42 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 43 * and/or sell copies of the Software, and to permit persons to whom the 44 * Software is furnished to do so, subject to the following conditions: 45 * 46 * The above copyright notice and this permission notice (including the next 47 * paragraph) shall be included in all copies or substantial portions of the 48 * Software. 49 * 50 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 51 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 52 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 53 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 54 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 55 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 56 * DEALINGS IN THE SOFTWARE. 57 */ 58 59 60/* this might be rightly regarded an os dependent file */ 61 62#ifdef HAVE_CONFIG_H 63#include <config.h> 64#endif 65#include "Xlibint.h" 66 67int 68XAddHost ( 69 register Display *dpy, 70 XHostAddress *host) 71{ 72 register xChangeHostsReq *req; 73 register int length; 74 XServerInterpretedAddress *siAddr; 75 int addrlen; 76 77 siAddr = host->family == FamilyServerInterpreted ? 78 (XServerInterpretedAddress *)host->address : NULL; 79 addrlen = siAddr ? 80 siAddr->typelength + siAddr->valuelength + 1 : host->length; 81 82 length = (addrlen + 3) & ~0x3; /* round up */ 83 84 LockDisplay(dpy); 85 GetReqExtra (ChangeHosts, length, req); 86 req->mode = HostInsert; 87 req->hostFamily = host->family; 88 req->hostLength = addrlen; 89 if (siAddr) { 90 char *dest = (char *) NEXTPTR(req,xChangeHostsReq); 91 memcpy(dest, siAddr->type, siAddr->typelength); 92 dest[siAddr->typelength] = '\0'; 93 memcpy(dest + siAddr->typelength + 1,siAddr->value,siAddr->valuelength); 94 } else { 95 memcpy((char *) NEXTPTR(req,xChangeHostsReq), host->address, addrlen); 96 } 97 UnlockDisplay(dpy); 98 SyncHandle(); 99 return 1; 100} 101 102int 103XRemoveHost ( 104 register Display *dpy, 105 XHostAddress *host) 106{ 107 register xChangeHostsReq *req; 108 register int length; 109 XServerInterpretedAddress *siAddr; 110 int addrlen; 111 112 siAddr = host->family == FamilyServerInterpreted ? 113 (XServerInterpretedAddress *)host->address : NULL; 114 addrlen = siAddr ? 115 siAddr->typelength + siAddr->valuelength + 1 : host->length; 116 117 length = (addrlen + 3) & ~0x3; /* round up */ 118 119 LockDisplay(dpy); 120 GetReqExtra (ChangeHosts, length, req); 121 req->mode = HostDelete; 122 req->hostFamily = host->family; 123 req->hostLength = addrlen; 124 if (siAddr) { 125 char *dest = (char *) NEXTPTR(req,xChangeHostsReq); 126 memcpy(dest, siAddr->type, siAddr->typelength); 127 dest[siAddr->typelength] = '\0'; 128 memcpy(dest + siAddr->typelength + 1,siAddr->value,siAddr->valuelength); 129 } else { 130 memcpy((char *) NEXTPTR(req,xChangeHostsReq), host->address, addrlen); 131 } 132 UnlockDisplay(dpy); 133 SyncHandle(); 134 return 1; 135} 136 137int 138XAddHosts ( 139 register Display *dpy, 140 XHostAddress *hosts, 141 int n) 142{ 143 register int i; 144 for (i = 0; i < n; i++) { 145 (void) XAddHost(dpy, &hosts[i]); 146 } 147 return 1; 148} 149 150int 151XRemoveHosts ( 152 register Display *dpy, 153 XHostAddress *hosts, 154 int n) 155{ 156 register int i; 157 for (i = 0; i < n; i++) { 158 (void) XRemoveHost(dpy, &hosts[i]); 159 } 160 return 1; 161} 162