]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Add IPv6 support to the SNMP backend, and do some additional cleanup wherever
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 15 Apr 2011 23:38:13 +0000 (23:38 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Fri, 15 Apr 2011 23:38:13 +0000 (23:38 +0000)
we directly access socket address members.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@9691 7a7537e8-13f0-0310-91df-b6672ffda945

20 files changed:
backend/ipp.c
backend/lpd.c
backend/snmp.c
backend/socket.c
cups/http-addr.c
cups/http-addrlist.c
cups/http-private.h
cups/libcups2.def
cups/libcups_s.exp
cups/snmp.c
scheduler/client.c
scheduler/conf.c
scheduler/cups-polld.c
scheduler/dirsvc.c
scheduler/listen.c
scheduler/main.c
scheduler/network.c
scheduler/testdirsvc.c
test/ippserver.c
xcode/CUPS.xcodeproj/project.pbxproj

index 2582912ee24063ce51b1d977178d8b418f0acd50..f6b002933533be15285b60af3ea2d47463559218 100644 (file)
@@ -685,17 +685,9 @@ main(int  argc,                            /* I - Number of command-line args */
   fputs("STATE: -connecting-to-device\n", stderr);
   _cupsLangPrintFilter(stderr, "INFO", _("Connected to printer."));
 
-#ifdef AF_INET6
-  if (http->hostaddr->addr.sa_family == AF_INET6)
-    fprintf(stderr, "DEBUG: Connected to [%s]:%d (IPv6)...\n",
-           httpAddrString(http->hostaddr, addrname, sizeof(addrname)),
-           ntohs(http->hostaddr->ipv6.sin6_port));
-  else
-#endif /* AF_INET6 */
-    if (http->hostaddr->addr.sa_family == AF_INET)
-      fprintf(stderr, "DEBUG: Connected to %s:%d (IPv4)...\n",
-             httpAddrString(http->hostaddr, addrname, sizeof(addrname)),
-             ntohs(http->hostaddr->ipv4.sin_port));
+  fprintf(stderr, "DEBUG: Connected to %s:%d...\n",
+         httpAddrString(http->hostaddr, addrname, sizeof(addrname)),
+         _httpAddrPort(http->hostaddr));
 
  /*
   * Build a URI for the printer and fill the standard IPP attributes for
index 9b44f536aac156921b98efd9c7e809eef5348b75..5ff342613a736e9ff3a606c0819fab79ea1c363b 100644 (file)
@@ -860,17 +860,9 @@ lpd_queue(const char      *hostname,       /* I - Host to connect to */
     fputs("STATE: -connecting-to-device\n", stderr);
     _cupsLangPrintFilter(stderr, "INFO", _("Connected to printer."));
 
-#ifdef AF_INET6
-    if (addr->addr.addr.sa_family == AF_INET6)
-      fprintf(stderr, "DEBUG: Connected to [%s]:%d (IPv6) (local port %d)...\n", 
-             httpAddrString(&addr->addr, addrname, sizeof(addrname)),
-             ntohs(addr->addr.ipv6.sin6_port), lport);
-    else
-#endif /* AF_INET6 */
-      if (addr->addr.addr.sa_family == AF_INET)
-       fprintf(stderr, "DEBUG: Connected to %s:%d (IPv4) (local port %d)...\n",
-               httpAddrString(&addr->addr, addrname, sizeof(addrname)),
-               ntohs(addr->addr.ipv4.sin_port), lport);
+    fprintf(stderr, "DEBUG: Connected to %s:%d (local port %d)...\n",
+           httpAddrString(&(addr->addr), addrname, sizeof(addrname)),
+           _httpAddrPort(&(addr->addr)), lport);
 
    /*
     * See if the printer supports SNMP...
@@ -1278,12 +1270,7 @@ rresvport_af(int *port,                  /* IO - Port number to bind to */
     * Set the port number...
     */
 
-#  ifdef AF_INET6
-    if (family == AF_INET6)
-      addr.ipv6.sin6_port = htons(*port);
-    else
-#  endif /* AF_INET6 */
-    addr.ipv4.sin_port = htons(*port);
+    _httpAddrSetPort(&addr, *port);
 
    /*
     * Try binding the port to the socket; return if all is OK...
index 3890b4ac9a53ea00254b6926ffe0890925155bcf..b6d0fe4796e1443b38b96dba511fec077fd9ba12 100644 (file)
@@ -1,9 +1,9 @@
 /*
  * "$Id$"
  *
- *   SNMP discovery backend for the Common UNIX Printing System (CUPS).
+ *   SNMP discovery backend for CUPS.
  *
- *   Copyright 2007-2009 by Apple Inc.
+ *   Copyright 2007-2011 by Apple Inc.
  *   Copyright 2006-2007 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -164,7 +164,7 @@ static void         probe_device(snmp_cache_t *device);
 static void            read_snmp_conf(const char *address);
 static void            read_snmp_response(int fd);
 static double          run_time(void);
-static void            scan_devices(int fd);
+static void            scan_devices(int ipv4, int ipv6);
 static int             try_connect(http_addr_t *addr, const char *addrname,
                                    int port);
 static void            update_cache(snmp_cache_t *device, const char *uri,
@@ -202,7 +202,8 @@ int                                 /* O - Exit status */
 main(int  argc,                                /* I - Number of command-line arguments (6 or 7) */
      char *argv[])                     /* I - Command-line arguments */
 {
-  int          fd;                     /* SNMP socket */
+  int          ipv4,                   /* SNMP IPv4 socket */
+               ipv6;                   /* SNMP IPv6 socket */
 #if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
   struct sigaction action;             /* Actions for POSIX signals */
 #endif /* HAVE_SIGACTION && !HAVE_SIGSET */
@@ -245,9 +246,16 @@ main(int  argc,                            /* I - Number of command-line arguments (6 or 7) */
   * Open the SNMP socket...
   */
 
-  if ((fd = _cupsSNMPOpen(AF_INET)) < 0)
+  if ((ipv4 = _cupsSNMPOpen(AF_INET)) < 0)
     return (1);
 
+#ifdef AF_INET6
+  if ((ipv6 = _cupsSNMPOpen(AF_INET6)) < 0)
+    return (1);
+#else
+  ipv6 = -1;
+#endif /* AF_INET6 */
+
  /*
   * Read the configuration file and any cache data...
   */
@@ -262,13 +270,15 @@ main(int  argc,                           /* I - Number of command-line arguments (6 or 7) */
   * Scan for devices...
   */
 
-  scan_devices(fd);
+  scan_devices(ipv4, ipv6);
 
  /*
   * Close, free, and return with no errors...
   */
 
-  _cupsSNMPClose(fd);
+  _cupsSNMPClose(ipv4);
+  if (ipv6 >= 0)
+    _cupsSNMPClose(ipv6);
 
   free_array(Addresses);
   free_array(Communities);
@@ -708,7 +718,7 @@ probe_device(snmp_cache_t *device)  /* I - Device */
 
 #ifdef __APPLE__
  /*
-  * TODO: Try an mDNS query first, and then fallback on direct probes...
+  * If the printer supports Bonjour/mDNS, don't report it from the SNMP backend.
   */
 
   if (!try_connect(&(device->address), device->addrname, 5353))
@@ -1146,8 +1156,11 @@ run_time(void)
  */
 
 static void
-scan_devices(int fd)                   /* I - SNMP socket */
+scan_devices(int ipv4,                 /* I - SNMP IPv4 socket */
+             int ipv6)                 /* I - SNMP IPv6 socket */
 {
+  int                  fd,             /* File descriptor for this address */
+                       busy;           /* Are we busy processing something? */
   char                 *address,       /* Current address */
                        *community;     /* Current community */
   fd_set               input;          /* Input set for select() */
@@ -1156,6 +1169,7 @@ scan_devices(int fd)                      /* I - SNMP socket */
   http_addrlist_t      *addrs,         /* List of addresses */
                        *addr;          /* Current address */
   snmp_cache_t         *device;        /* Current device */
+  char                 temp[1024];     /* Temporary address string */
 
 
   gettimeofday(&StartTime, NULL);
@@ -1174,7 +1188,6 @@ scan_devices(int fd)                      /* I - SNMP socket */
     {
       char     ifname[255];            /* Interface name */
 
-
       strlcpy(ifname, address + 4, sizeof(ifname));
       if (ifname[0])
         ifname[strlen(ifname) - 1] = '\0';
@@ -1182,7 +1195,7 @@ scan_devices(int fd)                      /* I - SNMP socket */
       addrs = get_interface_addresses(ifname);
     }
     else
-      addrs = httpAddrGetList(address, AF_INET, NULL);
+      addrs = httpAddrGetList(address, AF_UNSPEC, NULL);
 
     if (!addrs)
     {
@@ -1198,8 +1211,20 @@ scan_devices(int fd)                     /* I - SNMP socket */
                   community, address);
 
       for (addr = addrs; addr; addr = addr->next)
+      {
+#ifdef AF_INET6
+        if (_httpAddrFamily(&(addr->addr)) == AF_INET6)
+         fd = ipv6;
+       else
+#endif /* AF_INET6 */
+        fd = ipv4;
+
+        debug_printf("DEBUG: Sending get request to %s...\n",
+                    httpAddrString(&(addr->addr), temp, sizeof(temp)));
+
         _cupsSNMPWrite(fd, &(addr->addr), CUPS_SNMP_VERSION_1, community,
                       CUPS_ASN1_GET_REQUEST, DEVICE_TYPE, DeviceTypeOID);
+      }
     }
 
     httpAddrFreeList(addrs);
@@ -1218,17 +1243,33 @@ scan_devices(int fd)                    /* I - SNMP socket */
     timeout.tv_sec  = 2;
     timeout.tv_usec = 0;
 
-    FD_SET(fd, &input);
+    FD_SET(ipv4, &input);
+    if (ipv6 >= 0)
+      FD_SET(ipv6, &input);
+
+    fd = ipv4 > ipv6 ? ipv4 : ipv6;
     if (select(fd + 1, &input, NULL, NULL, &timeout) < 0)
     {
-      fprintf(stderr, "ERROR: %.3f select() for %d failed: %s\n", run_time(),
-              fd, strerror(errno));
+      fprintf(stderr, "ERROR: %.3f select() for %d/%d failed: %s\n", run_time(),
+              ipv4, ipv6, strerror(errno));
       break;
     }
 
-    if (FD_ISSET(fd, &input))
-      read_snmp_response(fd);
-    else
+    busy = 0;
+
+    if (FD_ISSET(ipv4, &input))
+    {
+      read_snmp_response(ipv4);
+      busy = 1;
+    }
+
+    if (ipv6 >= 0 && FD_ISSET(ipv6, &input))
+    {
+      read_snmp_response(ipv6);
+      busy = 1;
+    }
+
+    if (!busy)
     {
      /*
       * List devices with complete information...
@@ -1274,14 +1315,14 @@ try_connect(http_addr_t *addr,          /* I - Socket address */
   debug_printf("DEBUG: %.3f Trying %s://%s:%d...\n", run_time(),
                port == 515 ? "lpd" : "socket", addrname, port);
 
-  if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
+  if ((fd = socket(_httpAddrFamily(addr), SOCK_STREAM, 0)) < 0)
   {
     fprintf(stderr, "ERROR: Unable to create socket: %s\n",
             strerror(errno));
     return (-1);
   }
 
-  addr->ipv4.sin_port = htons(port);
+  _httpAddrSetPort(addr, port);
 
   alarm(1);
 
index 232f514a33cbfa090c50e7739f25a57a1b10a08b..dd9cb7b267384b250cc066dff514f784299a4abb 100644 (file)
@@ -391,17 +391,9 @@ main(int  argc,                            /* I - Number of command-line arguments (6 or 7) */
   fputs("STATE: -connecting-to-device\n", stderr);
   _cupsLangPrintFilter(stderr, "INFO", _("Connected to printer."));
 
-#ifdef AF_INET6
-  if (addr->addr.addr.sa_family == AF_INET6)
-    fprintf(stderr, "DEBUG: Connected to [%s]:%d (IPv6)...\n",
-           httpAddrString(&addr->addr, addrname, sizeof(addrname)),
-           ntohs(addr->addr.ipv6.sin6_port));
-  else
-#endif /* AF_INET6 */
-    if (addr->addr.addr.sa_family == AF_INET)
-      fprintf(stderr, "DEBUG: Connected to %s:%d (IPv4)...\n",
-             httpAddrString(&addr->addr, addrname, sizeof(addrname)),
-             ntohs(addr->addr.ipv4.sin_port));
+  fprintf(stderr, "DEBUG: Connected to %s:%d...\n",
+         httpAddrString(&(addr->addr), addrname, sizeof(addrname)),
+         _httpAddrPort(&(addr->addr)));
 
  /*
   * Print everything...
index 69779e5b98cc7c2e4fcccf9bf8af10a273de24cf..64f4db358f5a2fe3ec8eaafdd64ddc41602d2c37 100644 (file)
@@ -19,6 +19,7 @@
  *   httpAddrLocalhost() - Check for the local loopback address.
  *   httpAddrLookup()    - Lookup the hostname associated with the address.
  *   _httpAddrPort()     - Get the port number associated with an address.
+ *   _httpAddrSetPort()  - Set the port number associated with an address.
  *   httpAddrString()    - Convert an IP address to a dotted string.
  *   httpGetHostByName() - Lookup a hostname or IP address, and return
  *                         address records for the specified name.
@@ -317,6 +318,27 @@ _httpAddrPort(http_addr_t *addr)   /* I - Address */
 }
 
 
+/*
+ * '_httpAddrSetPort()' - Set the port number associated with an address.
+ */
+
+void
+_httpAddrSetPort(http_addr_t *addr,    /* I - Address */
+                 int         port)     /* I - Port */
+{
+  if (!addr || port <= 0)
+    return;
+
+#ifdef AF_INET6
+  if (addr->addr.sa_family == AF_INET6)
+    addr->ipv6.sin6_port = htons(port);
+  else
+#endif /* AF_INET6 */
+  if (addr->addr.sa_family == AF_INET)
+    addr->ipv4.sin_port = htons(port);
+}
+
+
 /*
  * 'httpAddrString()' - Convert an address to a numeric string.
  *
index 7d50140384669a04add8e16f39e671175a72f695..b4b9d82fd4eaf9081cbe2edc4a2435e016add72a 100644 (file)
@@ -71,7 +71,7 @@ httpAddrConnect(
                  httpAddrString(&(addrlist->addr), temp, sizeof(temp)),
                  _httpAddrPort(&(addrlist->addr))));
 
-    if ((*sock = (int)socket(addrlist->addr.addr.sa_family, SOCK_STREAM,
+    if ((*sock = (int)socket(_httpAddrFamily(&(addrlist->addr)), SOCK_STREAM,
                              0)) < 0)
     {
      /*
index 49d079855b014d5d649101e4d6ec9a1caccf845b..63e9785d371db58cd1e9b6951dadafd6082180c4 100644 (file)
@@ -345,7 +345,9 @@ extern void _cups_freeifaddrs(struct ifaddrs *addrs);
  * Prototypes...
  */
 
+#define                        _httpAddrFamily(addrp) (addrp)->addr.sa_family
 extern int             _httpAddrPort(http_addr_t *addr);
+extern void            _httpAddrSetPort(http_addr_t *addr, int port);
 extern char            *_httpAssembleUUID(const char *server, int port,
                                           const char *name, int number,
                                           char *buffer, size_t bufsize);
index 13009f340ff2136db6c2efaaa647ce5598647ff9..6d589d2ecca1b9a08ff6ab5e8d24291a08002c8d 100644 (file)
@@ -29,6 +29,7 @@ _cups_strcpy
 _cups_strlcat\r
 _cups_strlcpy\r
 _httpAddrPort\r
+_httpAddrSetPort\r
 _httpAssembleUUID\r
 _httpCreate\r
 _httpEncodeURI\r
index c36b87810b57513d2cbdf8566be49695f1d7161c..4d095537a0118a9b3a28f9b7b284449f2d81e1b9 100644 (file)
@@ -41,6 +41,7 @@ _cups_strcpy
 _cups_strlcat
 _cups_strlcpy
 _httpAddrPort
+_httpAddrSetPort
 _httpAssembleUUID
 _httpBIOMethods
 _httpCreate
index a2aeafbba8c6fbede5463a053f3f17cce4d8ed4e..d5f6126f27cb79f1121e2d6d3385254f81a97ddb 100644 (file)
@@ -761,12 +761,7 @@ _cupsSNMPWrite(
 
   temp = *address;
 
-#ifdef AF_INET6
-  if (temp.addr.sa_family == AF_INET6)
-    temp.ipv6.sin6_port = htons(CUPS_SNMP_PORT);
-  else
-#endif /* AF_INET6 */
-  temp.ipv4.sin_port = htons(CUPS_SNMP_PORT);
+  _httpAddrSetPort(&temp, CUPS_SNMP_PORT);
 
   return (sendto(fd, buffer, bytes, 0, (void *)&temp,
                  httpAddrLength(&temp)) == bytes);
index 2b7185d0af00578b39205a77bafb5ce1e78e2fe5..87bdbf7c12669b66e572e33a16e16f8e87aedf5d 100644 (file)
@@ -179,29 +179,24 @@ cupsdAcceptClient(cupsd_listener_t *lis)/* I - Listener socket */
     return;
   }
 
-#ifdef AF_INET6
-  if (lis->address.addr.sa_family == AF_INET6)
-  {
-   /*
-    * Save the connected port number...
-    */
+ /*
+  * Save the connected port number...
+  */
 
-    con->http.hostaddr->ipv6.sin6_port = lis->address.ipv6.sin6_port;
+  _httpAddrSetPort(con->http.hostaddr, _httpAddrPort(&(lis->address)));
 
-   /*
-    * Convert IPv4 over IPv6 addresses (::ffff:n.n.n.n) to IPv4 forms we
-    * can more easily use...
-    */
+#ifdef AF_INET6
+ /*
+  * Convert IPv4 over IPv6 addresses (::ffff:n.n.n.n) to IPv4 forms we
+  * can more easily use...
+  */
 
-    if (con->http.hostaddr->ipv6.sin6_addr.s6_addr32[0] == 0 &&
-        con->http.hostaddr->ipv6.sin6_addr.s6_addr32[1] == 0 &&
-        ntohl(con->http.hostaddr->ipv6.sin6_addr.s6_addr32[2]) == 0xffff)
-      con->http.hostaddr->ipv6.sin6_addr.s6_addr32[2] = 0;
-  }
-  else
+  if (lis->address.addr.sa_family == AF_INET6 &&
+      con->http.hostaddr->ipv6.sin6_addr.s6_addr32[0] == 0 &&
+      con->http.hostaddr->ipv6.sin6_addr.s6_addr32[1] == 0 &&
+      ntohl(con->http.hostaddr->ipv6.sin6_addr.s6_addr32[2]) == 0xffff)
+    con->http.hostaddr->ipv6.sin6_addr.s6_addr32[2] = 0;
 #endif /* AF_INET6 */
-  if (lis->address.addr.sa_family == AF_INET)
-    con->http.hostaddr->ipv4.sin_port = lis->address.ipv4.sin_port;
 
  /*
   * Check the number of clients on the same address...
@@ -357,22 +352,16 @@ cupsdAcceptClient(cupsd_listener_t *lis)/* I - Listener socket */
   }
 #endif /* HAVE_TCPD_H */
 
-#ifdef AF_INET6
-  if (con->http.hostaddr->addr.sa_family == AF_INET6)
-    cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdAcceptClient: %d from %s:%d (IPv6)",
-                    con->http.fd, con->http.hostname,
-                   ntohs(con->http.hostaddr->ipv6.sin6_port));
-  else
-#endif /* AF_INET6 */
 #ifdef AF_LOCAL
   if (con->http.hostaddr->addr.sa_family == AF_LOCAL)
     cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdAcceptClient: %d from %s (Domain)",
                     con->http.fd, con->http.hostname);
   else
 #endif /* AF_LOCAL */
-  cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdAcceptClient: %d from %s:%d (IPv4)",
+  cupsdLogMessage(CUPSD_LOG_DEBUG, "cupsdAcceptClient: %d from %s:%d (IPv%d)",
                   con->http.fd, con->http.hostname,
-                 ntohs(con->http.hostaddr->ipv4.sin_port));
+                 _httpAddrPort(con->http.hostaddr),
+                 _httpAddrFamily(con->http.hostaddr) == AF_INET ? 4 : 6);
 
  /*
   * Get the local address the client connected to...
@@ -387,38 +376,23 @@ cupsdAcceptClient(cupsd_listener_t *lis)/* I - Listener socket */
     strcpy(con->servername, "localhost");
     con->serverport = LocalPort;
   }
+#ifdef AF_LOCAL
+  else if (_httpAddrFamily(&temp) == AF_LOCAL)
+  {
+    strcpy(con->servername, "localhost");
+    con->serverport = LocalPort;
+  }
+#endif /* AF_LOCAL */
   else
   {
-#ifdef AF_INET6
-    if (temp.addr.sa_family == AF_INET6)
-    {
-      if (httpAddrLocalhost(&temp))
-        strlcpy(con->servername, "localhost", sizeof(con->servername));
-      else if (HostNameLookups || RemotePort)
-        httpAddrLookup(&temp, con->servername, sizeof(con->servername));
-      else
-        httpAddrString(&temp, con->servername, sizeof(con->servername));
-
-      con->serverport = ntohs(lis->address.ipv6.sin6_port);
-    }
+    if (httpAddrLocalhost(&temp))
+      strlcpy(con->servername, "localhost", sizeof(con->servername));
+    else if (HostNameLookups || RemotePort)
+      httpAddrLookup(&temp, con->servername, sizeof(con->servername));
     else
-#endif /* AF_INET6 */
-    if (temp.addr.sa_family == AF_INET)
-    {
-      if (httpAddrLocalhost(&temp))
-        strlcpy(con->servername, "localhost", sizeof(con->servername));
-      else if (HostNameLookups || RemotePort)
-        httpAddrLookup(&temp, con->servername, sizeof(con->servername));
-      else
-        httpAddrString(&temp, con->servername, sizeof(con->servername));
+      httpAddrString(&temp, con->servername, sizeof(con->servername));
 
-      con->serverport = ntohs(lis->address.ipv4.sin_port);
-    }
-    else
-    {
-      strcpy(con->servername, "localhost");
-      con->serverport = LocalPort;
-    }
+    con->serverport = _httpAddrPort(&(lis->address));
   }
 
   cupsArrayAdd(Clients, con);
index 5bc9534821316568cfe33f1bccf4e15463c0857d..a562db4ddeb4a477607f2d98f5427c5cf166fb0e 100644 (file)
@@ -2631,29 +2631,17 @@ read_configuration(cups_file_t *fp)     /* I - File to read from */
 
        httpAddrString(&lis->address, temp, sizeof(temp));
 
-#ifdef AF_INET6
-        if (lis->address.addr.sa_family == AF_INET6)
-          cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s:%d (IPv6)", temp,
-                          ntohs(lis->address.ipv6.sin6_port));
-       else
-#endif /* AF_INET6 */
 #ifdef AF_LOCAL
         if (lis->address.addr.sa_family == AF_LOCAL)
           cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s (Domain)", temp);
        else
 #endif /* AF_LOCAL */
