e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * CDDL HEADER START
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * The contents of this file are subject to the terms of the
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * Common Development and Distribution License (the "License").
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * You may not use this file except in compliance with the License.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * See the License for the specific language governing permissions
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * and limitations under the License.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * When distributing Covered Code, include this CDDL HEADER in each
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * If applicable, add the following below this CDDL HEADER, with the
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * fields enclosed by brackets "[]" replaced with your own identifying
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * information: Portions Copyright [yyyy] [name of copyright owner]
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * CDDL HEADER END
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * Use is subject to license terms.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * Create a list of the addresses on physical interface `ifname' with at least
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * one of the flags in `set' set and all of the flags in `clear' clear.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * Return the number of items in the list, or -1 on failure.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeemifaddrlistx(const char *ifname, uint64_t set, uint64_t clear,
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem flags = LIFC_NOXMIT | LIFC_ALLZONES | LIFC_TEMPORARY | LIFC_UNDER_IPMP;
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * We need both IPv4 and IPv6 sockets to query both IPv4 and IPv6
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * interfaces below.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * Get the number of network interfaces of type `family'.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * Pad the interface count to detect when additional interfaces have
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * been configured between SIOCGLIFNUM and SIOCGLIFCONF.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem lifc.lifc_len = lifn.lifn_count * sizeof (struct lifreq);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem if ((lifc.lifc_buf = realloc(lifc.lifc_buf, lifc.lifc_len)) == NULL)
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * If every lifr_req slot is taken, then additional interfaces must
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * have been plumbed between the SIOCGLIFNUM and the SIOCGLIFCONF.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * Recalculate to make sure we didn't miss any interfaces.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * Populate the ifaddrlistx by querying each matching interface. If a
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * query ioctl returns ENXIO, then the interface must have been
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * removed after the SIOCGLIFCONF completed -- so we just ignore it.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem for (lifrp = lifc.lifc_req, i = 0; i < nlifr; i++, lifrp++) {
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem if (ioctl(isv6 ? s6 : s4, SIOCGLIFFLAGS, lifrp) == -1) {
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * We've got a match; allocate a new record.
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem if ((ifaddrp = malloc(sizeof (ifaddrlistx_t))) == NULL)
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem (void) strlcpy(ifaddrp->ia_name, lifrp->lifr_name, LIFNAMSIZ);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem return (-1);
e11c3f44f531fdff80941ce57c065d2ae861cefcmeem * Free the provided ifaddrlistx_t.