interface_id.c revision e11c3f44f531fdff80941ce57c065d2ae861cefc
1N/A * The contents of this file are subject to the terms of the 1N/A * Common Development and Distribution License (the "License"). 1N/A * You may not use this file except in compliance with the License. 1N/A * See the License for the specific language governing permissions 1N/A * and limitations under the License. 1N/A * When distributing Covered Code, include this CDDL HEADER in each 1N/A * If applicable, add the following below this CDDL HEADER, with the 1N/A * fields enclosed by brackets "[]" replaced with your own identifying 1N/A * information: Portions Copyright [yyyy] [name of copyright owner] 1N/A * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 1N/A * Use is subject to license terms. 1N/A * Given an interface name, this function retrives the associated 1N/A * index value. Returns index value if successful, zero otherwise. 1N/A * The length of the supplied interface name must be at most 1N/A * IF_NAMESIZE-1 bytes 1N/A /* Make sure the given name is not NULL */ 1N/A * Fill up the interface name in the ioctl 1N/A * request message. Make sure that the length of 1N/A * the given interface name <= (IF_NAMESIZE-1) 1N/A /* Check the v4 interfaces first */ 1N/A /* Check the v6 interface list */ 1N/A * Given an index, this function returns the associated interface 1N/A * name in the supplied buffer ifname. 1N/A * Returns physical interface name if successful, NULL otherwise. 1N/A * The interface name returned will be at most IF_NAMESIZE-1 bytes. 1N/A /* A interface index of 0 is invalid */ 1N/A /* Prepare to send a SIOCGLIFNUM request message */ * NOTE: "+ 10" sleaze mitigates new IP interfaces showing up between * the SIOCGLIFNUM and the SIOCGLIFCONF. * Provide enough buffer to obtain the interface * list from the kernel as response to a SIOCGLIFCONF * Obtain the index value of each interface, and * match to see if the retrived index value matches * the given one. If so we have return the corresponding * device name of that interface. /* Oops the interface just disappeared */ * This function returns all the interface names and indexes /* Allocate the array of if_nameindex structure */ * Make sure that terminator structure automatically * happens to be all zeroes. * Search the current array to see if this interface /* New one. Allocate an array element and fill it */ * Obtain the index value for the interface /* Create the last one of the array */ /* Free up the excess array space */ * This function frees the the array that is created while * the if_nameindex function. /* First free the if_name member in each array element */ /* Now free up the array space */