-       cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s:%d (IPv4)", temp,
-                        ntohs(lis->address.ipv4.sin_port));
+       cupsdLogMessage(CUPSD_LOG_INFO, "Listening to %s:%d (IPv%d)", temp,
+                        _httpAddrPort(&(lis->address)),
+                       _httpAddrFamily(&(lis->address)) == AF_INET ? 4 : 6);
 
         if (!httpAddrLocalhost(&(lis->address)))
-       {
-#ifdef AF_INET6
-         if (lis->address.addr.sa_family == AF_INET6)
-           RemotePort = ntohs(lis->address.ipv6.sin6_port);
-         else
-#endif /* AF_INET6 */
-         RemotePort = ntohs(lis->address.ipv4.sin_port);
-       }
+         RemotePort = _httpAddrPort(&(lis->address));
       }
 
      /*
@@ -2719,7 +2707,7 @@ read_configuration(cups_file_t *fp)       /* I - File to read from */
         */
 
        for (addr = addrlist; addr; addr = addr->next)
-         if (addr->addr.addr.sa_family == AF_INET)
+         if (_httpAddrFamily(&(addr->addr)) == AF_INET)
            break;
 
        if (addr)
@@ -2729,7 +2717,7 @@ read_configuration(cups_file_t *fp)       /* I - File to read from */
 
          cupsdLogMessage(CUPSD_LOG_INFO,
                          "Sending browsing info to %s:%d (IPv4)",
-                         temp, ntohs(dira->to.ipv4.sin_port));
+                         temp, _httpAddrPort(&(dira->to)));
 
          NumBrowsers ++;
        }
