-
- /*
- * Set things up to reuse the local address for this port.
- */
-
- val = 1;
-#ifdef __sun
- setsockopt(lis->fd, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val));
-#else
- setsockopt(lis->fd, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val));
-#endif /* __sun */
-
- /*
- * Bind to the port we found...
- */
-
-#ifdef AF_INET6
- if (lis->address.addr.sa_family == AF_INET6)
- {
-# ifdef IPV6_V6ONLY
- /*
- * Accept only IPv6 connections on this socket, to avoid
- * potential security issues and to make all platforms behave
- * the same.
- */
-
- val = 1;
-# ifdef __sun
- setsockopt(lis->fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&val, sizeof(val));
-# else
- setsockopt(lis->fd, IPPROTO_IPV6, IPV6_V6ONLY, &val, sizeof(val));
-# endif /* __sun */
-# endif /* IPV6_V6ONLY */
-
- status = bind(lis->fd, (struct sockaddr *)&(lis->address),
- httpAddrLength(&(lis->address)));
- }
- else
-#endif /* AF_INET6 */
-#ifdef AF_LOCAL
- if (lis->address.addr.sa_family == AF_LOCAL)
- {
- mode_t mask; /* Umask setting */
-
-
- /*
- * Remove any existing domain socket file...
- */
-
- unlink(lis->address.un.sun_path);
-
- /*
- * Save the current umask and set it to 0 so that all users can access
- * the domain socket...
- */
-
- mask = umask(0);
-
- /*
- * Bind the domain socket...
- */
-
- status = bind(lis->fd, (struct sockaddr *)&(lis->address),
- httpAddrLength(&(lis->address)));
-
- /*
- * Restore the umask...
- */
-
- umask(mask);
- }
- else
-#endif /* AF_LOCAL */
- status = bind(lis->fd, (struct sockaddr *)&(lis->address),
- sizeof(lis->address.ipv4));
-
- if (status < 0)
- {
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "Unable to bind socket for address %s:%d - %s.",
- s, p, strerror(errno));
- close(lis->fd);
- lis->fd = -1;
-
- if (FatalErrors & CUPSD_FATAL_LISTEN)
- cupsdEndProcess(getpid(), 0);
-
- continue;
- }
-
- /*
- * Listen for new clients.
- */
-
- if (listen(lis->fd, ListenBackLog) < 0)
- {
- cupsdLogMessage(CUPSD_LOG_ERROR,
- "Unable to listen for clients on address %s:%d - %s.",
- s, p, strerror(errno));
-
- close(lis->fd);
- lis->fd = -1;
-
- if (FatalErrors & CUPSD_FATAL_LISTEN)
- cupsdEndProcess(getpid(), 0);
-
- continue;
- }