summaryrefslogtreecommitdiff
path: root/netspeed
diff options
context:
space:
mode:
Diffstat (limited to 'netspeed')
-rw-r--r--netspeed/data/netspeed-details.ui161
-rw-r--r--netspeed/src/backend.c102
-rw-r--r--netspeed/src/backend.h4
-rw-r--r--netspeed/src/netspeed.c22
4 files changed, 203 insertions, 86 deletions
diff --git a/netspeed/data/netspeed-details.ui b/netspeed/data/netspeed-details.ui
index a537555f..32f01ed1 100644
--- a/netspeed/data/netspeed-details.ui
+++ b/netspeed/data/netspeed-details.ui
@@ -1,40 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.36.0 -->
+<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<object class="GtkImage" id="close_img">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="icon_name">window-close</property>
+ <property name="can-focus">False</property>
+ <property name="icon-name">window-close</property>
</object>
<object class="GtkImage" id="help_img">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="icon_name">help-browser</property>
+ <property name="can-focus">False</property>
+ <property name="icon-name">help-browser</property>
</object>
<object class="GtkDialog" id="dialog">
- <property name="can_focus">False</property>
- <property name="border_width">12</property>
- <property name="type_hint">dialog</property>
+ <property name="can-focus">False</property>
+ <property name="border-width">12</property>
+ <property name="type-hint">dialog</property>
<signal name="response" handler="on_dialog_response" swapped="no"/>
<child internal-child="vbox">
<object class="GtkBox">
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">12</property>
<child internal-child="action_area">
<object class="GtkButtonBox">
- <property name="can_focus">False</property>
- <property name="layout_style">end</property>
+ <property name="can-focus">False</property>
+ <property name="layout-style">end</property>
<child>
<object class="GtkButton" id="button1">
<property name="label" translatable="yes">_Help</property>
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">True</property>
<property name="image">help_img</property>
- <property name="use_underline">True</property>
- <property name="always_show_image">True</property>
+ <property name="use-underline">True</property>
+ <property name="always-show-image">True</property>
</object>
<packing>
<property name="expand">True</property>
@@ -46,13 +46,13 @@
<object class="GtkButton" id="button2">
<property name="label" translatable="yes">_Close</property>
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="can_default">True</property>
- <property name="has_default">True</property>
- <property name="receives_default">True</property>
+ <property name="can-focus">True</property>
+ <property name="can-default">True</property>
+ <property name="has-default">True</property>
+ <property name="receives-default">True</property>
<property name="image">close_img</property>
- <property name="use_underline">True</property>
- <property name="always_show_image">True</property>
+ <property name="use-underline">True</property>
+ <property name="always-show-image">True</property>
</object>
<packing>
<property name="expand">True</property>
@@ -70,26 +70,26 @@
<child>
<object class="GtkBox">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">10</property>
<child>
<object class="GtkFrame" id="da_frame">
<property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="label_xalign">0</property>
- <property name="shadow_type">none</property>
+ <property name="can-focus">False</property>
+ <property name="label-xalign">0</property>
+ <property name="shadow-type">none</property>
<child>
<object class="GtkAlignment">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
<child>
<object class="GtkDrawingArea" id="drawingarea">
- <property name="height_request">180</property>
+ <property name="height-request">180</property>
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<signal name="draw" handler="on_drawingarea_draw" swapped="no"/>
</object>
</child>
@@ -97,7 +97,7 @@
</child>
<child type="label">
<object class="GtkLabel">
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="label" translatable="yes">Transfer Rate Graph</property>
</object>
</child>
@@ -111,13 +111,13 @@
<child>
<object class="GtkBox">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="spacing">6</property>
<child>
<object class="GtkColorButton" id="incolor_sel">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">True</property>
<signal name="color-set" handler="on_incolor_sel_color_set" swapped="no"/>
</object>
<packing>
@@ -129,10 +129,10 @@
<child>
<object class="GtkLabel">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="label" translatable="yes">_In graph color</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">incolor_sel</property>
+ <property name="use-underline">True</property>
+ <property name="mnemonic-widget">incolor_sel</property>
</object>
<packing>
<property name="expand">False</property>
@@ -143,8 +143,8 @@
<child>
<object class="GtkColorButton" id="outcolor_sel">
<property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">True</property>
+ <property name="can-focus">True</property>
+ <property name="receives-default">True</property>
<signal name="color-set" handler="on_outcolor_sel_color_set" swapped="no"/>
</object>
<packing>
@@ -156,10 +156,10 @@
<child>
<object class="GtkLabel">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="label" translatable="yes">_Out graph color</property>
- <property name="use_underline">True</property>
- <property name="mnemonic_widget">outcolor_sel</property>
+ <property name="use-underline">True</property>
+ <property name="mnemonic-widget">outcolor_sel</property>
</object>
<packing>
<property name="expand">False</property>
@@ -177,19 +177,19 @@
<child>
<object class="GtkBox">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="ip_label">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">IPv4 Address:</property>
<property name="xalign">0</property>
@@ -203,7 +203,7 @@
<child>
<object class="GtkLabel" id="ip_text">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="selectable">True</property>
<property name="xalign">0</property>
@@ -217,7 +217,7 @@
<child>
<object class="GtkLabel" id="netmask_label">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Netmask:</property>
<property name="xalign">0</property>
@@ -231,7 +231,7 @@
<child>
<object class="GtkLabel" id="netmask_text">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="selectable">True</property>
<property name="xalign">0</property>
@@ -252,12 +252,12 @@
<child>
<object class="GtkBox">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="hwaddr_label">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Hardware Address:</property>
<property name="xalign">0</property>
@@ -271,7 +271,7 @@
<child>
<object class="GtkLabel" id="hwaddr_text">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="selectable">True</property>
<property name="xalign">0</property>
@@ -285,7 +285,7 @@
<child>
<object class="GtkLabel" id="ptpip_label">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">P-t-P Address:</property>
<property name="xalign">0</property>
@@ -299,7 +299,7 @@
<child>
<object class="GtkLabel" id="ptpip_text">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="selectable">True</property>
<property name="xalign">0</property>
@@ -320,12 +320,12 @@
<child>
<object class="GtkBox">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="inbytes_label">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Bytes in:</property>
<property name="xalign">0</property>
@@ -339,7 +339,7 @@
<child>
<object class="GtkLabel" id="inbytes_text">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">0 byte</property>
<property name="xalign">0</property>
@@ -353,7 +353,7 @@
<child>
<object class="GtkLabel" id="outbytes_label">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Bytes out:</property>
<property name="xalign">0</property>
@@ -367,7 +367,7 @@
<child>
<object class="GtkLabel" id="outbytes_text">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">0 byte</property>
<property name="xalign">0</property>
@@ -388,15 +388,16 @@
<child>
<object class="GtkBox" id="ipv6_box">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="ipv6_label">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">IPv6 Address:</property>
<property name="xalign">0</property>
+ <property name="yalign">0</property>
</object>
<packing>
<property name="expand">False</property>
@@ -407,10 +408,11 @@
<child>
<object class="GtkLabel" id="ipv6_text">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="selectable">True</property>
<property name="xalign">0</property>
+ <property name="yalign">0</property>
</object>
<packing>
<property name="expand">False</property>
@@ -428,18 +430,18 @@
<child>
<object class="GtkBox" id="wireless_box">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="essid_label">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">ESSID:</property>
<property name="xalign">0</property>
@@ -453,7 +455,7 @@
<child>
<object class="GtkLabel" id="essid_text">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="selectable">True</property>
<property name="xalign">0</property>
@@ -467,7 +469,7 @@
<child>
<object class="GtkLabel" id="signal_label">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="label" translatable="yes">Signal Strength:</property>
<property name="xalign">0</property>
@@ -481,7 +483,7 @@
<child>
<object class="GtkProgressBar" id="signalbar">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="halign">start</property>
<property name="hexpand">True</property>
</object>
@@ -501,18 +503,18 @@
<child>
<object class="GtkBox" id="netlink_box">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="station_label">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="label" translatable="yes">Station:</property>
<property name="xalign">0</property>
</object>
@@ -525,7 +527,7 @@
<child>
<object class="GtkLabel" id="station_text">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="xalign">0</property>
</object>
<packing>
@@ -537,7 +539,7 @@
<child>
<object class="GtkLabel" id="channel_label">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="label" translatable="yes">Channel:</property>
<property name="xalign">0</property>
</object>
@@ -550,7 +552,7 @@
<child>
<object class="GtkLabel" id="channel_text">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="xalign">0</property>
</object>
<packing>
@@ -569,12 +571,12 @@
<child>
<object class="GtkBox">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="spacing">12</property>
<child>
<object class="GtkLabel" id="connected_time_label">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="label" translatable="yes">Connected Time:</property>
<property name="xalign">0</property>
</object>
@@ -587,7 +589,7 @@
<child>
<object class="GtkLabel" id="connected_time_text">
<property name="visible">True</property>
- <property name="can_focus">False</property>
+ <property name="can-focus">False</property>
<property name="xalign">0</property>
</object>
<packing>
@@ -637,12 +639,9 @@
<action-widget response="-11">button1</action-widget>
<action-widget response="-3">button2</action-widget>
</action-widgets>
- <child type="titlebar">
- <placeholder/>
- </child>
</object>
<object class="GtkSizeGroup">
- <property name="ignore_hidden">True</property>
+ <property name="ignore-hidden">True</property>
<widgets>
<widget name="ip_label"/>
<widget name="hwaddr_label"/>
@@ -654,7 +653,7 @@
</widgets>
</object>
<object class="GtkSizeGroup">
- <property name="ignore_hidden">True</property>
+ <property name="ignore-hidden">True</property>
<widgets>
<widget name="ip_text"/>
<widget name="hwaddr_text"/>
@@ -664,7 +663,7 @@
</widgets>
</object>
<object class="GtkSizeGroup">
- <property name="ignore_hidden">True</property>
+ <property name="ignore-hidden">True</property>
<widgets>
<widget name="netmask_label"/>
<widget name="ptpip_label"/>
@@ -674,7 +673,7 @@
</widgets>
</object>
<object class="GtkSizeGroup">
- <property name="ignore_hidden">True</property>
+ <property name="ignore-hidden">True</property>
<widgets>
<widget name="netmask_text"/>
<widget name="ptpip_text"/>
diff --git a/netspeed/src/backend.c b/netspeed/src/backend.c
index 110173d6..5eb67319 100644
--- a/netspeed/src/backend.c
+++ b/netspeed/src/backend.c
@@ -27,6 +27,12 @@
#include <sys/sockio.h>
#endif
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <ifaddrs.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
#include <glib.h>
#include <glib/gi18n.h>
#include <glibtop/netlist.h>
@@ -105,6 +111,102 @@ get_available_devices (void)
return device_glist;
}
+GSList*
+get_ip_address_list (const char *iface_name,
+ gboolean ipv4)
+{
+ GSList *list = NULL;
+ struct ifaddrs *ifaces;
+
+ if (getifaddrs (&ifaces) != -1) {
+ int family;
+ char ip[INET6_ADDRSTRLEN];
+
+ family = ipv4 ? AF_INET : AF_INET6;
+ for (struct ifaddrs *iface = ifaces; iface != NULL; iface = iface->ifa_next) {
+ if (iface->ifa_addr == NULL)
+ continue;
+
+ if ((iface->ifa_addr->sa_family == family) &&
+ !g_strcmp0 (iface->ifa_name, iface_name))
+ {
+ unsigned int netmask = 0;
+ void *sinx_addr = NULL;
+
+ if (iface->ifa_addr->sa_family == AF_INET6) {
+ struct sockaddr_in6 ip6_addr;
+ struct sockaddr_in6 ip6_network;
+ uint32_t ip6_netmask = 0;
+ const char *scope;
+ int i;
+
+ memcpy (&ip6_addr, iface->ifa_addr, sizeof (struct sockaddr_in6));
+ memcpy (&ip6_network, iface->ifa_netmask, sizeof (struct sockaddr_in6));
+
+ /* get network scope */
+ if (IN6_IS_ADDR_LINKLOCAL (&ip6_addr.sin6_addr)) {
+ scope = _("link-local");
+ } else if (IN6_IS_ADDR_SITELOCAL (&ip6_addr.sin6_addr)) {
+ scope = _("site-local");
+ } else if (IN6_IS_ADDR_V4MAPPED (&ip6_addr.sin6_addr)) {
+ scope = _("v4mapped");
+ } else if (IN6_IS_ADDR_V4COMPAT (&ip6_addr.sin6_addr)) {
+ scope = _("v4compat");
+ } else if (IN6_IS_ADDR_LOOPBACK (&ip6_addr.sin6_addr)) {
+ scope = _("host");
+ } else if (IN6_IS_ADDR_UNSPECIFIED (&ip6_addr.sin6_addr)) {
+ scope = _("unspecified");
+ } else {
+ scope = _("global");
+ }
+
+ /* get network ip */
+ sinx_addr = &ip6_addr.sin6_addr;
+ inet_ntop (iface->ifa_addr->sa_family, sinx_addr, ip, sizeof (ip));
+
+ /* get network mask length */
+ for (i = 0; i < 4; i++) {
+ ip6_netmask = ntohl (((uint32_t*)(&ip6_network.sin6_addr))[i]);
+ while (ip6_netmask) {
+ netmask++;
+ ip6_netmask <<= 1;
+ }
+ }
+
+ list = g_slist_prepend (list,
+ g_strdup_printf ("%s: %s/%u",
+ scope, ip, netmask));
+ } else {
+ struct sockaddr_in ip4_addr;
+ struct sockaddr_in ip4_network;
+ in_addr_t ip4_netmask = 0;
+
+ memcpy (&ip4_addr, iface->ifa_addr, sizeof (struct sockaddr_in));
+ memcpy (&ip4_network, iface->ifa_netmask, sizeof (struct sockaddr_in));
+
+ /* get network ip */
+ sinx_addr = &ip4_addr.sin_addr;
+ inet_ntop (iface->ifa_addr->sa_family, sinx_addr, ip, sizeof (ip));
+
+ /* get network mask length */
+ ip4_netmask = ntohl (ip4_network.sin_addr.s_addr);
+ while (ip4_netmask) {
+ netmask++;
+ ip4_netmask <<= 1;
+ }
+
+ list = g_slist_prepend (list,
+ g_strdup_printf ("%s/%u", ip, netmask));
+ }
+ }
+ }
+ if (list != NULL)
+ list = g_slist_sort (list, (GCompareFunc) g_strcmp0);
+ freeifaddrs (ifaces);
+ }
+ return list;
+}
+
const gchar*
get_default_route (void)
{
diff --git a/netspeed/src/backend.h b/netspeed/src/backend.h
index 536bf862..cd98c66c 100644
--- a/netspeed/src/backend.h
+++ b/netspeed/src/backend.h
@@ -104,4 +104,8 @@ compare_device_info (const DevInfo *a, const DevInfo *b);
void
get_wireless_info (DevInfo *devinfo);
+
+GSList*
+get_ip_address_list (const char *ifa_name, gboolean ipv4);
+
#endif /* _BACKEND_H */
diff --git a/netspeed/src/netspeed.c b/netspeed/src/netspeed.c
index b3e88847..eaa1b5ae 100644
--- a/netspeed/src/netspeed.c
+++ b/netspeed/src/netspeed.c
@@ -688,7 +688,6 @@ fill_details_dialog (MateNetspeedApplet *applet)
{
char *text;
char ipv4_text [INET_ADDRSTRLEN];
- char ipv6_text [INET6_ADDRSTRLEN];
if (applet->devinfo->ip) {
format_ipv4 (applet->devinfo->ip, ipv4_text);
@@ -723,10 +722,23 @@ fill_details_dialog (MateNetspeedApplet *applet)
gtk_label_set_text (GTK_LABEL (applet->ptpip_text), text);
/* check if we got an ipv6 address */
- format_ipv6 (applet->devinfo->ipv6, ipv6_text);
- if (strlen (ipv6_text) > 2) {
- gtk_label_set_text (GTK_LABEL (applet->ipv6_text), ipv6_text);
- gtk_widget_show (applet->ipv6_box);
+ GSList *ipv6_address_list = get_ip_address_list (applet->devinfo->name, FALSE);
+ if (ipv6_address_list != NULL) {
+ GSList *iterator;
+ GString *string = NULL;
+
+ for (iterator = ipv6_address_list; iterator; iterator = iterator->next) {
+ if (string == NULL)
+ string = g_string_new ((char*) iterator->data);
+ else
+ g_string_append_printf (string, "\n%s", (char*) iterator->data);
+ }
+ if (string != NULL) {
+ gtk_label_set_text (GTK_LABEL (applet->ipv6_text), string->str);
+ gtk_widget_show (applet->ipv6_box);
+ }
+ g_string_free (string, TRUE);
+ g_slist_free_full (ipv6_address_list, g_free);
} else {
gtk_widget_hide (applet->ipv6_box);
}