@@ -3061,7 +3049,7 @@ read_configuration(cups_file_t *fp)       /* I - File to read from */
          httpAddrString(&(relay->to), temp, sizeof(temp));
 
          cupsdLogMessage(CUPSD_LOG_INFO, "Relaying from %s to %s:%d (IPv4)",
-                         value, temp, ntohs(relay->to.ipv4.sin_port));
+                         value, temp, _httpAddrPort(&(relay->to)));
 
          NumRelays ++;
        }
index ab4a544a14abb211a645b0b30c4c0ebb110a21e2..e8041e06186074ae844959b28dd7ad01b3e8f7ab 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   Polling daemon for CUPS.
  *
- *   Copyright 2007-2010 by Apple Inc.
+ *   Copyright 2007-2011 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
index b3e94d0ce5084d7502314fbf4b4f738edc3a6d11..901840ac5d172f988a8ded13c82babf81f0db7c2 100644 (file)
@@ -1594,16 +1594,8 @@ cupsdStartBrowsing(void)
        if (httpAddrLocalhost(&(lis->address)))
          continue;
 
-       if (lis->address.addr.sa_family == AF_INET)
-       {
-         DNSSDPort = ntohs(lis->address.ipv4.sin_port);
-         break;
-       }
-       else if (lis->address.addr.sa_family == AF_INET6)
-       {
-         DNSSDPort = ntohs(lis->address.ipv6.sin6_port);
-         break;
-       }
+        DNSSDPort = _httpAddrPort(&(lis->address));
+       break;
       }
 
      /*
index 51e0e462dd1115e61863a144181a207bf32c3e9b..b8baaf2bdb6cd7b2f006d00a8edaa9136db7c347 100644 (file)
@@ -151,18 +151,7 @@ cupsdStartListening(void)
        lis = (cupsd_listener_t *)cupsArrayNext(Listeners))
   {
     httpAddrString(&(lis->address), s, sizeof(s));
-
-#ifdef AF_INET6
-    if (lis->address.addr.sa_family == AF_INET6)
-      p = ntohs(lis->address.ipv6.sin6_port);
-    else
-#endif /* AF_INET6 */
-#ifdef AF_LOCAL
-    if (lis->address.addr.sa_family == AF_LOCAL)
-      p = 0;
-    else
-#endif /* AF_LOCAL */
-    p = ntohs(lis->address.ipv4.sin_port);
+    p = _httpAddrPort(&(lis->address));
 
    /*
     * If needed, create a socket for listening...
index 142ed7ee3e23db37eaa19801a4ee43aead3bda02..4c429059d8537ca44e2fe0aa366e82c263184404 100644 (file)
@@ -1492,9 +1492,6 @@ launchd_checkin(void)
 {
   size_t               i,              /* Looping var */
                        count;          /* Number of listeners */
