1 /* $TOG: socket.c /main/9 1997/12/23 12:25:32 bill $ */
2 /* (c) Copyright 1997 The Open Group */
4 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
5 * (c) Copyright 1993, 1994 International Business Machines Corp. *
6 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
7 * (c) Copyright 1993, 1994 Novell, Inc. *
16 * Revision 1.1.2.3 1995/06/06 20:24:26 Chris_Beute
17 * Code snapshot merge from March 15 and SIA changes
18 * [1995/05/31 20:15:01 Chris_Beute]
20 * Revision 1.1.2.2 1995/04/21 13:05:38 Peter_Derr
21 * dtlogin auth key fixes from deltacde
22 * [1995/04/12 19:21:26 Peter_Derr]
24 * R6 xdm version used to pick up XDMCP improvements.
25 * [1995/04/12 18:05:54 Peter_Derr]
31 Copyright (c) 1988 X Consortium
33 Permission is hereby granted, free of charge, to any person obtaining
34 a copy of this software and associated documentation files (the
35 "Software"), to deal in the Software without restriction, including
36 without limitation the rights to use, copy, modify, merge, publish,
37 distribute, sublicense, and/or sell copies of the Software, and to
38 permit persons to whom the Software is furnished to do so, subject to
39 the following conditions:
41 The above copyright notice and this permission notice shall be included
42 in all copies or substantial portions of the Software.
44 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
45 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
46 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
47 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
48 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
49 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
50 OTHER DEALINGS IN THE SOFTWARE.
52 Except as contained in this notice, the name of the X Consortium shall
53 not be used in advertising or otherwise to promote the sale, use or
54 other dealings in this Software without prior written authorization
55 from the X Consortium.
60 * xdm - display manager daemon
61 * Author: Keith Packard, MIT X Consortium
63 * socket.c - Support for BSD sockets
70 #include <sys/socket.h>
71 #include <netinet/in.h>
83 extern FD_TYPE WellKnownSocketsMask;
84 extern int WellKnownSocketsMax;
86 CreateWellKnownSockets ()
88 struct sockaddr_in sock_addr;
89 char *name, *localHostname();
91 if (request_port == 0)
93 Debug ("creating socket %d\n", request_port);
94 xdmcpFd = socket (AF_INET, SOCK_DGRAM, 0);
96 LogError (ReadCatalog(MC_LOG_SET,MC_LOG_FAIL_SOCK,MC_DEF_LOG_FAIL_SOCK),
100 name = localHostname ();
101 registerHostname (name, strlen (name));
102 RegisterCloseOnFork (xdmcpFd);
103 /* zero out the entire structure; this avoids 4.4 incompatibilities */
104 bzero ((char *) &sock_addr, sizeof (sock_addr));
106 sock_addr.sin_len = sizeof(sock_addr);
108 sock_addr.sin_family = AF_INET;
109 sock_addr.sin_port = htons ((short) request_port);
110 sock_addr.sin_addr.s_addr = htonl (INADDR_ANY);
111 if (bind (xdmcpFd, (struct sockaddr *)&sock_addr, sizeof (sock_addr)) == -1)
113 LogError (ReadCatalog(MC_LOG_SET,MC_LOG_ERR_BIND,MC_DEF_LOG_ERR_BIND),
114 request_port, errno);
119 WellKnownSocketsMax = xdmcpFd;
120 FD_SET (xdmcpFd, &WellKnownSocketsMask);
122 chooserFd = socket (AF_INET, SOCK_STREAM, 0);
123 Debug ("Created chooser socket %d\n", chooserFd);
126 LogError ((unsigned char *)"chooser socket creation failed, errno %d\n", errno);
129 listen (chooserFd, 5);
130 if (chooserFd > WellKnownSocketsMax)
131 WellKnownSocketsMax = chooserFd;
132 FD_SET (chooserFd, &WellKnownSocketsMask);
135 GetChooserAddr (addr, lenp)
139 struct sockaddr_in in_addr;
142 len = sizeof in_addr;
143 #if defined (_AIX) && (OSMAJORVERSION==4) && (OSMINORVERSION==2)
144 if (getsockname (chooserFd, (struct sockaddr *)&in_addr, (size_t *)&len) < 0)
146 if (getsockname (chooserFd, (struct sockaddr *)&in_addr, &len) < 0)
149 Debug ("Chooser socket port: %d\n", ntohs(in_addr.sin_port));
150 memmove( addr, (char *) &in_addr, len);