/*
- * "$Id: network.c 6649 2007-07-11 21:46:42Z mike $"
+ * "$Id$"
*
- * Network interface functions for the Common UNIX Printing System
- * (CUPS) scheduler.
+ * Network interface functions for the CUPS scheduler.
*
- * Copyright 2007 by Apple Inc.
+ * Copyright 2007-2012 by Apple Inc.
* Copyright 1997-2006 by Easy Software Products, all rights reserved.
*
* These coded instructions, statements, and computer programs are the
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 */
/*
/*
* 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)
break;
/*
*/
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)
{
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;
}
}
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);
/*
- * End of "$Id: network.c 6649 2007-07-11 21:46:42Z mike $".
+ * End of "$Id$".
*/