Exemplo n.º 1
0
/*
 * Function: copy_present_interface
 * Purpose:
 *   Check the list of interfaces on the system, and find the one corresponding
 *   to the specified BSD name.
 */
STATIC SCNetworkInterfaceRef
copy_present_interface(CFStringRef if_name)
{
    int				count = 0;
    int				i;
    CFArrayRef			list;
    SCNetworkInterfaceRef	ret = NULL;

    list = SCNetworkInterfaceCopyAll();
    if (list != NULL) {
	count = CFArrayGetCount(list);
    }
    if (count == 0) {
	goto done;
    }
    for (i = 0; i < count; i++) {
	SCNetworkInterfaceRef	this_if;
	CFStringRef		this_if_name;

	this_if = (SCNetworkInterfaceRef)CFArrayGetValueAtIndex(list, i);
	this_if_name = SCNetworkInterfaceGetBSDName(this_if);
	if (this_if_name == NULL) {
	    continue;
	}
	if (CFEqual(if_name, this_if_name)) {
	    ret = this_if;
	    CFRetain(ret);
	    break;
	}
    }

 done:
    my_CFRelease(&list);
    return (ret);
}
Exemplo n.º 2
0
 *    maybe kSCNetworkInterfaceTypeWWAN means IF_DIALUP
 */
static void
add_unix_interface_ifinfo(if_info_t *if_info, const char *name,
    const char *description _U_)
{
	CFStringRef name_CFString;
	CFArrayRef interfaces;
	CFIndex num_interfaces;
	CFIndex i;
	SCNetworkInterfaceRef interface;
	CFStringRef bsdname_CFString;
	CFStringRef friendly_name_CFString;
	CFStringRef interface_type_CFString;

	interfaces = SCNetworkInterfaceCopyAll();
	if (interfaces == NULL) {
		/*
		 * Couldn't get a list of interfaces.
		 */
		return;
	}

	name_CFString = CFStringCreateWithCString(kCFAllocatorDefault,
	    name, kCFStringEncodingUTF8);
	if (name_CFString == NULL) {
		/*
		 * Couldn't convert the interface name to a CFString.
		 */
		CFRelease(interfaces);
		return;