aboutsummaryrefslogtreecommitdiffstats
path: root/cfutils.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2012-11-22 06:02:49 +0000
committerGuy Harris <guy@alum.mit.edu>2012-11-22 06:02:49 +0000
commitbd976ae6c06b2111bd82df16b77739731dc17402 (patch)
tree406d65d00129abb45868150687f267a139bbf670 /cfutils.c
parentb9e8e95ffe9f352cde5847d458081826523cf46f (diff)
On UN*X, if an interface has a description, use it as the "friendly
name". If it doesn't have a description, on OS X, use the System Configuration framework to attempt to get a "friendly name" for interfaces. If a loopback device doesn't have a friendly name, give it "Loopback" as the friendly name. Move the "turn a CFString into a mallocated C string" routine into common code, as it's used in more than one place. svn path=/trunk/; revision=46131
Diffstat (limited to 'cfutils.c')
-rw-r--r--cfutils.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/cfutils.c b/cfutils.c
new file mode 100644
index 0000000000..78db0ac26c
--- /dev/null
+++ b/cfutils.c
@@ -0,0 +1,56 @@
+/* cfutils.c
+ * Routines to work around deficiencies in Core Foundation, such as the
+ * lack of a routine to convert a CFString to a C string of arbitrary
+ * size.
+ *
+ * $Id$
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 2001 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "config.h"
+
+#ifdef HAVE_OS_X_FRAMEWORKS
+#include <glib.h>
+#include <CoreFoundation/CoreFoundation.h>
+#include "cfutils.h"
+
+/*
+ * Convert a CFString to a UTF-8-encoded C string; the resulting string
+ * is allocated with g_malloc(). Returns NULL if the conversion fails.
+ */
+char *
+CFString_to_C_string(CFStringRef cfstring)
+{
+ CFIndex string_len;
+ char *string;
+
+ string_len = CFStringGetMaximumSizeForEncoding(CFStringGetLength(cfstring),
+ kCFStringEncodingUTF8);
+ string = g_malloc(string_len + 1);
+ if (!CFStringGetCString(cfstring, string, string_len + 1,
+ kCFStringEncodingUTF8)) {
+ g_free(string);
+ return NULL;
+ }
+ return string;
+}
+#endif
+
+