1 /* capture_unix_ifnames.c
2 * Routines supporting the use of UN*X friendly interface names, if any,
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 2001 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30 #include "capture_unix_ifnames.h"
33 * Given an interface name, find the "friendly name" for the interface.
38 #include <CoreFoundation/CoreFoundation.h>
39 #include <SystemConfiguration/SystemConfiguration.h>
44 * On OS X, we do that by getting all the interfaces that the System
45 * Configuration framework knows about, look for the one with a "BSD
46 * name" matching the interface name, and, if we find it, return its
47 * "localized display name", if it has one.
50 get_unix_interface_friendly_name(const char *ifname)
52 CFStringRef ifname_CFString;
53 CFArrayRef interfaces;
54 CFIndex num_interfaces;
56 SCNetworkInterfaceRef interface;
57 CFStringRef bsdname_CFString;
58 CFStringRef friendly_name_CFString;
59 char *friendly_name = NULL;
61 interfaces = SCNetworkInterfaceCopyAll();
62 if (interfaces == NULL) {
64 * Couldn't get a list of interfaces.
69 ifname_CFString = CFStringCreateWithCString(kCFAllocatorDefault,
70 ifname, kCFStringEncodingUTF8);
71 if (ifname_CFString == NULL) {
73 * Couldn't convert the interface name to a CFString.
75 CFRelease(interfaces);
79 num_interfaces = CFArrayGetCount(interfaces);
80 for (i = 0; i < num_interfaces; i++) {
81 interface = (SCNetworkInterfaceRef)CFArrayGetValueAtIndex(interfaces, i);
82 bsdname_CFString = SCNetworkInterfaceGetBSDName(interface);
83 if (bsdname_CFString == NULL) {
85 * This interface has no BSD name, so it's not
86 * a regular network interface.
90 if (CFStringCompare(ifname_CFString, bsdname_CFString, 0) == 0) {
92 * This is the interface.
94 friendly_name_CFString = SCNetworkInterfaceGetLocalizedDisplayName(interface);
95 if (friendly_name_CFString != NULL)
96 friendly_name = CFString_to_C_string(friendly_name_CFString);
101 CFRelease(interfaces);
102 return friendly_name;
105 #else /* __APPLE__ */
108 * Nothing supported on other platforms.
111 get_unix_interface_friendly_name(const char *ifname _U_)
116 #endif /* __APPLE__ */