Index: cups/http-addrlist.c =================================================================== --- cups/http-addrlist.c (revision 9607) +++ cups/http-addrlist.c (working copy) @@ -1,9 +1,9 @@ /* * "$Id$" * - * HTTP address list routines for the Common UNIX Printing System (CUPS). + * HTTP address list routines for CUPS. * - * Copyright 2007-2009 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 @@ -271,7 +271,7 @@ struct addrinfo hints, /* Address lookup hints */ *results, /* Address lookup results */ *current; /* Current result */ - char ipv6[1024], /* IPv6 address */ + char ipv6[64], /* IPv6 address */ *ipv6zone; /* Pointer to zone separator */ int ipv6len; /* Length of IPv6 address */ int error; /* getaddrinfo() error */ Index: cups/http-addr.c =================================================================== --- cups/http-addr.c (revision 9607) +++ cups/http-addr.c (working copy) @@ -1,9 +1,9 @@ /* * "$Id$" * - * HTTP address routines for the Common UNIX Printing System (CUPS). + * HTTP address routines for CUPS. * - * Copyright 2007-2009 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 @@ -358,8 +358,11 @@ #ifdef AF_INET6 else if (addr->addr.sa_family == AF_INET6) { + char *sptr, /* Pointer into string */ + temps[64]; /* Temporary string for address */ + # ifdef HAVE_GETNAMEINFO - if (getnameinfo(&addr->addr, httpAddrLength(addr), s, slen, + if (getnameinfo(&addr->addr, httpAddrLength(addr), temps, sizeof(temps), NULL, 0, NI_NUMERICHOST)) { /* @@ -371,29 +374,36 @@ return (NULL); } + else if ((sptr = strchr(temps, '%')) != NULL) + { + /* + * Convert "%zone" to "+zone" to match URI form... + */ + + *sptr = '+'; + } + # else - char *sptr; /* Pointer into string */ int i; /* Looping var */ unsigned temp; /* Current value */ const char *prefix; /* Prefix for address */ prefix = ""; - for (sptr = s, i = 0; i < 4 && addr->ipv6.sin6_addr.s6_addr32[i]; i ++) + for (sptr = temps, i = 0; i < 4 && addr->ipv6.sin6_addr.s6_addr32[i]; i ++) { temp = ntohl(addr->ipv6.sin6_addr.s6_addr32[i]); - snprintf(sptr, slen, "%s%x", prefix, (temp >> 16) & 0xffff); + snprintf(sptr, sizeof(temps) - (sptr - temps), "%s%x", prefix, + (temp >> 16) & 0xffff); prefix = ":"; - slen -= strlen(sptr); sptr += strlen(sptr); temp &= 0xffff; if (temp || i == 3 || addr->ipv6.sin6_addr.s6_addr32[i + 1]) { - snprintf(sptr, slen, "%s%x", prefix, temp); - slen -= strlen(sptr); + snprintf(sptr, sizeof(temps) - (sptr - temps), "%s%x", prefix, temp); sptr += strlen(sptr); } } @@ -405,24 +415,24 @@ if (i < 4) { - snprintf(sptr, slen, "%s:", prefix); + snprintf(sptr, sizeof(temps) - (sptr - temps), "%s:", prefix); prefix = ":"; - slen -= strlen(sptr); sptr += strlen(sptr); for (; i < 4; i ++) { temp = ntohl(addr->ipv6.sin6_addr.s6_addr32[i]); - if ((temp & 0xffff0000) || addr->ipv6.sin6_addr.s6_addr32[i - 1]) + if ((temp & 0xffff0000) || + (i > 0 && addr->ipv6.sin6_addr.s6_addr32[i - 1])) { - snprintf(sptr, slen, "%s%x", prefix, (temp >> 16) & 0xffff); - slen -= strlen(sptr); + snprintf(sptr, sizeof(temps) - (sptr - temps), "%s%x", prefix, + (temp >> 16) & 0xffff); sptr += strlen(sptr); } - snprintf(sptr, slen, "%s%x", prefix, temp & 0xffff); - slen -= strlen(sptr); + snprintf(sptr, sizeof(temps) - (sptr - temps), "%s%x", prefix, + temp & 0xffff); sptr += strlen(sptr); } } @@ -432,9 +442,7 @@ * Empty address... */ - strlcpy(s, "::", slen); - sptr = s + 2; - slen -= 2; + strlcpy(temps, "::", sizeof(temps)); } else { @@ -442,12 +450,16 @@ * Empty at end... */ - strlcpy(sptr, "::", slen); - sptr += 2; - slen -= 2; + strlcpy(sptr, "::", sizeof(temps) - (sptr - temps)); } } # endif /* HAVE_GETNAMEINFO */ + + /* + * Add "[v1." and "]" around IPv6 address to convert to URI form. + */ + + snprintf(s, slen, "[v1.%s]", temps); } #endif /* AF_INET6 */ else