]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/network.c
Fix whitespace issues.
[thirdparty/cups.git] / scheduler / network.c
index e63d4f44e78abdee5316e90e85482fd177a7155a..f935f648d3041f265b0d0b0c9ab27dc2013eb609 100644 (file)
@@ -1,33 +1,11 @@
 /*
- * "$Id: network.c 6090 2006-11-14 16:35:27Z mike $"
+ * Network interface functions for the CUPS scheduler.
  *
- *   Network interface functions for the Common UNIX Printing System
- *   (CUPS) scheduler.
+ * Copyright © 2007-2014 by Apple Inc.
+ * Copyright © 1997-2006 by Easy Software Products, all rights reserved.
  *
- *   Copyright 1997-2006 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
- *   copyright law.  Distribution and use rights are outlined in the file
- *   "LICENSE" which should have been included with this file.  If this
- *   file is missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
- *
- * Contents:
- *
- *   cupsdNetIFFind()   - Find a network interface.
- *   cupsdNetIFFree()   - Free the current network interface list.
- *   cupsdNetIFUpdate() - Update the network interface list as needed...
- *   compare_netif()    - Compare two network interfaces.
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more
+ * information.
  */
 
 /*
@@ -109,8 +87,8 @@ cupsdNetIFUpdate(void)
   cupsd_netif_t                *temp;          /* New interface */
   struct ifaddrs       *addrs,         /* Interface address list */
                        *addr;          /* Current interface address */
-  http_addrlist_t      *saddr;         /* Current server address */
   char                 hostname[1024]; /* Hostname for address */
+  size_t               hostlen;        /* Length of hostname */
 
 
  /*
@@ -143,7 +121,10 @@ cupsdNetIFUpdate(void)
   */
 
   if (getifaddrs(&addrs) < 0)
+  {
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdNetIFUpdate: Unable to get interface list - %s", strerror(errno));
     return;
+  }
 
   for (addr = addrs; addr != NULL; addr = addr->ifa_next)
   {
@@ -158,7 +139,10 @@ cupsdNetIFUpdate(void)
 #endif
        ) ||
         addr->ifa_netmask == NULL || addr->ifa_name == NULL)
+    {
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdNetIFUpdate: Ignoring \"%s\".", addr->ifa_name);
       continue;
+    }
 
    /*
     * Try looking up the hostname for the address as needed...
@@ -172,39 +156,34 @@ cupsdNetIFUpdate(void)
      /*
       * Map the default server address and localhost to the server name
       * and localhost, respectively; for all other addresses, use the
-      * dotted notation...
+      * numeric address...
       */
 
       if (httpAddrLocalhost((http_addr_t *)(addr->ifa_addr)))
-        strcpy(hostname, "localhost");
+        strlcpy(hostname, "localhost", sizeof(hostname));
       else
-      {
-        for (saddr = ServerAddrs; saddr; saddr = saddr->next)
-         if (httpAddrEqual((http_addr_t *)(addr->ifa_addr), &(saddr->addr)))
-           break;
-
-       if (saddr)
-          strlcpy(hostname, ServerName, sizeof(hostname));
-       else
-          httpAddrString((http_addr_t *)(addr->ifa_addr), hostname,
-                        sizeof(hostname));
-      }
+       httpAddrString((http_addr_t *)(addr->ifa_addr), hostname,
+                      sizeof(hostname));
     }
 
    /*
     * Create a new address element...
     */
 
-    if ((temp = calloc(1, sizeof(cupsd_netif_t) +
-                          strlen(hostname))) == NULL)
+    hostlen = strlen(hostname);
+    if ((temp = calloc(1, sizeof(cupsd_netif_t) + hostlen)) == NULL)
+    {
+      cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdNetIFUpdate: Unable to allocate memory for interface.");
       break;
+    }
 
    /*
     * Copy all of the information...
     */
 
     strlcpy(temp->name, addr->ifa_name, sizeof(temp->name));