-#  ifdef HAVE_SSL
-  int                  portnum;        /* Port number */
-#  endif /* HAVE_SSL */
   launch_data_t                ld_msg,         /* Launch data message */
                        ld_resp,        /* Launch data response */
                        ld_array,       /* Launch data array */
@@ -1626,17 +1623,7 @@ launchd_checkin(void)
        lis->fd = fd;
 
 #  ifdef HAVE_SSL
-       portnum = 0;
-
-#    ifdef AF_INET6
-       if (lis->address.addr.sa_family == AF_INET6)
-         portnum = ntohs(lis->address.ipv6.sin6_port);
-       else
-#    endif /* AF_INET6 */
-       if (lis->address.addr.sa_family == AF_INET)
-         portnum = ntohs(lis->address.ipv4.sin_port);
-
-       if (portnum == 443)
+       if (_httpAddrPort(&(lis->address)) == 443)
          lis->encryption = HTTP_ENCRYPT_ALWAYS;
 #  endif /* HAVE_SSL */
       }
index 766e4645072d8a6fcfaea778d9fcdc4f73cb7107..29b42ea04d01ebebb563b0dae67dbb146a06e944 100644 (file)
@@ -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;
       }
     }
index b474c9e22ce40c590bd95ee56c28138fc5932e02..214cd0f8a291c8b89f392c090a355b02a090da0d 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   Browsing test program for CUPS.
  *
