]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/network.c
Fix source file header text duplication text duplication.
[thirdparty/cups.git] / scheduler / network.c
index 7f30b1e256195718be446082b512487881c86c1c..679f92f9b2a11928dad518cf87d65bc86589339b 100644 (file)
@@ -1,23 +1,14 @@
 /*
- * "$Id: network.c 7861 2008-08-26 03:15:14Z mike $"
+ * Network interface functions for the CUPS scheduler.
  *
- *   Network interface functions for the CUPS scheduler.
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products, all rights reserved.
  *
- *   Copyright 2007-2010 by Apple Inc.
- *   Copyright 1997-2006 by Easy Software Products, all rights reserved.
- *
- *   These coded instructions, statements, and computer programs are the
- *   property of Apple Inc. and are protected by Federal copyright
- *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- *   "LICENSE" which should have been included with this file.  If this
- *   file is missing or damaged, see the license at "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.
+ * These coded instructions, statements, and computer programs are the
+ * property of Apple Inc. and are protected by Federal copyright
+ * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ * "LICENSE" which should have been included with this file.  If this
+ * file is missing or damaged, see the license at "http://www.cups.org/".
  */
 
 /*
@@ -133,7 +124,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)
   {
@@ -148,7 +142,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...
@@ -166,7 +163,7 @@ cupsdNetIFUpdate(void)
       */
 
       if (httpAddrLocalhost((http_addr_t *)(addr->ifa_addr)))
-        strcpy(hostname, "localhost");
+        strlcpy(hostname, "localhost", sizeof(hostname));
       else
        httpAddrString((http_addr_t *)(addr->ifa_addr), hostname,
                       sizeof(hostname));
@@ -178,7 +175,10 @@ cupsdNetIFUpdate(void)
 
     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...
@@ -186,7 +186,7 @@ cupsdNetIFUpdate(void)
 
     strlcpy(temp->name, addr->ifa_name, sizeof(temp->name));
     temp->hostlen = hostlen;
-    strcpy(temp->hostname, hostname);  /* Safe because hostname is allocated */
+    memcpy(temp->hostname, hostname, hostlen + 1);
 
     if (addr->ifa_addr->sa_family == AF_INET)
     {
@@ -264,12 +264,7 @@ cupsdNetIFUpdate(void)
 
       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;
       }
     }
@@ -298,8 +293,3 @@ compare_netif(cupsd_netif_t *a,             /* I - First network interface */
 {
   return (strcmp(a->name, b->name));
 }
-
-
-/*
- * End of "$Id: network.c 7861 2008-08-26 03:15:14Z mike $".
- */