2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: socket.c /main/9 1997/12/23 12:25:32 bill $ */
24 /* (c) Copyright 1997 The Open Group */
26 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
27 * (c) Copyright 1993, 1994 International Business Machines Corp. *
28 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
29 * (c) Copyright 1993, 1994 Novell, Inc. *
38 * Revision 1.1.2.3 1995/06/06 20:24:26 Chris_Beute
39 * Code snapshot merge from March 15 and SIA changes
40 * [1995/05/31 20:15:01 Chris_Beute]
42 * Revision 1.1.2.2 1995/04/21 13:05:38 Peter_Derr
43 * dtlogin auth key fixes from deltacde
44 * [1995/04/12 19:21:26 Peter_Derr]
46 * R6 xdm version used to pick up XDMCP improvements.
47 * [1995/04/12 18:05:54 Peter_Derr]
53 Copyright (c) 1988 X Consortium
55 Permission is hereby granted, free of charge, to any person obtaining
56 a copy of this software and associated documentation files (the
57 "Software"), to deal in the Software without restriction, including
58 without limitation the rights to use, copy, modify, merge, publish,
59 distribute, sublicense, and/or sell copies of the Software, and to
60 permit persons to whom the Software is furnished to do so, subject to
61 the following conditions:
63 The above copyright notice and this permission notice shall be included
64 in all copies or substantial portions of the Software.
66 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
67 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
68 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
69 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
70 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
71 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
72 OTHER DEALINGS IN THE SOFTWARE.
74 Except as contained in this notice, the name of the X Consortium shall
75 not be used in advertising or otherwise to promote the sale, use or
76 other dealings in this Software without prior written authorization
77 from the X Consortium.
82 * xdm - display manager daemon
83 * Author: Keith Packard, MIT X Consortium
85 * socket.c - Support for BSD sockets
92 #include <sys/socket.h>
93 #include <netinet/in.h>
103 extern int chooserFd;
105 extern FD_TYPE WellKnownSocketsMask;
106 extern int WellKnownSocketsMax;
108 CreateWellKnownSockets ()
110 struct sockaddr_in sock_addr;
111 char *name, *localHostname();
113 if (request_port == 0)
115 Debug ("creating socket %d\n", request_port);
116 xdmcpFd = socket (AF_INET, SOCK_DGRAM, 0);
118 LogError (ReadCatalog(MC_LOG_SET,MC_LOG_FAIL_SOCK,MC_DEF_LOG_FAIL_SOCK),
122 name = localHostname ();
123 registerHostname (name, strlen (name));
124 RegisterCloseOnFork (xdmcpFd);
125 /* zero out the entire structure; this avoids 4.4 incompatibilities */
126 bzero ((char *) &sock_addr, sizeof (sock_addr));
128 sock_addr.sin_len = sizeof(sock_addr);
130 sock_addr.sin_family = AF_INET;
131 sock_addr.sin_port = htons ((short) request_port);
132 sock_addr.sin_addr.s_addr = htonl (INADDR_ANY);
133 if (bind (xdmcpFd, (struct sockaddr *)&sock_addr, sizeof (sock_addr)) == -1)
135 LogError (ReadCatalog(MC_LOG_SET,MC_LOG_ERR_BIND,MC_DEF_LOG_ERR_BIND),
136 request_port, errno);
141 WellKnownSocketsMax = xdmcpFd;
142 FD_SET (xdmcpFd, &WellKnownSocketsMask);
144 chooserFd = socket (AF_INET, SOCK_STREAM, 0);
145 Debug ("Created chooser socket %d\n", chooserFd);
148 LogError ((unsigned char *)"chooser socket creation failed, errno %d\n", errno);
151 listen (chooserFd, 5);
152 if (chooserFd > WellKnownSocketsMax)
153 WellKnownSocketsMax = chooserFd;
154 FD_SET (chooserFd, &WellKnownSocketsMask);
157 GetChooserAddr (addr, lenp)
161 struct sockaddr_in in_addr;
164 len = sizeof in_addr;
165 #if defined (_AIX) && (OSMAJORVERSION==4) && (OSMINORVERSION==2)
166 if (getsockname (chooserFd, (struct sockaddr *)&in_addr, (size_t *)&len) < 0)
168 if (getsockname (chooserFd, (struct sockaddr *)&in_addr, &len) < 0)
171 Debug ("Chooser socket port: %d\n", ntohs(in_addr.sin_port));
172 memmove( addr, (char *) &in_addr, len);