- *   Copyright 2007-2010 by Apple Inc.
+ *   Copyright 2007-2011 by Apple Inc.
  *   Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  *   These coded instructions, statements, and computer programs are the
@@ -297,7 +297,7 @@ main(int  argc,                             /* I - Number of command-line arguments */
     * Sleep for any remaining time...
     */
 
-    if (seconds > 0) 
+    if (seconds > 0)
       sleep(seconds);
   }
 
index 484ada29ddfe59a27b3bbddb9a82110a6bb50c3a..76ad8caa880e406f96e14ca0ed5176d29dfa5dc3 100644 (file)
@@ -202,7 +202,7 @@ typedef struct _ipp_printer_s               /**** Printer data ****/
   size_t               urilen;         /* Length of printer URI */
   ipp_t                        *attrs;         /* Static attributes */
   ipp_pstate_t         state;          /* printer-state value */
-  _ipp_preasons_t      state_reasons;  /* printer-state-reasons values */  
+  _ipp_preasons_t      state_reasons;  /* printer-state-reasons values */
   cups_array_t         *jobs;          /* Jobs */
   _ipp_job_t           *active_job;    /* Current active/pending job */
   int                  next_job_id;    /* Next job-id value */
@@ -1084,16 +1084,8 @@ create_listener(int family,              /* I  - Address family */
   }
 
   memset(&address, 0, sizeof(address));
