diff options
Diffstat (limited to 'arch/linux/common/net.h')
-rw-r--r-- | arch/linux/common/net.h | 72 |
1 files changed, 41 insertions, 31 deletions
diff --git a/arch/linux/common/net.h b/arch/linux/common/net.h index cd8b8706..527da1df 100644 --- a/arch/linux/common/net.h +++ b/arch/linux/common/net.h @@ -16,7 +16,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -static gchar *network_interfaces = NULL; +static gchar *network_interfaces = NULL, + *network_icons = NULL; #include <sys/ioctl.h> #include <net/if.h> @@ -100,26 +101,27 @@ void get_net_info(char *if_name, NetInfo *netinfo) static struct { char *type; char *label; + char *icon; } netdev2type[] = { - { "eth", "Ethernet" }, - { "lo", "Loopback" }, - { "ppp", "Point-to-Point" }, - { "ath", "Wireless" }, - { "wlan", "Wireless" }, - { "tun", "Virtual Point-to-Point (TUN)" }, - { "tap", "Ethernet (TAP)" }, - { "plip", "Parallel Line Internet Protocol" }, - { "irlan", "Infrared" }, - { "slip", "Serial Line Internet Protocol" }, - { "isdn", "Integrated Services Digital Network" }, - { "sit", "IPv6-over-IPv4 Tunnel" }, - { "vmnet8", "VMWare Virtual Network Interface (NAT)" }, - { "vmnet", "VMWare Virtual Network Interface" }, - { NULL, "Unknown" }, + { "eth", "Ethernet", "network" }, + { "lo", "Loopback", "network-generic" }, + { "ppp", "Point-to-Point", "modem" }, + { "ath", "Wireless", "wireless" }, + { "wlan", "Wireless", "wireless" }, + { "tun", "Virtual Point-to-Point (TUN)", "network-generic" }, + { "tap", "Ethernet (TAP)", "network-generic" }, + { "plip", "Parallel Line Internet Protocol", "network" }, + { "irlan", "Infrared", "network-generic" }, + { "slip", "Serial Line Internet Protocol", "network-generic" }, + { "isdn", "Integrated Services Digital Network", "modem" }, + { "sit", "IPv6-over-IPv4 Tunnel", "network-generic" }, + { "vmnet8", "VMWare Virtual Network Interface (NAT)", "computer" }, + { "vmnet", "VMWare Virtual Network Interface", "computer"}, + { NULL, "Unknown", "network-generic" }, }; -static const gchar * -net_get_iface_type(gchar *name) +static void +net_get_iface_type(gchar *name, gchar **type, gchar **icon) { int i; @@ -128,18 +130,14 @@ net_get_iface_type(gchar *name) break; } - return netdev2type[i].label; + *type = netdev2type[i].label; + *icon = netdev2type[i].icon; } static gboolean remove_net_devices(gpointer key, gpointer value, gpointer data) { - if (!strncmp((gchar *) key, "NET", 4)) { - g_free((gchar *) key); - g_free((GtkTreeIter *) value); - return TRUE; - } - return FALSE; + return g_str_has_prefix(key, "NET"); } static void @@ -171,7 +169,12 @@ scan_net_interfaces_24(void) g_free(network_interfaces); } + if (network_icons) { + g_free(network_icons); + } + network_interfaces = g_strdup("[Network Interfaces]\n"); + network_icons = g_strdup(""); proc_net = fopen("/proc/net/dev", "r"); while (fgets(buffer, 256, proc_net)) { @@ -179,6 +182,7 @@ scan_net_interfaces_24(void) gint trash; gchar ifacename[16]; gchar *buf = buffer; + gchar *iface_type, *iface_icon, *ip; gint i; buf = g_strstrip(buf); @@ -204,14 +208,21 @@ scan_net_interfaces_24(void) get_net_info(ifacename, &ni); devid = g_strdup_printf("NET%s", ifacename); - network_interfaces = g_strdup_printf("%s$%s$%s=Sent %.2fMiB, received %.2fMiB%s\n", + + ip = g_strdup_printf(" (%s)", ni.ip); + network_interfaces = h_strdup_cprintf("$%s$%s=Sent %.2fMiB, received %.2fMiB%s\n", network_interfaces, devid, ifacename, trans_mb, recv_mb, - ni.ip[0] ? - (gchar*)idle_free(g_strdup_printf(" (%s)", ni.ip)) : ""); + ni.ip[0] ? ip: ""); + g_free(ip); + + net_get_iface_type(ifacename, &iface_type, &iface_icon); + network_icons = h_strdup_cprintf("Icon$%s$%s=%s.png\n", + network_icons, devid, + ifacename, iface_icon); detailed = g_strdup_printf("[Network Adapter Properties]\n" "Interface Type=%s\n" @@ -220,7 +231,7 @@ scan_net_interfaces_24(void) "[Transfer Details]\n" "Bytes Received=%ld (%.2fMiB)\n" "Bytes Sent=%ld (%.2fMiB)\n", - net_get_iface_type(ifacename), + iface_type, ni.mac[0], ni.mac[1], ni.mac[2], ni.mac[3], ni.mac[4], ni.mac[5], @@ -229,8 +240,7 @@ scan_net_interfaces_24(void) trans_bytes, trans_mb); if (ni.ip[0] || ni.mask[0] || ni.broadcast[0]) { - detailed = g_strdup_printf("%s\n" - "[Internet Protocol (IPv4)]\n" + detailed = h_strdup_cprintf("\n[Internet Protocol (IPv4)]\n" "IP Address=%s\n" "Mask=%s\n" "Broadcast Address=%s\n", |