From: mike Date: Fri, 15 Apr 2011 23:38:13 +0000 (+0000) Subject: Add IPv6 support to the SNMP backend, and do some additional cleanup wherever X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f0aa54a14401a8862012d938fe7cf8da12d079f1;p=thirdparty%2Fcups.git Add IPv6 support to the SNMP backend, and do some additional cleanup wherever 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 --- diff --git a/backend/ipp.c b/backend/ipp.c index 2582912ee2..f6b0029335 100644 --- a/backend/ipp.c +++ b/backend/ipp.c @@ -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 diff --git a/backend/lpd.c b/backend/lpd.c index 9b44f536aa..5ff342613a 100644 --- a/backend/lpd.c +++ b/backend/lpd.c @@ -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... diff --git a/backend/snmp.c b/backend/snmp.c index 3890b4ac9a..b6d0fe4796 100644 --- a/backend/snmp.c +++ b/backend/snmp.c @@ -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); diff --git a/backend/socket.c b/backend/socket.c index 232f514a33..dd9cb7b267 100644 --- a/backend/socket.c +++ b/backend/socket.c @@ -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... diff --git a/cups/http-addr.c b/cups/http-addr.c index 69779e5b98..64f4db358f 100644 --- a/cups/http-addr.c +++ b/cups/http-addr.c @@ -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. * diff --git a/cups/http-addrlist.c b/cups/http-addrlist.c index 7d50140384..b4b9d82fd4 100644 --- a/cups/http-addrlist.c +++ b/cups/http-addrlist.c @@ -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) { /* diff --git a/cups/http-private.h b/cups/http-private.h index 49d079855b..63e9785d37 100644 --- a/cups/http-private.h +++ b/cups/http-private.h @@ -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); diff --git a/cups/libcups2.def b/cups/libcups2.def index 13009f340f..6d589d2ecc 100644 --- a/cups/libcups2.def +++ b/cups/libcups2.def @@ -29,6 +29,7 @@ _cups_strcpy _cups_strlcat _cups_strlcpy _httpAddrPort +_httpAddrSetPort _httpAssembleUUID _httpCreate _httpEncodeURI diff --git a/cups/libcups_s.exp b/cups/libcups_s.exp index c36b87810b..4d095537a0 100644 --- a/cups/libcups_s.exp +++ b/cups/libcups_s.exp @@ -41,6 +41,7 @@ _cups_strcpy _cups_strlcat _cups_strlcpy _httpAddrPort +_httpAddrSetPort _httpAssembleUUID _httpBIOMethods _httpCreate diff --git a/cups/snmp.c b/cups/snmp.c index a2aeafbba8..d5f6126f27 100644 --- a/cups/snmp.c +++ b/cups/snmp.c @@ -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); diff --git a/scheduler/client.c b/scheduler/client.c index 2b7185d0af..87bdbf7c12 100644 --- a/scheduler/client.c +++ b/scheduler/client.c @@ -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); diff --git a/scheduler/conf.c b/scheduler/conf.c index 5bc9534821..a562db4dde 100644 --- a/scheduler/conf.c +++ b/scheduler/conf.c @@ -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 ++; } diff --git a/scheduler/cups-polld.c b/scheduler/cups-polld.c index ab4a544a14..e8041e0618 100644 --- a/scheduler/cups-polld.c +++ b/scheduler/cups-polld.c @@ -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 diff --git a/scheduler/dirsvc.c b/scheduler/dirsvc.c index b3e94d0ce5..901840ac5d 100644 --- a/scheduler/dirsvc.c +++ b/scheduler/dirsvc.c @@ -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; } /* diff --git a/scheduler/listen.c b/scheduler/listen.c index 51e0e462dd..b8baaf2bdb 100644 --- a/scheduler/listen.c +++ b/scheduler/listen.c @@ -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... diff --git a/scheduler/main.c b/scheduler/main.c index 142ed7ee3e..4c429059d8 100644 --- a/scheduler/main.c +++ b/scheduler/main.c @@ -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 */ } diff --git a/scheduler/network.c b/scheduler/network.c index 766e464507..29b42ea04d 100644 --- a/scheduler/network.c +++ b/scheduler/network.c @@ -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; } } diff --git a/scheduler/testdirsvc.c b/scheduler/testdirsvc.c index b474c9e22c..214cd0f8a2 100644 --- a/scheduler/testdirsvc.c +++ b/scheduler/testdirsvc.c @@ -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); } diff --git a/test/ippserver.c b/test/ippserver.c index 484ada29dd..76ad8caa88 100644 --- a/test/ippserver.c +++ b/test/ippserver.c @@ -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) diff --git a/xcode/CUPS.xcodeproj/project.pbxproj b/xcode/CUPS.xcodeproj/project.pbxproj index 07f865b421..4a23dc924b 100644 --- a/xcode/CUPS.xcodeproj/project.pbxproj +++ b/xcode/CUPS.xcodeproj/project.pbxproj @@ -48,6 +48,7 @@ 276683DD1337B24A000D33D0 /* PBXTargetDependency */, 276683DF1337B24A000D33D0 /* PBXTargetDependency */, 7258EAEF13459ADA009286F1 /* PBXTargetDependency */, + 720DD6D11358FDBE0064AA82 /* PBXTargetDependency */, 7243793F1333FD23009631B9 /* PBXTargetDependency */, 724379C31333FF7D009631B9 /* PBXTargetDependency */, ); @@ -204,6 +205,9 @@ 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 */; }; @@ -660,6 +664,20 @@ 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 */; @@ -931,6 +949,15 @@ ); runOnlyForDeploymentPostprocessing = 1; }; + 720DD6C01358FD5F0064AA82 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; 72220F5913330A5A00FCA411 /* CopyFiles */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 2147483647; @@ -1070,6 +1097,8 @@ 276684101337FA7C000D33D0 /* cupsaddsmb.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = cupsaddsmb.c; path = ../systemv/cupsaddsmb.c; sourceTree = ""; }; 27D3037C134148CB00F022B1 /* libcups_s.exp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.exports; name = libcups_s.exp; path = ../cups/libcups_s.exp; sourceTree = ""; }; 27D3037D134148CB00F022B1 /* libcups2.def */ = {isa = PBXFileReference; lastKnownFileType = text; name = libcups2.def; path = ../cups/libcups2.def; sourceTree = ""; }; + 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 = ""; }; 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 = ""; }; 72220EB71333056300FCA411 /* adminutil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = adminutil.h; path = ../cups/adminutil.h; sourceTree = ""; }; @@ -1391,6 +1420,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 720DD6BF1358FD5F0064AA82 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 720DD6CD1358FD720064AA82 /* libcups.dylib in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 72220EAB1333047D00FCA411 /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -1604,6 +1641,7 @@ 276683F01337F78E000D33D0 /* ipptool */, 276684041337FA1D000D33D0 /* cupsaddsmb */, 7258EAE2134594C4009286F1 /* rastertopwg */, + 720DD6C21358FD5F0064AA82 /* snmp */, ); name = Products; sourceTree = ""; @@ -1800,6 +1838,7 @@ 724379281333E952009631B9 /* lpd.c */, 7243790B1333E4E3009631B9 /* network.c */, 724379121333E516009631B9 /* runloop.c */, + 720DD6D21358FDDE0064AA82 /* snmp.c */, 7243790C1333E4E3009631B9 /* snmp-supplies.c */, 7243793C1333FD19009631B9 /* socket.c */, 724379C51333FFC7009631B9 /* usb.c */, @@ -2267,6 +2306,24 @@ 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" */; @@ -2514,6 +2571,7 @@ 276683961337ACA2000D33D0 /* ppdmerge */, 276683A31337ACAB000D33D0 /* ppdpo */, 7258EAE1134594C4009286F1 /* rastertopwg */, + 720DD6C11358FD5F0064AA82 /* snmp */, 7243792F1333FB85009631B9 /* socket */, 273BF6BC1333B5000022CAAB /* testcups */, 7243795A1333FF1D009631B9 /* usb */, @@ -2723,6 +2781,15 @@ ); 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; @@ -3111,6 +3178,16 @@ 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 */; @@ -3916,6 +3993,45 @@ }; 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 = { @@ -4576,6 +4692,14 @@ 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 = (