-  if (family == AF_INET)
-  {
-    address.ipv4.sin_family = family;
-    address.ipv4.sin_port   = htons(*port);
-  }
-  else
-  {
-    address.ipv6.sin6_family = family;
-    address.ipv6.sin6_port   = htons(*port);
-  }
+  address.addr.sa_family = family;
+  _httpAddrSetPort(&address, *port);
 
   if (bind(sock, (struct sockaddr *)&address, httpAddrLength(&address)))
   {
@@ -2898,13 +2890,13 @@ ipp_print_job(_ipp_client_t *client)    /* I - Client */
     snprintf(filename, sizeof(filename), "%s/%d.png",
              client->printer->directory, job->id);
   else if (!strcasecmp(job->format, "application/pdf"))
-    snprintf(filename, sizeof(filename), "%s/%d.pdf", 
+    snprintf(filename, sizeof(filename), "%s/%d.pdf",
              client->printer->directory, job->id);
   else if (!strcasecmp(job->format, "application/postscript"))
-    snprintf(filename, sizeof(filename), "%s/%d.ps", 
+    snprintf(filename, sizeof(filename), "%s/%d.ps",
              client->printer->directory, job->id);
   else
-    snprintf(filename, sizeof(filename), "%s/%d.prn", 
+    snprintf(filename, sizeof(filename), "%s/%d.prn",
              client->printer->directory, job->id);
 
   if ((job->fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0600)) < 0)
index 07f865b421d1c0db54273cef653170ef0569d010..4a23dc924b0d1a3f14e185fc27afb712a772be15 100644 (file)
@@ -48,6 +48,7 @@
                                276683DD1337B24A000D33D0 /* PBXTargetDependency */,
                                276683DF1337B24A000D33D0 /* PBXTargetDependency */,
                                7258EAEF13459ADA009286F1 /* PBXTargetDependency */,
+                               720DD6D11358FDBE0064AA82 /* PBXTargetDependency */,
                                7243793F1333FD23009631B9 /* PBXTargetDependency */,
                                724379C31333FF7D009631B9 /* PBXTargetDependency */,
                        );
                276683FD1337F7B8000D33D0 /* libcups.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 72220EAE1333047D00FCA411 /* libcups.dylib */; };
                2766840F1337FA38000D33D0 /* libcups.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 72220EAE1333047D00FCA411 /* libcups.dylib */; };
                276684111337FA7C000D33D0 /* cupsaddsmb.c in Sources */ = {isa = PBXBuildFile; fileRef = 276684101337FA7C000D33D0 /* cupsaddsmb.c */; };
