]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/listen.c
Merge changes from 1.1.x into 1.2 devel.
[thirdparty/cups.git] / scheduler / listen.c
index 28df74a1a919646621ba3291f9fe14d4dfc4d6a4..3b565bf35b9a28fcb5a72d84ea32c167ccbb9a5a 100644 (file)
@@ -1,10 +1,10 @@
 /*
- * "$Id: listen.c,v 1.7 2000/11/21 20:59:56 mike Exp $"
+ * "$Id: listen.c,v 1.9.2.2 2001/12/26 16:52:54 mike Exp $"
  *
  *   Server listening routines for the Common UNIX Printing System (CUPS)
  *   scheduler.
  *
- *   Copyright 1997-2000 by Easy Software Products, all rights reserved.
+ *   Copyright 1997-2001 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
  *   property of Easy Software Products and are protected by Federal
@@ -96,6 +96,7 @@ StartListening(void)
                val;            /* Parameter value */
   listener_t   *lis;           /* Current listening socket */
   struct hostent *host;                /* Host entry for server address */
+  char         s[256];         /* String addresss */
 
 
   LogMessage(L_DEBUG, "StartListening: NumListeners=%d", NumListeners);
@@ -106,14 +107,13 @@ StartListening(void)
 
   memset(&ServerAddr, 0, sizeof(ServerAddr));
 
-  if ((host = gethostbyname(ServerName)) != NULL)
+  if ((host = httpGetHostByName(ServerName)) != NULL)
   {
    /*
     * Found the server's address!
     */
 
-    memcpy((char *)&(ServerAddr.sin_addr), host->h_addr, host->h_length);
-    ServerAddr.sin_family = host->h_addrtype;
+    httpAddrLoad(host, 0, 0, &ServerAddr);
   }
   else
   {
@@ -124,7 +124,7 @@ StartListening(void)
     LogMessage(L_ERROR, "StartListening: Unable to find IP address for server name \"%s\"!\n",
                ServerName);
 
-    ServerAddr.sin_family = AF_INET;
+    ServerAddr.ipv4.sin_family = AF_INET;
   }
 
  /*
@@ -133,11 +133,18 @@ StartListening(void)
 
   for (i = NumListeners, lis = Listeners; i > 0; i --, lis ++)
   {
-    LogMessage(L_DEBUG, "StartListening: address=%08x port=%d",
-               ntohl(lis->address.sin_addr.s_addr),
-              ntohs(lis->address.sin_port));
-
-    if ((lis->fd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
+    httpAddrString(&(lis->address), s, sizeof(s));
+
+#ifdef AF_INET6
+    if (lis->address.addr.sa_family == AF_INET6)
+      LogMessage(L_DEBUG, "StartListening: address=%s port=%d (IPv6)", s,
+                ntohs(lis->address.ipv6.sin6_port));
+    else
+#endif /* AF_INET6 */
+    LogMessage(L_DEBUG, "StartListening: address=%s port=%d", s,
+              ntohs(lis->address.ipv4.sin_port));
+
+    if ((lis->fd = socket(lis->address.addr.sa_family, SOCK_STREAM, 0)) == -1)
     {
       LogMessage(L_ERROR, "StartListening: Unable to open listen socket - %s.",
                  strerror(errno));
@@ -163,7 +170,8 @@ StartListening(void)
 
     if (bind(lis->fd, (struct sockaddr *)&(lis->address), sizeof(lis->address)) < 0)
     {
-      LogMessage(L_ERROR, "StartListening: Unable to bind socket - %s.", strerror(errno));
+      LogMessage(L_ERROR, "StartListening: Unable to bind socket - %s.",
+                 strerror(errno));
       exit(errno);
     }
 
@@ -171,7 +179,7 @@ StartListening(void)
     * Listen for new clients.
     */
 
-    if (listen(lis->fd, SOMAXCONN) < 0)
+    if (listen(lis->fd, ListenBackLog) < 0)
     {
       LogMessage(L_ERROR, "StartListening: Unable to listen for clients - %s.",
                  strerror(errno));
@@ -208,5 +216,5 @@ StopListening(void)
 
 
 /*
- * End of "$Id: listen.c,v 1.7 2000/11/21 20:59:56 mike Exp $".
+ * End of "$Id: listen.c,v 1.9.2.2 2001/12/26 16:52:54 mike Exp $".
  */