void CreateWellKnownSockets(void) { int i; int partial; char port[20]; FD_ZERO(&AllSockets); FD_ZERO(&AllClients); FD_ZERO(&LastSelectMask); FD_ZERO(&ClientsWithInput); #if !defined(WIN32) for (i=0; i<MaxClients; i++) ConnectionTranslation[i] = 0; #else ClearConnectionTranslation(); #endif FD_ZERO (&WellKnownConnections); sprintf (port, "%d", atoi (display)); if ((_XSERVTransMakeAllCOTSServerListeners (port, &partial, &ListenTransCount, &ListenTransConns) >= 0) && (ListenTransCount >= 1)) { if (!PartialNetwork && partial) { FatalError ("Failed to establish all listening sockets"); } else { ListenTransFds = xalloc (ListenTransCount * sizeof (int)); for (i = 0; i < ListenTransCount; i++) { int fd = _XSERVTransGetConnectionNumber (ListenTransConns[i]); ListenTransFds[i] = fd; FD_SET (fd, &WellKnownConnections); if (!_XSERVTransIsLocal (ListenTransConns[i])) { DefineSelf (fd); } } } } if (!XFD_ANYSET (&WellKnownConnections)) FatalError ("Cannot establish any listening sockets - Make sure an X server isn't already running"); #if !defined(WIN32) OsSignal (SIGPIPE, SIG_IGN); OsSignal (SIGHUP, AutoResetServer); #endif OsSignal (SIGINT, GiveUp); OsSignal (SIGTERM, GiveUp); XFD_COPYSET (&WellKnownConnections, &AllSockets); ResetHosts(display); InitParentProcess(); #ifdef XDMCP XdmcpInit (); #endif }
void CreateWellKnownSockets() { int request, i; int whichbyte; /* used to figure out whether this is LSB or MSB */ #ifdef TCPCONN struct sockaddr_in insock; int tcpportReg; /* port with same byte order as server */ #ifdef SO_LINGER static int linger[2] = { 0, 0 }; #endif /* SO_LINGER */ #endif /* TCPCONN */ #ifdef DNETCONN struct sockaddr_dn dnsock; #endif /* DNETCONN */ #ifdef ISOCONN struct TSAPdisconnect tds; struct TSAPdisconnect *td = &tds; struct TSAPaddr tas; struct TSAPaddr *ta = &tas; struct PSAPaddr *pa; AEI aei; #endif /* ISOCONN */ int retry; #ifdef ISOCONN #ifdef ISODEBUG isodetcpath = ISODEPATH; #endif #endif /* ISOCONN */ CLEARBITS(AllSockets); CLEARBITS(AllClients); CLEARBITS(LastSelectMask); CLEARBITS(ClientsWithInput); for (i=0; i<MAXSOCKS; i++) ConnectionTranslation[i] = (ClientPtr)NULL; #ifdef hpux lastfdesc = _NFILE - 1; #else lastfdesc = getdtablesize() - 1; #endif /* hpux */ if (lastfdesc > MAXSOCKS) { lastfdesc = MAXSOCKS; if (debug_conns) ErrorF( "GOT TO END OF SOCKETS %d\n", MAXSOCKS); } WellKnownConnections = 0; whichbyte = 1; if (*(char *) &whichbyte) whichByteIsFirst = 'l'; else whichByteIsFirst = 'B'; #ifdef TCPCONN tcpportReg = atoi (display); tcpportReg += X_TCP_PORT; if ((request = socket (AF_INET, SOCK_STREAM, 0)) < 0) { Notice ("Creating TCP socket"); } else { bzero ((char *)&insock, sizeof (insock)); insock.sin_family = AF_INET; insock.sin_port = htons (tcpportReg); insock.sin_addr.s_addr = htonl(INADDR_ANY); retry = 20; while (i = bind(request, (struct sockaddr *) &insock, sizeof (insock))) { #ifdef hpux /* Necesary to restart the server without a reboot */ if (errno == EADDRINUSE) set_socket_option (request, SO_REUSEADDR); if (--retry == 0) Error ("Binding TCP socket"); sleep (1); #else if (--retry == 0) Error ("Binding MSB TCP socket"); sleep (10); #endif /* hpux */ } #ifdef hpux /* return the socket option to the original */ if (errno) unset_socket_option (request, SO_REUSEADDR); #endif /* hpux */ #ifdef SO_LINGER if(setsockopt (request, SOL_SOCKET, SO_LINGER, (char *)linger, sizeof(linger))) Notice ("Setting TCP SO_LINGER\n"); #endif /* SO_LINGER */ if (listen (request, 5)) Error ("Reg TCP Listening"); WellKnownConnections |= (1 << request); DefineSelf (request); #ifdef ISOCONN fd2family[request] = UNIX_IO; #endif /* ISOCONN */ } #endif /* TCPCONN */ #ifdef UNIXCONN if ((request = open_unix_socket ()) != -1) { WellKnownConnections |= (1L << request); unixDomainConnection = request; #ifdef ISOCONN fd2family[request] = UNIX_IO; #endif /* ISOCONN */ } #endif /*UNIXCONN */ #ifdef DNETCONN if ((request = socket (AF_DECnet, SOCK_STREAM, 0)) < 0) { Notice ("Creating DECnet socket"); } else { bzero ((char *)&dnsock, sizeof (dnsock)); dnsock.sdn_family = AF_DECnet; sprintf(dnsock.sdn_objname, "X$X%d", atoi (display)); dnsock.sdn_objnamel = strlen(dnsock.sdn_objname); if (bind (request, (struct sockaddr *) &dnsock, sizeof (dnsock))) Error ("Binding DECnet socket"); if (listen (request, 5)) Error ("DECnet Listening"); WellKnownConnections |= (1 << request); DefineSelf (request); #ifdef ISOCONN fd2family[request] = UNIX_IO; #endif /* ISOCONN */ } #endif /* DNETCONN */ #ifdef ISOCONN /* * If display is set, its the string after the Colon: * i.e. X0 or X1 or T0 or T1... */ if ((display == NULLCP) || (atoi(display) == 0)) aei = str2aei(TLocalHostName(), DEFAULTTSERVICE); else aei = str2aei(TLocalHostName(), display); if (aei == NULLAEI) { ErrorF("No AEI for me:"); FatalError(TLocalHostName()); } /* * This hack only works if the PSAPaddr and SSAP addrsd are null!! */ if ((pa = aei2addr (aei)) == NULLPA) FatalError("address translation failed"); ta = (struct TSAPaddr *)&(pa->pa_addr.sa_addr); /* * Just put out a listen for now */ if ((request = TNetListen(ta, td)) != OK) { Error(TErrString(td->td_reason)); FatalError("TNetListen"); } WellKnownConnections |= (1 << request); DefineSelf (request); fd2family[request] = ISODE_IO; #endif /* ISOCONN */ if (WellKnownConnections == 0) Error ("No Listeners, nothing to do"); signal (SIGPIPE, SIG_IGN); signal (SIGHUP, AutoResetServer); signal (SIGINT, GiveUp); signal (SIGTERM, GiveUp); FirstClient = request + 1; AllSockets[0] = WellKnownConnections; ResetHosts(display); for (i=0; i<MaxClients; i++) { inputBuffers[i].buffer = (char *) NULL; inputBuffers[i].bufptr = (char *) NULL; inputBuffers[i].bufcnt = 0; inputBuffers[i].lenLastReq = 0; inputBuffers[i].size = 0; } }
void CreateWellKnownSockets(void) { int i; int partial; FD_ZERO(&AllSockets); FD_ZERO(&AllClients); FD_ZERO(&LastSelectMask); FD_ZERO(&ClientsWithInput); #if !defined(WIN32) for (i = 0; i < MaxClients; i++) ConnectionTranslation[i] = 0; #else ClearConnectionTranslation(); #endif FD_ZERO(&WellKnownConnections); /* display is initialized to "0" by main(). It is then set to the display * number if specified on the command line. */ if (NoListenAll) { ListenTransCount = 0; } else if ((displayfd < 0) || explicit_display) { if (TryCreateSocket(atoi(display), &partial) && ListenTransCount >= 1) if (!PartialNetwork && partial) FatalError ("Failed to establish all listening sockets"); } else { /* -displayfd and no explicit display number */ Bool found = 0; for (i = 0; i < 65536 - X_TCP_PORT; i++) { if (TryCreateSocket(i, &partial) && ListenTransCount >= 1 && (PartialNetwork || !partial)) { found = 1; break; } else CloseWellKnownConnections(); } if (!found) FatalError("Failed to find a socket to listen on"); dynamic_display_id=i; snprintf(dynamic_display, sizeof(dynamic_display), "%d", i); display = dynamic_display; } ListenTransFds = xallocarray(ListenTransCount, sizeof (int)); if (ListenTransFds == NULL) FatalError ("Failed to create listening socket array"); for (i = ListenTransCount; i > 0; i--) { int fd = _XSERVTransGetConnectionNumber (ListenTransConns[i-1]); ListenTransFds[i-1] = fd; FD_SET(fd, &WellKnownConnections); if (!_XSERVTransIsLocal (ListenTransConns[i-1])) { int protocol = 0; if (!strcmp("inet", ListenTransConns[i-1]->transptr->TransName)) protocol = 4; else if (!strcmp("inet6", ListenTransConns[i-1]->transptr->TransName)) protocol = 6; DefineSelf (fd, protocol); } } if (!XFD_ANYSET(&WellKnownConnections) && !NoListenAll) FatalError ("Cannot establish any listening sockets - Make sure an X server isn't already running"); #if !defined(WIN32) OsSignal(SIGPIPE, SIG_IGN); OsSignal(SIGHUP, AutoResetServer); #endif OsSignal(SIGINT, GiveUp); OsSignal(SIGTERM, GiveUp); XFD_COPYSET(&WellKnownConnections, &AllSockets); ResetHosts(display); InitParentProcess(); #ifdef XDMCP XdmcpInit(); #endif }
void CreateWellKnownSockets(void) { int i; int partial; FD_ZERO(&AllSockets); FD_ZERO(&AllClients); FD_ZERO(&LastSelectMask); FD_ZERO(&ClientsWithInput); #if !defined(WIN32) for (i = 0; i < MaxClients; i++) ConnectionTranslation[i] = 0; #else ClearConnectionTranslation(); #endif FD_ZERO(&WellKnownConnections); /* display is initialized to "0" by main(). It is then set to the display * number if specified on the command line, or to NULL when the -displayfd * option is used. */ if (display) { if (TryCreateSocket(atoi(display), &partial) && ListenTransCount >= 1) if (!PartialNetwork && partial) FatalError ("Failed to establish all listening sockets"); } else { /* -displayfd */ Bool found = 0; for (i = 0; i < 65535 - X_TCP_PORT; i++) { if (TryCreateSocket(i, &partial) && !partial) { found = 1; break; } else CloseWellKnownConnections(); } if (!found) FatalError("Failed to find a socket to listen on"); snprintf(dynamic_display, sizeof(dynamic_display), "%d", i); display = dynamic_display; } ListenTransFds = malloc(ListenTransCount * sizeof (int)); for (i = 0; i < ListenTransCount; i++) { int fd = _XSERVTransGetConnectionNumber(ListenTransConns[i]); ListenTransFds[i] = fd; FD_SET(fd, &WellKnownConnections); if (!_XSERVTransIsLocal(ListenTransConns[i])) DefineSelf (fd); } if (!XFD_ANYSET(&WellKnownConnections)) FatalError ("Cannot establish any listening sockets - Make sure an X server isn't already running"); #if !defined(WIN32) OsSignal(SIGPIPE, SIG_IGN); OsSignal(SIGHUP, AutoResetServer); #endif OsSignal(SIGINT, GiveUp); OsSignal(SIGTERM, GiveUp); XFD_COPYSET(&WellKnownConnections, &AllSockets); ResetHosts(display); InitParentProcess(); #ifdef XDMCP XdmcpInit(); #endif }