+               720DD6CD1358FD720064AA82 /* libcups.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 72220EAE1333047D00FCA411 /* libcups.dylib */; };
+               720DD6D31358FDDE0064AA82 /* snmp.c in Sources */ = {isa = PBXBuildFile; fileRef = 720DD6D21358FDDE0064AA82 /* snmp.c */; };
+               720DD6D413590AB90064AA82 /* ieee1284.c in Sources */ = {isa = PBXBuildFile; fileRef = 724379CA1334000E009631B9 /* ieee1284.c */; };
                72220EB61333052D00FCA411 /* adminutil.c in Sources */ = {isa = PBXBuildFile; fileRef = 72220EB51333052D00FCA411 /* adminutil.c */; };
                72220EC41333056300FCA411 /* adminutil.h in Headers */ = {isa = PBXBuildFile; fileRef = 72220EB71333056300FCA411 /* adminutil.h */; settings = {ATTRIBUTES = (Public, ); }; };
                72220EC51333056300FCA411 /* array.c in Sources */ = {isa = PBXBuildFile; fileRef = 72220EB81333056300FCA411 /* array.c */; };
                        remoteGlobalIDString = 276684031337FA1D000D33D0;
                        remoteInfo = cupsaddsmb;
                };
+               720DD6CE1358FD790064AA82 /* PBXContainerItemProxy */ = {
+                       isa = PBXContainerItemProxy;
+                       containerPortal = 72BF96371333042100B1EAD7 /* Project object */;
+                       proxyType = 1;
+                       remoteGlobalIDString = 72220EAD1333047D00FCA411;
+                       remoteInfo = libcups;
+               };
+               720DD6D01358FDBE0064AA82 /* PBXContainerItemProxy */ = {
+                       isa = PBXContainerItemProxy;
+                       containerPortal = 72BF96371333042100B1EAD7 /* Project object */;
+                       proxyType = 1;
+                       remoteGlobalIDString = 720DD6C11358FD5F0064AA82;
+                       remoteInfo = snmp;
+               };
                72220F6413330A6500FCA411 /* PBXContainerItemProxy */ = {
                        isa = PBXContainerItemProxy;
                        containerPortal = 72BF96371333042100B1EAD7 /* Project object */;
                        );
                        runOnlyForDeploymentPostprocessing = 1;
                };
+               720DD6C01358FD5F0064AA82 /* CopyFiles */ = {
+                       isa = PBXCopyFilesBuildPhase;
+                       buildActionMask = 2147483647;
+                       dstPath = /usr/share/man/man1/;
+                       dstSubfolderSpec = 0;
+                       files = (
+                       );
+                       runOnlyForDeploymentPostprocessing = 1;
+               };
                72220F5913330A5A00FCA411 /* CopyFiles */ = {
                        isa = PBXCopyFilesBuildPhase;
                        buildActionMask = 2147483647;
                276684101337FA7C000D33D0 /* cupsaddsmb.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = cupsaddsmb.c; path = ../systemv/cupsaddsmb.c; sourceTree = "<group>"; };
                27D3037C134148CB00F022B1 /* libcups_s.exp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.exports; name = libcups_s.exp; path = ../cups/libcups_s.exp; sourceTree = "<group>"; };
                27D3037D134148CB00F022B1 /* libcups2.def */ = {isa = PBXFileReference; lastKnownFileType = text; name = libcups2.def; path = ../cups/libcups2.def; sourceTree = "<group>"; };
+               720DD6C21358FD5F0064AA82 /* snmp */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = snmp; sourceTree = BUILT_PRODUCTS_DIR; };
+               720DD6D21358FDDE0064AA82 /* snmp.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = snmp.c; path = ../backend/snmp.c; sourceTree = "<group>"; };
                72220EAE1333047D00FCA411 /* libcups.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libcups.dylib; sourceTree = BUILT_PRODUCTS_DIR; };
                72220EB51333052D00FCA411 /* adminutil.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = adminutil.c; path = ../cups/adminutil.c; sourceTree = "<group>"; };
                72220EB71333056300FCA411 /* adminutil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = adminutil.h; path = ../cups/adminutil.h; sourceTree = "<group>"; };
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
+               720DD6BF1358FD5F0064AA82 /* Frameworks */ = {
+                       isa = PBXFrameworksBuildPhase;
+                       buildActionMask = 2147483647;
+                       files = (
+                               720DD6CD1358FD720064AA82 /* libcups.dylib in Frameworks */,
+                       );
+                       runOnlyForDeploymentPostprocessing = 0;
+               };
                72220EAB1333047D00FCA411 /* Frameworks */ = {
                        isa = PBXFrameworksBuildPhase;
                        buildActionMask = 2147483647;
                                276683F01337F78E000D33D0 /* ipptool */,
                                276684041337FA1D000D33D0 /* cupsaddsmb */,
                                7258EAE2134594C4009286F1 /* rastertopwg */,
+                               720DD6C21358FD5F0064AA82 /* snmp */,
                        );
                        name = Products;
                        sourceTree = "<group>";
                                724379281333E952009631B9 /* lpd.c */,
                                7243790B1333E4E3009631B9 /* network.c */,
                                724379121333E516009631B9 /* runloop.c */,
+                               720DD6D21358FDDE0064AA82 /* snmp.c */,
                                7243790C1333E4E3009631B9 /* snmp-supplies.c */,
                                7243793C1333FD19009631B9 /* socket.c */,
                                724379C51333FFC7009631B9 /* usb.c */,
                        productReference = 276684041337FA1D000D33D0 /* cupsaddsmb */;
                        productType = "com.apple.product-type.tool";
                };
