From 6dae878bbd1c2d0813f26b38cd6c447e33c903fe Mon Sep 17 00:00:00 2001
From: Jiří Klimeš <jklimes@redhat.com>
Date: Wed, 05 Sep 2012 12:59:26 +0000
Subject: editor: use nm_utils_hwaddr_ntoa() for converting MAC address to string

and fix the string leakage.
---
diff --git a/src/connection-editor/page-wired.c b/src/connection-editor/page-wired.c
index 2d1ad0f..58e13be 100644
--- a/src/connection-editor/page-wired.c
+++ b/src/connection-editor/page-wired.c
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 - 2011 Red Hat, Inc.
+ * (C) Copyright 2008 - 2012 Red Hat, Inc.
  */
 
 #include "config.h"
@@ -31,6 +31,8 @@
 #include <nm-setting-connection.h>
 #include <nm-setting-wired.h>
 #include <nm-device-ethernet.h>
+#include <nm-utils.h>
+#include <net/if_arp.h> /* for ARPHRD_ETHER for MAC utilies */
 
 #include "page-wired.h"
 
@@ -174,11 +176,7 @@ populate_ui (CEPageWired *self)
 	/* Device MAC address */
 	mac_list = ce_page_get_mac_list (CE_PAGE (self));
 	s_mac = nm_setting_wired_get_mac_address (setting);
-	s_mac_str = s_mac ? g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
-	                                     s_mac->data[0], s_mac->data[1], s_mac->data[2],
-	                                     s_mac->data[3], s_mac->data[4], s_mac->data[5]):
-	                    NULL;
-
+	s_mac_str = s_mac ? nm_utils_hwaddr_ntoa (s_mac->data, ARPHRD_ETHER) : NULL;
 	for (iter = mac_list; iter && *iter; iter++) {
 #if GTK_CHECK_VERSION (2,24,0)
 		gtk_combo_box_text_append_text (priv->device_mac, *iter);
@@ -202,6 +200,7 @@ populate_ui (CEPageWired *self)
 		if (entry)
 			gtk_entry_set_text (GTK_ENTRY (entry), active_mac ? active_mac : s_mac_str);
 	}
+	g_free (s_mac_str);
 	g_strfreev (mac_list);
 	g_signal_connect (priv->device_mac, "changed", G_CALLBACK (stuff_changed), self);
 
diff --git a/src/connection-editor/page-wireless.c b/src/connection-editor/page-wireless.c
index 886f175..74b48cf 100644
--- a/src/connection-editor/page-wireless.c
+++ b/src/connection-editor/page-wireless.c
@@ -17,7 +17,7 @@
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
- * (C) Copyright 2008 - 2010 Red Hat, Inc.
+ * (C) Copyright 2008 - 2012 Red Hat, Inc.
  */
 
 #include "config.h"
@@ -32,6 +32,7 @@
 #include <nm-setting-wireless.h>
 #include <nm-device-wifi.h>
 #include <nm-utils.h>
+#include <net/if_arp.h> /* for ARPHRD_ETHER for MAC utilies */
 
 #include "page-wireless.h"
 
@@ -374,11 +375,7 @@ populate_ui (CEPageWireless *self)
 	/* Device MAC address */
 	mac_list = ce_page_get_mac_list (CE_PAGE (self));
 	s_mac = nm_setting_wireless_get_mac_address (setting);
-	s_mac_str = s_mac ? g_strdup_printf ("%02X:%02X:%02X:%02X:%02X:%02X",
-	                                     s_mac->data[0], s_mac->data[1], s_mac->data[2],
-	                                     s_mac->data[3], s_mac->data[4], s_mac->data[5]):
-	                    NULL;
-
+	s_mac_str = s_mac ? nm_utils_hwaddr_ntoa (s_mac->data, ARPHRD_ETHER) : NULL;
 	for (iter = mac_list; iter && *iter; iter++) {
 #if GTK_CHECK_VERSION (2,24,0)
 		gtk_combo_box_text_append_text (priv->device_mac, *iter);
@@ -402,6 +399,7 @@ populate_ui (CEPageWireless *self)
 		if (entry)
 			gtk_entry_set_text (GTK_ENTRY (entry), active_mac ? active_mac : s_mac_str);
 	}
+	g_free (s_mac_str);
 	g_strfreev (mac_list);
 	g_signal_connect_swapped (priv->device_mac, "changed", G_CALLBACK (ce_page_changed), self);
 
--
cgit v0.9.0.2
