Host.c revision e9fcaa8a
11ab64890Smrg/* 21ab64890Smrg 31ab64890SmrgCopyright 1986, 1998 The Open Group 41ab64890Smrg 51ab64890SmrgAll rights reserved. 61ab64890Smrg 71ab64890SmrgPermission is hereby granted, free of charge, to any person obtaining a 81ab64890Smrgcopy of this software and associated documentation files (the 91ab64890Smrg"Software"), to deal in the Software without restriction, including 101ab64890Smrgwithout limitation the rights to use, copy, modify, merge, publish, 111ab64890Smrgdistribute, and/or sell copies of the Software, and to permit persons 121ab64890Smrgto whom the Software is furnished to do so, provided that the above 131ab64890Smrgcopyright notice(s) and this permission notice appear in all copies of 141ab64890Smrgthe Software and that both the above copyright notice(s) and this 151ab64890Smrgpermission notice appear in supporting documentation. 161ab64890Smrg 171ab64890SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 181ab64890SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 191ab64890SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 201ab64890SmrgOF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 211ab64890SmrgHOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL 221ab64890SmrgINDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING 231ab64890SmrgFROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 241ab64890SmrgNEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 251ab64890SmrgWITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 261ab64890Smrg 271ab64890SmrgExcept as contained in this notice, the name of a copyright holder 281ab64890Smrgshall not be used in advertising or otherwise to promote the sale, use 291ab64890Smrgor other dealings in this Software without prior written authorization 301ab64890Smrgof the copyright holder. 311ab64890Smrg 321ab64890SmrgX Window System is a trademark of The Open Group. 331ab64890Smrg 341ab64890Smrg*/ 35b4ee4795Smrg 36b4ee4795Smrg/* 37e9fcaa8aSmrg * Copyright 2004 Oracle and/or its affiliates. All rights reserved. 38b4ee4795Smrg * 39b4ee4795Smrg * Permission is hereby granted, free of charge, to any person obtaining a 40b4ee4795Smrg * copy of this software and associated documentation files (the "Software"), 41b4ee4795Smrg * to deal in the Software without restriction, including without limitation 42b4ee4795Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 43b4ee4795Smrg * and/or sell copies of the Software, and to permit persons to whom the 44b4ee4795Smrg * Software is furnished to do so, subject to the following conditions: 45b4ee4795Smrg * 46b4ee4795Smrg * The above copyright notice and this permission notice (including the next 47b4ee4795Smrg * paragraph) shall be included in all copies or substantial portions of the 48b4ee4795Smrg * Software. 49b4ee4795Smrg * 50b4ee4795Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 51b4ee4795Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 52b4ee4795Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 53b4ee4795Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 54b4ee4795Smrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 55b4ee4795Smrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 56b4ee4795Smrg * DEALINGS IN THE SOFTWARE. 57b4ee4795Smrg */ 58b4ee4795Smrg 591ab64890Smrg 601ab64890Smrg/* this might be rightly regarded an os dependent file */ 611ab64890Smrg 621ab64890Smrg#ifdef HAVE_CONFIG_H 631ab64890Smrg#include <config.h> 641ab64890Smrg#endif 651ab64890Smrg#include "Xlibint.h" 661ab64890Smrg 671ab64890Smrgint 681ab64890SmrgXAddHost ( 691ab64890Smrg register Display *dpy, 701ab64890Smrg XHostAddress *host) 711ab64890Smrg{ 721ab64890Smrg register xChangeHostsReq *req; 731ab64890Smrg register int length; 741ab64890Smrg XServerInterpretedAddress *siAddr; 751ab64890Smrg int addrlen; 761ab64890Smrg 7761b2299dSmrg siAddr = host->family == FamilyServerInterpreted ? 7861b2299dSmrg (XServerInterpretedAddress *)host->address : NULL; 7961b2299dSmrg addrlen = siAddr ? 8061b2299dSmrg siAddr->typelength + siAddr->valuelength + 1 : host->length; 8161b2299dSmrg 821ab64890Smrg length = (addrlen + 3) & ~0x3; /* round up */ 831ab64890Smrg 841ab64890Smrg LockDisplay(dpy); 851ab64890Smrg GetReqExtra (ChangeHosts, length, req); 861ab64890Smrg req->mode = HostInsert; 871ab64890Smrg req->hostFamily = host->family; 881ab64890Smrg req->hostLength = addrlen; 8961b2299dSmrg if (siAddr) { 901ab64890Smrg char *dest = (char *) NEXTPTR(req,xChangeHostsReq); 911ab64890Smrg memcpy(dest, siAddr->type, siAddr->typelength); 921ab64890Smrg dest[siAddr->typelength] = '\0'; 931ab64890Smrg memcpy(dest + siAddr->typelength + 1,siAddr->value,siAddr->valuelength); 941ab64890Smrg } else { 951ab64890Smrg memcpy((char *) NEXTPTR(req,xChangeHostsReq), host->address, addrlen); 961ab64890Smrg } 971ab64890Smrg UnlockDisplay(dpy); 981ab64890Smrg SyncHandle(); 991ab64890Smrg return 1; 1001ab64890Smrg} 1011ab64890Smrg 1021ab64890Smrgint 1031ab64890SmrgXRemoveHost ( 1041ab64890Smrg register Display *dpy, 1051ab64890Smrg XHostAddress *host) 1061ab64890Smrg{ 1071ab64890Smrg register xChangeHostsReq *req; 1081ab64890Smrg register int length; 1091ab64890Smrg XServerInterpretedAddress *siAddr; 1101ab64890Smrg int addrlen; 1111ab64890Smrg 11261b2299dSmrg siAddr = host->family == FamilyServerInterpreted ? 11361b2299dSmrg (XServerInterpretedAddress *)host->address : NULL; 11461b2299dSmrg addrlen = siAddr ? 11561b2299dSmrg siAddr->typelength + siAddr->valuelength + 1 : host->length; 11661b2299dSmrg 1171ab64890Smrg length = (addrlen + 3) & ~0x3; /* round up */ 1181ab64890Smrg 1191ab64890Smrg LockDisplay(dpy); 1201ab64890Smrg GetReqExtra (ChangeHosts, length, req); 1211ab64890Smrg req->mode = HostDelete; 1221ab64890Smrg req->hostFamily = host->family; 1231ab64890Smrg req->hostLength = addrlen; 12461b2299dSmrg if (siAddr) { 1251ab64890Smrg char *dest = (char *) NEXTPTR(req,xChangeHostsReq); 1261ab64890Smrg memcpy(dest, siAddr->type, siAddr->typelength); 1271ab64890Smrg dest[siAddr->typelength] = '\0'; 1281ab64890Smrg memcpy(dest + siAddr->typelength + 1,siAddr->value,siAddr->valuelength); 1291ab64890Smrg } else { 1301ab64890Smrg memcpy((char *) NEXTPTR(req,xChangeHostsReq), host->address, addrlen); 1311ab64890Smrg } 1321ab64890Smrg UnlockDisplay(dpy); 1331ab64890Smrg SyncHandle(); 1341ab64890Smrg return 1; 1351ab64890Smrg} 1361ab64890Smrg 1371ab64890Smrgint 1381ab64890SmrgXAddHosts ( 1391ab64890Smrg register Display *dpy, 1401ab64890Smrg XHostAddress *hosts, 1411ab64890Smrg int n) 1421ab64890Smrg{ 1431ab64890Smrg register int i; 1441ab64890Smrg for (i = 0; i < n; i++) { 1451ab64890Smrg (void) XAddHost(dpy, &hosts[i]); 1461ab64890Smrg } 1471ab64890Smrg return 1; 1481ab64890Smrg} 1491ab64890Smrg 1501ab64890Smrgint 1511ab64890SmrgXRemoveHosts ( 1521ab64890Smrg register Display *dpy, 1531ab64890Smrg XHostAddress *hosts, 1541ab64890Smrg int n) 1551ab64890Smrg{ 1561ab64890Smrg register int i; 1571ab64890Smrg for (i = 0; i < n; i++) { 1581ab64890Smrg (void) XRemoveHost(dpy, &hosts[i]); 1591ab64890Smrg } 1601ab64890Smrg return 1; 1611ab64890Smrg} 162