+               720DD6C11358FD5F0064AA82 /* snmp */ = {
+                       isa = PBXNativeTarget;
+                       buildConfigurationList = 720DD6CB1358FD600064AA82 /* Build configuration list for PBXNativeTarget "snmp" */;
+                       buildPhases = (
+                               720DD6BE1358FD5F0064AA82 /* Sources */,
+                               720DD6BF1358FD5F0064AA82 /* Frameworks */,
+                               720DD6C01358FD5F0064AA82 /* CopyFiles */,
+                       );
+                       buildRules = (
+                       );
+                       dependencies = (
+                               720DD6CF1358FD790064AA82 /* PBXTargetDependency */,
+                       );
+                       name = snmp;
+                       productName = snmp;
+                       productReference = 720DD6C21358FD5F0064AA82 /* snmp */;
+                       productType = "com.apple.product-type.tool";
+               };
                72220EAD1333047D00FCA411 /* libcups */ = {
                        isa = PBXNativeTarget;
                        buildConfigurationList = 72220EB21333047D00FCA411 /* Build configuration list for PBXNativeTarget "libcups" */;
                                276683961337ACA2000D33D0 /* ppdmerge */,
                                276683A31337ACAB000D33D0 /* ppdpo */,
                                7258EAE1134594C4009286F1 /* rastertopwg */,
+                               720DD6C11358FD5F0064AA82 /* snmp */,
                                7243792F1333FB85009631B9 /* socket */,
                                273BF6BC1333B5000022CAAB /* testcups */,
                                7243795A1333FF1D009631B9 /* usb */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
+               720DD6BE1358FD5F0064AA82 /* Sources */ = {
+                       isa = PBXSourcesBuildPhase;
+                       buildActionMask = 2147483647;
+                       files = (
+                               720DD6D413590AB90064AA82 /* ieee1284.c in Sources */,
+                               720DD6D31358FDDE0064AA82 /* snmp.c in Sources */,
+                       );
+                       runOnlyForDeploymentPostprocessing = 0;
+               };
                72220EAA1333047D00FCA411 /* Sources */ = {
                        isa = PBXSourcesBuildPhase;
                        buildActionMask = 2147483647;
                        target = 276684031337FA1D000D33D0 /* cupsaddsmb */;
                        targetProxy = 276684121337FA8D000D33D0 /* PBXContainerItemProxy */;
                };
+               720DD6CF1358FD790064AA82 /* PBXTargetDependency */ = {
+                       isa = PBXTargetDependency;
+                       target = 72220EAD1333047D00FCA411 /* libcups */;
+                       targetProxy = 720DD6CE1358FD790064AA82 /* PBXContainerItemProxy */;
+               };
+               720DD6D11358FDBE0064AA82 /* PBXTargetDependency */ = {
+                       isa = PBXTargetDependency;
+                       target = 720DD6C11358FD5F0064AA82 /* snmp */;
+                       targetProxy = 720DD6D01358FDBE0064AA82 /* PBXContainerItemProxy */;
+               };
                72220F6513330A6500FCA411 /* PBXTargetDependency */ = {
                        isa = PBXTargetDependency;
                        target = 72220EAD1333047D00FCA411 /* libcups */;
                        };
                        name = Release;
                };
+               720DD6C91358FD5F0064AA82 /* Debug */ = {
+                       isa = XCBuildConfiguration;
+                       buildSettings = {
+                               ALWAYS_SEARCH_USER_PATHS = NO;
+                               ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
+                               COPY_PHASE_STRIP = NO;
+                               GCC_C_LANGUAGE_STANDARD = gnu99;
+                               GCC_DYNAMIC_NO_PIC = NO;
+                               GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+                               GCC_OPTIMIZATION_LEVEL = 0;
+                               GCC_PREPROCESSOR_DEFINITIONS = "DEBUG=1";
+                               GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+                               GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+                               GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+                               GCC_WARN_ABOUT_RETURN_TYPE = YES;
+                               GCC_WARN_UNUSED_VARIABLE = YES;
+                               INSTALL_PATH = /usr/libexec/cups/backend;
+                               ONLY_ACTIVE_ARCH = YES;
+                               PRODUCT_NAME = "$(TARGET_NAME)";
+                       };
+                       name = Debug;
+               };
+               720DD6CA1358FD5F0064AA82 /* Release */ = {
+                       isa = XCBuildConfiguration;
+                       buildSettings = {
+                               ALWAYS_SEARCH_USER_PATHS = NO;
+                               COPY_PHASE_STRIP = YES;
+                               DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+                               GCC_C_LANGUAGE_STANDARD = gnu99;
+                               GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+                               GCC_VERSION = com.apple.compilers.llvm.clang.1_0;
+                               GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+                               GCC_WARN_ABOUT_RETURN_TYPE = YES;
+                               GCC_WARN_UNUSED_VARIABLE = YES;
+                               INSTALL_PATH = /usr/libexec/cups/backend;
+                               PRODUCT_NAME = "$(TARGET_NAME)";
+                       };
+                       name = Release;
+               };
                72220EB01333047D00FCA411 /* Debug */ = {
                        isa = XCBuildConfiguration;
                        buildSettings = {
                        defaultConfigurationIsVisible = 0;
                        defaultConfigurationName = Release;
                };
+               720DD6CB1358FD600064AA82 /* Build configuration list for PBXNativeTarget "snmp" */ = {
+                       isa = XCConfigurationList;
+                       buildConfigurations = (
+                               720DD6C91358FD5F0064AA82 /* Debug */,
+                               720DD6CA1358FD5F0064AA82 /* Release */,
+                       );
+                       defaultConfigurationIsVisible = 0;
+               };
                72220EB21333047D00FCA411 /* Build configuration list for PBXNativeTarget "libcups" */ = {
                        isa = XCConfigurationList;
                        buildConfigurations = (