-    strcpy(temp->hostname, hostname);  /* Safe because hostname is allocated */
+    temp->hostlen = hostlen;
+    memcpy(temp->hostname, hostname, hostlen + 1);
 
     if (addr->ifa_addr->sa_family == AF_INET)
     {
@@ -254,35 +233,35 @@ cupsdNetIFUpdate(void)
       else if (addr->ifa_addr->sa_family == AF_INET &&
                lis->address.addr.sa_family == AF_INET &&
                (lis->address.ipv4.sin_addr.s_addr &
-                  temp->mask.ipv4.sin_addr.s_addr) ==
-                      temp->address.ipv4.sin_addr.s_addr)
+               temp->mask.ipv4.sin_addr.s_addr) ==
+                  (temp->address.ipv4.sin_addr.s_addr &
+                   temp->mask.ipv4.sin_addr.s_addr))
         match = 1;
 #ifdef AF_INET6
       else if (addr->ifa_addr->sa_family == AF_INET6 &&
                lis->address.addr.sa_family == AF_INET6 &&
                (lis->address.ipv6.sin6_addr.s6_addr[0] &
-                  temp->mask.ipv6.sin6_addr.s6_addr[0]) ==
-                      temp->address.ipv6.sin6_addr.s6_addr[0] &&
+               temp->mask.ipv6.sin6_addr.s6_addr[0]) ==
+                  (temp->address.ipv6.sin6_addr.s6_addr[0] &
+                   temp->mask.ipv6.sin6_addr.s6_addr[0]) &&
                (lis->address.ipv6.sin6_addr.s6_addr[1] &
-                  temp->mask.ipv6.sin6_addr.s6_addr[1]) ==
-                      temp->address.ipv6.sin6_addr.s6_addr[1] &&
+               temp->mask.ipv6.sin6_addr.s6_addr[1]) ==
+                  (temp->address.ipv6.sin6_addr.s6_addr[1] &
+                   temp->mask.ipv6.sin6_addr.s6_addr[1]) &&
                (lis->address.ipv6.sin6_addr.s6_addr[2] &
-                  temp->mask.ipv6.sin6_addr.s6_addr[2]) ==
-                      temp->address.ipv6.sin6_addr.s6_addr[2] &&
+               temp->mask.ipv6.sin6_addr.s6_addr[2]) ==
+                  (temp->address.ipv6.sin6_addr.s6_addr[2] &
+                   temp->mask.ipv6.sin6_addr.s6_addr[2]) &&
                (lis->address.ipv6.sin6_addr.s6_addr[3] &
-                  temp->mask.ipv6.sin6_addr.s6_addr[3]) ==
-                      temp->address.ipv6.sin6_addr.s6_addr[3])
+               temp->mask.ipv6.sin6_addr.s6_addr[3]) ==
+                  (temp->address.ipv6.sin6_addr.s6_addr[3] &
+                   temp->mask.ipv6.sin6_addr.s6_addr[3]))
         match = 1;
 #endif /* AF_INET6 */
 
       if (match)
       {
-        if (lis->address.addr.sa_family == AF_INET)
-          temp->port = ntohs(lis->address.ipv4.sin_port);
-#ifdef AF_INET6
-        else if (lis->address.addr.sa_family == AF_INET6)
-          temp->port = ntohs(lis->address.ipv6.sin6_port);
-#endif /* AF_INET6 */
+        temp->port = httpAddrPort(&(lis->address));
        break;
       }
     }
@@ -293,8 +272,8 @@ cupsdNetIFUpdate(void)
 
     cupsArrayAdd(NetIFList, temp);
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdNetIFUpdate: \"%s\" = %s...",
-                    temp->name, temp->hostname);
+    cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdNetIFUpdate: \"%s\" = %s:%d",
+                    temp->name, temp->hostname, temp->port);
   }
 
   freeifaddrs(addrs);
@@ -311,8 +290,3 @@ compare_netif(cupsd_netif_t *a,             /* I - First network interface */
 {
   return (strcmp(a->name, b->name));
 }
-
-
-/*
- * End of "$Id: network.c 6090 2006-11-14 16:35:27Z mike $".
- */