[network-manager-applet] editor: use nm_utils_hwaddr_ntoa() for converting MAC address to string



commit c517af3b1fe7f3ea921bfe429e4f4539ce9b464f
Author: JiÅÃ KlimeÅ <jklimes redhat com>
Date:   Thu Aug 30 11:46:52 2012 +0200

    editor: use nm_utils_hwaddr_ntoa() for converting MAC address to string
    
    and fix the string leakage.

 src/connection-editor/page-ethernet.c   |    8 +++-----
 src/connection-editor/page-infiniband.c |    3 ++-
 src/connection-editor/page-wifi.c       |    7 ++-----
 src/connection-editor/page-wimax.c      |    7 ++-----
 4 files changed, 9 insertions(+), 16 deletions(-)
---
diff --git a/src/connection-editor/page-ethernet.c b/src/connection-editor/page-ethernet.c
index 0024ca1..985388d 100644
--- a/src/connection-editor/page-ethernet.c
+++ b/src/connection-editor/page-ethernet.c
@@ -31,6 +31,7 @@
 #include <nm-setting-connection.h>
 #include <nm-setting-wired.h>
 #include <nm-device-ethernet.h>
+#include <nm-utils.h>
 
 #include "page-ethernet.h"
 
@@ -174,11 +175,7 @@ populate_ui (CEPageEthernet *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 +199,7 @@ populate_ui (CEPageEthernet *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-infiniband.c b/src/connection-editor/page-infiniband.c
index c0a4f60..d10af7b 100644
--- a/src/connection-editor/page-infiniband.c
+++ b/src/connection-editor/page-infiniband.c
@@ -127,7 +127,7 @@ populate_ui (CEPageInfiniband *self)
 #else
 		gtk_combo_box_append_text (GTK_COMBO_BOX (priv->device_mac), *iter);
 #endif
-		if (s_mac_str && g_ascii_strncasecmp (*iter, s_mac_str, 17) == 0)
+		if (s_mac_str && g_ascii_strncasecmp (*iter, s_mac_str, 59) == 0)
 			active_mac = *iter;
 	}
 
@@ -144,6 +144,7 @@ populate_ui (CEPageInfiniband *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-wifi.c b/src/connection-editor/page-wifi.c
index 4199a2f..be7449f 100644
--- a/src/connection-editor/page-wifi.c
+++ b/src/connection-editor/page-wifi.c
@@ -378,11 +378,7 @@ populate_ui (CEPageWifi *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);
@@ -406,6 +402,7 @@ populate_ui (CEPageWifi *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);
 
diff --git a/src/connection-editor/page-wimax.c b/src/connection-editor/page-wimax.c
index c51fa0f..449a621 100644
--- a/src/connection-editor/page-wimax.c
+++ b/src/connection-editor/page-wimax.c
@@ -95,11 +95,7 @@ populate_ui (CEPageWimax *self)
 	/* Device MAC address */
 	mac_list = ce_page_get_mac_list (CE_PAGE (self));
 	s_mac = nm_setting_wimax_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);
@@ -123,6 +119,7 @@ populate_ui (CEPageWimax *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);
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]