I have attached to the mail a patch to add IPv6 support for the info tool. It includes a GUI change, so you can see a screenshot here: http://www.linups.org/~kal/gn.png -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Carlos Garcia Campos a.k.a. KaL elkalmail yahoo es carlosgc gnome org Grupo Linups Usuarios de SL/Linux de la UPSAM http://www.linups.org =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= PGP key: http://pgp.rediris.es:11371/pks/lookup?op=get&search=0x523E6462
Index: ChangeLog =================================================================== RCS file: /cvs/gnome/gnome-network/gnome-netinfo/ChangeLog,v retrieving revision 1.93 diff -u -u -r1.93 ChangeLog --- ChangeLog 2 Oct 2003 21:26:16 -0000 1.93 +++ ChangeLog 20 Oct 2003 21:41:55 -0000 @@ -1,3 +1,15 @@ +2003-10-20 Carlos García Campos <carlosgc gnome org> + + * gnome-netinfo.glade: added a treeview for the ip addresses information + * info.c (create_model, ip6_masklen,ip6_construct_address, + get_nic_information, compare, get_interfaces), info.h: IPv6 Support + * main.c, netinfo.h: IPv6 Support + +2003-10-06 Carlos García Campos <carlosgc gnome org> + + * netstat.c (get_active_option, strip_protocol_line, + strip_route_line): IPv6 support + 2003-10-02 Carlos García Campos <carlosgc gnome org> * netinfo.c (get_ip_version): added a function to get the Index: gnome-netinfo.glade =================================================================== RCS file: /cvs/gnome/gnome-network/gnome-netinfo/gnome-netinfo.glade,v retrieving revision 1.26 diff -u -u -r1.26 gnome-netinfo.glade --- gnome-netinfo.glade 31 Jul 2003 20:34:40 -0000 1.26 +++ gnome-netinfo.glade 20 Oct 2003 21:41:55 -0000 @@ -227,6 +227,123 @@ </child> <child> + <widget class="GtkVBox" id="vbox13"> + <property name="border_width">6</property> + <property name="visible">True</property> + <property name="homogeneous">False</property> + <property name="spacing">12</property> + + <child> + <widget class="GtkLabel" id="label83"> + <property name="visible">True</property> + <property name="label" translatable="yes"><span weight="bold">IP Information</span></property> + <property name="use_underline">False</property> + <property name="use_markup">True</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + + <child> + <widget class="GtkHBox" id="hbox31"> + <property name="visible">True</property> + <property name="homogeneous">False</property> + <property name="spacing">0</property> + + <child> + <widget class="GtkLabel" id="label81"> + <property name="visible">True</property> + <property name="label" translatable="yes"> </property> + <property name="use_underline">False</property> + <property name="use_markup">False</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + + <child> + <widget class="GtkScrolledWindow" id="scrolledwindow7"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="hscrollbar_policy">GTK_POLICY_AUTOMATIC</property> + <property name="vscrollbar_policy">GTK_POLICY_AUTOMATIC</property> + <property name="shadow_type">GTK_SHADOW_IN</property> + <property name="window_placement">GTK_CORNER_TOP_LEFT</property> + + <child> + <widget class="GtkTreeView" id="list_ip_addr"> + <property name="visible">True</property> + <property name="can_focus">True</property> + <property name="headers_visible">True</property> + <property name="rules_hint">True</property> + <property name="reorderable">False</property> + <property name="enable_search">False</property> + </widget> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">True</property> + <property name="fill">True</property> + </packing> + </child> + + <child> + <widget class="GtkLabel" id="label82"> + <property name="visible">True</property> + <property name="label" translatable="yes"> </property> + <property name="use_underline">False</property> + <property name="use_markup">False</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0.5</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">False</property> + <property name="fill">False</property> + </packing> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">True</property> + <property name="fill">True</property> + </packing> + </child> + </widget> + <packing> + <property name="padding">0</property> + <property name="expand">True</property> + <property name="fill">True</property> + </packing> + </child> + + <child> <widget class="GtkHBox" id="hbox_info_detail"> <property name="visible">True</property> <property name="homogeneous">True</property> @@ -242,7 +359,7 @@ <child> <widget class="GtkLabel" id="label49"> <property name="visible">True</property> - <property name="label" translatable="yes"><span weight="bold">Information</span></property> + <property name="label" translatable="yes"><span weight="bold">Interface Information</span></property> <property name="use_underline">False</property> <property name="use_markup">True</property> <property name="justify">GTK_JUSTIFY_LEFT</property> @@ -291,7 +408,7 @@ <widget class="GtkTable" id="table_information"> <property name="border_width">6</property> <property name="visible">True</property> - <property name="n_rows">8</property> + <property name="n_rows">5</property> <property name="n_columns">2</property> <property name="homogeneous">False</property> <property name="row_spacing">6</property> @@ -322,30 +439,6 @@ </child> <child> - <widget class="GtkLabel" id="label_ip_address"> - <property name="visible">True</property> - <property name="label" translatable="yes">IP address:</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> <widget class="GtkLabel" id="info_hw_address"> <property name="visible">True</property> <property name="can_focus">True</property> @@ -370,129 +463,6 @@ </child> <child> - <widget class="GtkLabel" id="info_ip_address"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">not available</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">True</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">1</property> - <property name="bottom_attach">2</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label_netmask"> - <property name="visible">True</property> - <property name="label" translatable="yes">Netmask:</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="label_broadcast"> - <property name="visible">True</property> - <property name="label" translatable="yes">Broadcast:</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">False</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">0</property> - <property name="right_attach">1</property> - <property name="top_attach">3</property> - <property name="bottom_attach">4</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="info_netmask"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">not available</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">True</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">2</property> - <property name="bottom_attach">3</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> - <widget class="GtkLabel" id="info_broadcast"> - <property name="visible">True</property> - <property name="can_focus">True</property> - <property name="label" translatable="yes">not available</property> - <property name="use_underline">False</property> - <property name="use_markup">False</property> - <property name="justify">GTK_JUSTIFY_LEFT</property> - <property name="wrap">False</property> - <property name="selectable">True</property> - <property name="xalign">0</property> - <property name="yalign">0.5</property> - <property name="xpad">0</property> - <property name="ypad">0</property> - </widget> - <packing> - <property name="left_attach">1</property> - <property name="right_attach">2</property> - <property name="top_attach">3</property> - <property name="bottom_attach">4</property> - <property name="x_options">fill</property> - <property name="y_options"></property> - </packing> - </child> - - <child> <widget class="GtkLabel" id="label_multicast"> <property name="visible">True</property> <property name="label" translatable="yes">Multicast:</property> @@ -509,8 +479,8 @@ <packing> <property name="left_attach">0</property> <property name="right_attach">1</property> - <property name="top_attach">4</property> - <property name="bottom_attach">5</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> <property name="x_options">fill</property> <property name="y_options"></property> </packing> @@ -534,8 +504,8 @@ <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> - <property name="top_attach">4</property> - <property name="bottom_attach">5</property> + <property name="top_attach">1</property> + <property name="bottom_attach">2</property> <property name="x_options">fill</property> <property name="y_options"></property> </packing> @@ -559,8 +529,8 @@ <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> - <property name="top_attach">7</property> - <property name="bottom_attach">8</property> + <property name="top_attach">4</property> + <property name="bottom_attach">5</property> <property name="x_options">fill</property> <property name="y_options"></property> </packing> @@ -583,8 +553,8 @@ <packing> <property name="left_attach">0</property> <property name="right_attach">1</property> - <property name="top_attach">7</property> - <property name="bottom_attach">8</property> + <property name="top_attach">4</property> + <property name="bottom_attach">5</property> <property name="x_options">fill</property> <property name="y_options"></property> </packing> @@ -607,8 +577,8 @@ <packing> <property name="left_attach">0</property> <property name="right_attach">1</property> - <property name="top_attach">5</property> - <property name="bottom_attach">6</property> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> <property name="x_options">fill</property> <property name="y_options"></property> </packing> @@ -632,8 +602,8 @@ <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> - <property name="top_attach">5</property> - <property name="bottom_attach">6</property> + <property name="top_attach">2</property> + <property name="bottom_attach">3</property> <property name="x_options">fill</property> <property name="y_options"></property> </packing> @@ -656,8 +626,8 @@ <packing> <property name="left_attach">0</property> <property name="right_attach">1</property> - <property name="top_attach">6</property> - <property name="bottom_attach">7</property> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> <property name="x_options">fill</property> <property name="y_options"></property> </packing> @@ -681,8 +651,8 @@ <packing> <property name="left_attach">1</property> <property name="right_attach">2</property> - <property name="top_attach">6</property> - <property name="bottom_attach">7</property> + <property name="top_attach">3</property> + <property name="bottom_attach">4</property> <property name="x_options">fill</property> <property name="y_options"></property> </packing> Index: info.c =================================================================== RCS file: /cvs/gnome/gnome-network/gnome-netinfo/info.c,v retrieving revision 1.18 diff -u -u -r1.18 info.c --- info.c 24 Jul 2003 21:34:16 -0000 1.18 +++ info.c 20 Oct 2003 21:41:56 -0000 @@ -29,6 +29,7 @@ #include <sys/socket.h> /* basic socket definitions */ #include <arpa/inet.h> /* inet(3) functions */ #include <sys/un.h> /* for Unix domain sockets */ +#include <ifaddrs.h> /* getifaddrs () funtion */ #include <sys/ioctl.h> #include <stdlib.h> #include <net/if.h> @@ -37,18 +38,73 @@ #include "utils.h" #include "util-mii.h" +#ifndef IN6_IS_ADDR_GLOBAL +#define IN6_IS_ADDR_GLOBAL(a) \ + (((((__const uint8_t *) (a))[0] & 0xff) == 0x3f \ + || (((__const uint8_t *) (a))[0] & 0xff) == 0x20)) +#endif + /* #ifdef IFCONFIG_PROGRAM #define IFCONFIG IFCONFIG_PROGRAM " -s" */ + GList * info_get_interfaces (); void info_do (const gchar * nic, Netinfo * info) { + +} + +static void +info_create_model (GtkTreeView * widget) +{ + GtkCellRenderer *renderer; + static GtkTreeViewColumn *column; + GtkTreeModel *model; + + g_return_if_fail (widget != NULL); + + renderer = gtk_cell_renderer_text_new (); + /* IP Address */ + column = + gtk_tree_view_column_new_with_attributes + (_("IP Address"), renderer, "text", 0, NULL); + gtk_tree_view_append_column (widget, column); + + renderer = gtk_cell_renderer_text_new (); + /* Netmask / Prefix */ + column = + gtk_tree_view_column_new_with_attributes + (_("Netmask"), renderer, "text", 1, NULL); + gtk_tree_view_append_column (widget, column); + + renderer = gtk_cell_renderer_text_new (); + /* Broadcast */ + column = + gtk_tree_view_column_new_with_attributes + (_("Broadcast"), renderer, "text", 2, NULL); + gtk_tree_view_append_column (widget, column); + + renderer = gtk_cell_renderer_text_new (); + /* Scope */ + column = + gtk_tree_view_column_new_with_attributes + (_("Scope"), renderer, "text", 3, NULL); + gtk_tree_view_append_column (widget, column); + + model = GTK_TREE_MODEL (gtk_list_store_new + (4, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING)); + gtk_tree_view_set_model (widget, model); + /*return model;*/ } void @@ -66,6 +122,7 @@ } g_list_free (items); + } gboolean @@ -150,13 +207,18 @@ { const gchar *text; Netinfo *info = data; + GtkTreeModel *model; static gint timeout_source = 0; g_return_if_fail (info != NULL); text = gtk_entry_get_text (GTK_ENTRY (editable)); - + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (info->list_ip_addr)); + if (model != NULL) + gtk_list_store_clear (GTK_LIST_STORE (model)); + /* Fill the NIC configuration data */ info_get_nic_information (text, info); info_nic_update_stats (data); @@ -168,161 +230,289 @@ timeout_source = g_timeout_add (DELAY_STATS, info_nic_update_stats, data); } +static gint +info_ip6_masklen (struct in6_addr netmask) +{ + gint len = 0; + guchar val; + guchar *pnt; + + pnt = (guchar *) & netmask; + + while ((*pnt == 0xff) && len < 128) { + len += 8; + pnt++; + } + + if (len < 128) { + val = *pnt; + while (val) { + len++; + val <<= 1; + } + } + return len; +} + +static InfoIpAddr * +info_ip6_construct_address (const struct ifaddrs *ifr6) +{ + struct sockaddr_in6 *sinptr6; + gchar ip_addr[INFO_ADDRSTRLEN], *scope; + gint prefix; + InfoIpAddr *ip6; + + sinptr6 = (struct sockaddr_in6 *) ifr6->ifa_addr; + inet_ntop (AF_INET6, &sinptr6->sin6_addr, ip_addr, INFO_ADDRSTRLEN); + + if (IN6_IS_ADDR_LINKLOCAL (&sinptr6->sin6_addr)) + scope = g_strdup ("Link"); + else if (IN6_IS_ADDR_SITELOCAL (&sinptr6->sin6_addr)) + scope = g_strdup ("Site"); + else if (IN6_IS_ADDR_GLOBAL (&sinptr6->sin6_addr)) + scope = g_strdup ("Global"); + else if (IN6_IS_ADDR_MC_ORGLOCAL (&sinptr6->sin6_addr)) + scope = g_strdup ("Global"); + else if (IN6_IS_ADDR_V4COMPAT (&sinptr6->sin6_addr)) + scope = g_strdup ("Global"); + else if (IN6_IS_ADDR_MULTICAST (&sinptr6->sin6_addr)) + scope = g_strdup ("Global"); + else if (IN6_IS_ADDR_UNSPECIFIED (&sinptr6->sin6_addr)) + scope = g_strdup ("Global"); + else if (IN6_IS_ADDR_LOOPBACK (&sinptr6->sin6_addr)) + scope = g_strdup ("Host"); + else + scope = g_strdup (_("Unknown")); + + sinptr6 = (struct sockaddr_in6 *) ifr6->ifa_netmask; + prefix = info_ip6_masklen (sinptr6->sin6_addr); + + ip6 = g_new0 (InfoIpAddr, 1); + ip6->ip_addr = g_strdup (ip_addr); + ip6->ip_prefix = g_strdup_printf ("%d", prefix); + ip6->ip_bcast = g_strdup (""); + ip6->ip_scope = g_strdup (scope); + + g_free (scope); + + return (ip6); +} + void info_get_nic_information (const gchar *nic, Netinfo *info) { - gint sockfd, len; - gchar *ptr, buf[2048], dst[INFO_ADDRSTRLEN]; - struct ifconf ifc; - struct ifreq *ifr, ifrcopy; - struct sockaddr_in *sinptr; - gint flags; - gboolean loopback; - mii_data_result data; + GtkTreeModel *model; + GtkTreeIter iter; + gint sockfd, len, count; + gchar *ptr, buf[2048], dst[INFO_ADDRSTRLEN]; + struct ifconf ifc; + struct ifreq *ifr, ifrcopy; + struct ifaddrs *ifa0, *ifr6; + struct sockaddr_in *sinptr; + struct sockaddr_in6 *sinptr6; + gint flags; + gboolean loopback; + mii_data_result data; + InfoIpAddr *ip; + + model = gtk_tree_view_get_model (GTK_TREE_VIEW (info->list_ip_addr)); + if (model == NULL) + info_create_model (GTK_TREE_VIEW (info->list_ip_addr)); + + getifaddrs (&ifa0); + + count = 0; + for (ifr6 = ifa0; ifr6; ifr6 = ifr6->ifa_next) { + if (strcmp (ifr6->ifa_name, nic) != 0) { + continue; + } - sockfd = socket (AF_INET, SOCK_DGRAM, 0); + switch (ifr6->ifa_addr->sa_family) { - ifc.ifc_len = sizeof (buf); - ifc.ifc_req = (struct ifreq *) buf; - ioctl (sockfd, SIOCGIFCONF, &ifc); - - for (ptr = buf; ptr < buf + ifc.ifc_len;) { - ifr = (struct ifreq *) ptr; - len = sizeof (struct sockaddr); -#ifdef HAVE_SOCKADDR_SA_LEN - if (ifr->ifr_addr.sa_len > len) - len = ifr->ifr_addr.sa_len; /* length > 16 */ -#endif - ptr += sizeof (ifr->ifr_name) + len; /* for next one in buffer */ + case AF_INET6: + + ip = info_ip6_construct_address (ifr6); + + model = gtk_tree_view_get_model ( + GTK_TREE_VIEW (info->list_ip_addr)); + + gtk_list_store_append (GTK_LIST_STORE (model), &iter); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + 0, g_strdup (ip->ip_addr), + 1, g_strdup (ip->ip_prefix), + 2, g_strdup (ip->ip_bcast), + 3, g_strdup (ip->ip_scope), + -1); - if (strcmp (ifr->ifr_name, nic) != 0) { - continue; - } - - data = mii_get_basic (nic); - - switch (ifr->ifr_addr.sa_family) { - case AF_INET: - - /* Get the IPv4 address */ - sinptr = (struct sockaddr_in *) &ifr->ifr_addr; - inet_ntop (AF_INET, &sinptr->sin_addr, dst, INFO_ADDRSTRLEN); - - gtk_label_set_text (GTK_LABEL (info->ip_address), dst); - bzero (dst, INFO_ADDRSTRLEN); - - ifrcopy = *ifr; - flags = ifrcopy.ifr_flags; + g_free (ip); - /* Get the Hardware Address */ + break; + case AF_INET: + + /* Get the IPv4 address */ + ip = g_new0 (InfoIpAddr, 1); + + sinptr = (struct sockaddr_in *) ifr6->ifa_addr; + inet_ntop (AF_INET, &sinptr->sin_addr, dst, INFO_ADDRSTRLEN); + + /*gtk_label_set_text (GTK_LABEL (info->ip_address), dst);*/ + ip->ip_addr = g_strdup (dst); + bzero (dst, INFO_ADDRSTRLEN); + + sockfd = socket (AF_INET, SOCK_DGRAM, 0); + ifc.ifc_len = sizeof (buf); + ifc.ifc_req = (struct ifreq *) buf; + ioctl (sockfd, SIOCGIFCONF, &ifc); + + data = mii_get_basic (nic); + + for (ptr = buf; ptr < buf + ifc.ifc_len;) { + ifr = (struct ifreq *) ptr; + len = sizeof (struct sockaddr); +#ifdef HAVE_SOCKADDR_SA_LEN + if (ifr->ifr_addr.sa_len > len) + len = ifr->ifr_addr.sa_len; /* length > 16 */ +#endif + ptr += sizeof (ifr->ifr_name) + len; /* for next one in buffer */ + + if (strcmp (ifr->ifr_name, nic) == 0) { + break; + } + } + + ifrcopy = *ifr; + flags = ifrcopy.ifr_flags; + + /*Get the Hardware Address */ #ifdef SIOCGIFHWADDR - ioctl (sockfd, SIOCGIFHWADDR, &ifrcopy); - sinptr = - (struct sockaddr_in *) &ifrcopy.ifr_dstaddr; - g_sprintf (dst, "%02x:%02x:%02x:%02x:%02x:%02x", - (int) ((guchar *) &ifrcopy.ifr_hwaddr.sa_data)[0], - (int) ((guchar*) &ifrcopy.ifr_hwaddr.sa_data)[1], - (int) ((guchar *) &ifrcopy.ifr_hwaddr.sa_data)[2], - (int) ((guchar *) &ifrcopy.ifr_hwaddr.sa_data)[3], - (int) ((guchar *) &ifrcopy.ifr_hwaddr.sa_data)[4], - (int) ((guchar *) &ifrcopy.ifr_hwaddr.sa_data)[5]); + ioctl (sockfd, SIOCGIFHWADDR, &ifrcopy); + sinptr = + (struct sockaddr_in *) &ifrcopy.ifr_dstaddr; + g_sprintf (dst, "%02x:%02x:%02x:%02x:%02x:%02x", + (int) ((guchar *) &ifrcopy.ifr_hwaddr.sa_data)[0], + (int) ((guchar *) &ifrcopy.ifr_hwaddr.sa_data)[1], + (int) ((guchar *) &ifrcopy.ifr_hwaddr.sa_data)[2], + (int) ((guchar *) &ifrcopy.ifr_hwaddr.sa_data)[3], + (int) ((guchar *) &ifrcopy.ifr_hwaddr.sa_data)[4], + (int) ((guchar *) &ifrcopy.ifr_hwaddr.sa_data)[5]); #else - g_sprintf (dst, NOT_AVAILABLE); + g_sprintf (dst, NOT_AVAILABLE); #endif /* SIOCGIFHWADDR */ - gtk_label_set_text (GTK_LABEL (info->hw_address), dst); + gtk_label_set_text (GTK_LABEL (info->hw_address), dst); - /* Get the netMask address */ + /* Get the netMask address */ #ifdef SIOCGIFNETMASK - ioctl (sockfd, SIOCGIFNETMASK, &ifrcopy); - - sinptr = (struct sockaddr_in *) &ifrcopy.ifr_addr; - + ioctl (sockfd, SIOCGIFNETMASK, &ifrcopy); + + sinptr = (struct sockaddr_in *) &ifrcopy.ifr_addr; + /* sinptr = (struct sockaddr_in *) &ifrcopy.ifr_netmask;*/ - inet_ntop (AF_INET, &sinptr->sin_addr, dst, INFO_ADDRSTRLEN); + inet_ntop (AF_INET, &sinptr->sin_addr, dst, INFO_ADDRSTRLEN); #else - g_sprintf (dst, NOT_AVAILABLE); + g_sprintf (dst, NOT_AVAILABLE); #endif /* SIOCGIFNETMASK */ - gtk_label_set_text (GTK_LABEL (info->netmask), dst); - bzero (dst, INFO_ADDRSTRLEN); + /*gtk_label_set_text (GTK_LABEL (info->netmask), dst);*/ + ip->ip_prefix = g_strdup (dst); + bzero (dst, INFO_ADDRSTRLEN); - /* Get the broadcast address */ - ioctl (sockfd, SIOCGIFBRDADDR, &ifrcopy); - sinptr = (struct sockaddr_in *) &ifrcopy.ifr_broadaddr; - inet_ntop (AF_INET, &sinptr->sin_addr, dst, INFO_ADDRSTRLEN); - gtk_label_set_text (GTK_LABEL (info->broadcast), dst); - bzero (dst, INFO_ADDRSTRLEN); + /* Get the broadcast address */ + ioctl (sockfd, SIOCGIFBRDADDR, &ifrcopy); + sinptr = (struct sockaddr_in *) &ifrcopy.ifr_broadaddr; + inet_ntop (AF_INET, &sinptr->sin_addr, dst, INFO_ADDRSTRLEN); + /*gtk_label_set_text (GTK_LABEL (info->broadcast), dst);*/ + ip->ip_bcast = g_strdup (dst); + bzero (dst, INFO_ADDRSTRLEN); - /* Get the MTU */ - ioctl (sockfd, SIOCGIFMTU, &ifrcopy); - g_sprintf (dst, "%d", ifrcopy.ifr_mtu); - gtk_label_set_text (GTK_LABEL (info->mtu), dst); - bzero (dst, INFO_ADDRSTRLEN); - - /* Get Flags to determine other properties */ - ioctl (sockfd, SIOCGIFFLAGS, &ifrcopy); - flags = ifrcopy.ifr_flags; - - /* Interface is up */ - if (flags & IFF_UP) { - gtk_label_set_text (GTK_LABEL (info->state), _("Active")); - } else { - gtk_label_set_text (GTK_LABEL (info->state), _("Inactive")); - } - - /* Is a loopback device */ - if ((flags & IFF_LOOPBACK)) { - gtk_label_set_text (GTK_LABEL (info->hw_address), _("Loopback")); - gtk_label_set_text (GTK_LABEL (info->broadcast), " "); - gtk_label_set_text (GTK_LABEL (info->link_speed), " "); - } else { - if (data.has_data) { - gtk_label_set_text (GTK_LABEL (info->link_speed), data.media); - } else { - gtk_label_set_text (GTK_LABEL (info->link_speed), NOT_AVAILABLE); - } - } + /* Get the MTU */ + ioctl (sockfd, SIOCGIFMTU, &ifrcopy); + g_sprintf (dst, "%d", ifrcopy.ifr_mtu); + gtk_label_set_text (GTK_LABEL (info->mtu), dst); + bzero (dst, INFO_ADDRSTRLEN); + + /* Get Flags to determine other properties */ + ioctl (sockfd, SIOCGIFFLAGS, &ifrcopy); + flags = ifrcopy.ifr_flags; + + /* Interface is up */ + if (flags & IFF_UP) { + gtk_label_set_text (GTK_LABEL (info->state), _("Active")); + } else { + gtk_label_set_text (GTK_LABEL (info->state), _("Inactive")); + } + + /* Is a loopback device */ + if ((flags & IFF_LOOPBACK)) { + gtk_label_set_text (GTK_LABEL (info->hw_address), _("Loopback")); + /*gtk_label_set_text (GTK_LABEL (info->broadcast), " ");*/ + ip->ip_bcast = g_strdup (""); + gtk_label_set_text (GTK_LABEL (info->link_speed), " "); + } else { + if (data.has_data) { + gtk_label_set_text (GTK_LABEL (info->link_speed), data.media); + } else { + gtk_label_set_text (GTK_LABEL (info->link_speed), NOT_AVAILABLE); + } + } - /* Supports multicast */ - if (flags & IFF_MULTICAST) { - gtk_label_set_text (GTK_LABEL (info->multicast), _("Enabled")); - } else { - gtk_label_set_text (GTK_LABEL (info->multicast), _("Disabled")); - } - - /* Interface is a point to point link */ - if (flags & IFF_POINTOPOINT) { - ioctl (sockfd, SIOCGIFDSTADDR, &ifrcopy); - sinptr = (struct sockaddr_in *) &ifrcopy.ifr_dstaddr; - - printf ("\tP-t-P: %s\n", - inet_ntop (AF_INET, - &sinptr->sin_addr, dst, - INFO_ADDRSTRLEN)); - } - bzero (dst, INFO_ADDRSTRLEN); - - break; + /* Supports multicast */ + if (flags & IFF_MULTICAST) { + gtk_label_set_text (GTK_LABEL (info->multicast), _("Enabled")); + } else { + gtk_label_set_text (GTK_LABEL (info->multicast), _("Disabled")); + } + + /* Interface is a point to point link */ + if (flags & IFF_POINTOPOINT) { + ioctl (sockfd, SIOCGIFDSTADDR, &ifrcopy); + sinptr = (struct sockaddr_in *) &ifrcopy.ifr_dstaddr; + + printf ("\tP-t-P: %s\n", + inet_ntop (AF_INET, + &sinptr->sin_addr, dst, + INFO_ADDRSTRLEN)); + } + bzero (dst, INFO_ADDRSTRLEN); + + model = gtk_tree_view_get_model ( + GTK_TREE_VIEW (info->list_ip_addr)); + + gtk_list_store_append (GTK_LIST_STORE (model), &iter); + gtk_list_store_set (GTK_LIST_STORE (model), &iter, + 0, g_strdup (ip->ip_addr), + 1, g_strdup (ip->ip_prefix), + 2, g_strdup (ip->ip_bcast), + 3, g_strdup (""), + -1); + g_free (ip); + + break; + + default: + gtk_label_set_text (GTK_LABEL (info->hw_address), NOT_AVAILABLE); + /*gtk_label_set_text (GTK_LABEL (info->ip_address), NOT_AVAILABLE); + gtk_label_set_text (GT K_LABEL (info->broadcast), NOT_AVAILABLE); + gtk_label_set_text (GTK_LABEL (info->netmask), NOT_AVAILABLE); + gtk_label_set_text (GTK_LABEL (info->dst_address), NOT_AVAILABLE);*/ + gtk_label_set_text (GTK_LABEL (info->mtu), NOT_AVAILABLE); + gtk_label_set_text (GTK_LABEL (info->state), NOT_AVAILABLE); + gtk_label_set_text (GTK_LABEL (info->multicast), NOT_AVAILABLE); + + if (data.has_data) { + gtk_label_set_text (GTK_LABEL (info->link_speed), data.media); + } else { + gtk_label_set_text (GTK_LABEL (info->link_speed), NOT_AVAILABLE); + } + break; + } + } + g_free (ifr); +} - default: - gtk_label_set_text (GTK_LABEL (info->hw_address), NOT_AVAILABLE); - gtk_label_set_text (GTK_LABEL (info->ip_address), NOT_AVAILABLE); - gtk_label_set_text (GTK_LABEL (info->broadcast), NOT_AVAILABLE); - gtk_label_set_text (GTK_LABEL (info->netmask), NOT_AVAILABLE); - /*gtk_label_set_text (GTK_LABEL (info->dst_address), NOT_AVAILABLE);*/ - gtk_label_set_text (GTK_LABEL (info->mtu), NOT_AVAILABLE); - gtk_label_set_text (GTK_LABEL (info->state), NOT_AVAILABLE); - gtk_label_set_text (GTK_LABEL (info->multicast), NOT_AVAILABLE); - - if (data.has_data) { - gtk_label_set_text (GTK_LABEL (info->link_speed), data.media); - } else { - gtk_label_set_text (GTK_LABEL (info->link_speed), NOT_AVAILABLE); - } - break; - } - } - g_free (ifr); +static gint * +compare (gconstpointer a, gconstpointer b) +{ + return (GINT_TO_POINTER (strcmp (a, b))); } GList * @@ -330,39 +520,20 @@ { GList *items = NULL; gchar *iface; - gchar *ptr, buf[2048]; - struct sockaddr_in *sinptr; - struct ifconf ifc; - struct ifreq *ifr; - int sockfd, len; - - sockfd = socket (AF_INET, SOCK_DGRAM, 0); + struct ifaddrs *ifa0, *ifr; - ifc.ifc_len = sizeof (buf); - ifc.ifc_req = (struct ifreq *) buf; + getifaddrs (&ifa0); - ioctl (sockfd, SIOCGIFCONF, &ifc); + for (ifr = ifa0; ifr; ifr = ifr->ifa_next) { + iface = g_strdup (ifr->ifa_name); - for (ptr = buf; ptr < buf + ifc.ifc_len;) { - ifr = (struct ifreq *) ptr; - len = sizeof (struct sockaddr); - - iface = g_strdup (ifr->ifr_name); - items = g_list_append (items, iface); - -#ifdef HAVE_SOCKADDR_SA_LEN - if (ifr->ifr_addr.sa_len > len) - len = ifr->ifr_addr.sa_len; /* length > 16 */ -#endif - ptr += sizeof (ifr->ifr_name) + len; /* for next one in buffer */ + if (((ifr->ifa_flags & IFF_UP) != 0) && + (g_list_find_custom (items, iface, (GCompareFunc) compare) == NULL)) + items = g_list_append (items, iface); } return items; } - -/* -#endif -*/ /* Copy on clipboard */ void Index: info.h =================================================================== RCS file: /cvs/gnome/gnome-network/gnome-netinfo/info.h,v retrieving revision 1.8 diff -u -u -r1.8 info.h --- info.h 24 Jul 2003 17:21:11 -0000 1.8 +++ info.h 20 Oct 2003 21:41:56 -0000 @@ -33,6 +33,13 @@ # define ifr_mtu ifr_ifru.ifru_metric #endif +typedef struct { + gchar *ip_addr; + gchar *ip_prefix; + gchar *ip_bcast; + gchar *ip_scope; +} InfoIpAddr; + void info_do (const gchar * nic, Netinfo * info); void info_load_iface (Netinfo * info, GtkWidget * combo); Index: main.c =================================================================== RCS file: /cvs/gnome/gnome-network/gnome-netinfo/main.c,v retrieving revision 1.37 diff -u -u -r1.37 main.c --- main.c 25 Aug 2003 15:54:37 -0000 1.37 +++ main.c 20 Oct 2003 21:41:56 -0000 @@ -281,6 +281,7 @@ info->rx = glade_xml_get_widget (xml, "info_rx"); info->rx_errors = glade_xml_get_widget (xml, "info_rx_errors"); info->collisions = glade_xml_get_widget (xml, "info_collisions"); + info->list_ip_addr = glade_xml_get_widget (xml, "list_ip_addr"); vbox_info = glade_xml_get_widget (xml, "vbox_info"); Index: netinfo.h =================================================================== RCS file: /cvs/gnome/gnome-network/gnome-netinfo/netinfo.h,v retrieving revision 1.14 diff -u -u -r1.14 netinfo.h --- netinfo.h 2 Oct 2003 21:26:16 -0000 1.14 +++ netinfo.h 20 Oct 2003 21:41:56 -0000 @@ -70,6 +70,7 @@ GtkWidget *broadcast; GtkWidget *netmask; GtkWidget *dst_address; + GtkWidget *list_ip_addr; /*GtkWidget *multicast;*/ GtkWidget *link_speed; GtkWidget *state; Index: netstat.c =================================================================== RCS file: /cvs/gnome/gnome-network/gnome-netinfo/netstat.c,v retrieving revision 1.10 diff -u -u -r1.10 netstat.c --- netstat.c 31 Aug 2003 16:18:24 -0000 1.10 +++ netstat.c 20 Oct 2003 21:41:56 -0000 @@ -105,11 +105,11 @@ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (netinfo->routing))) { /* Works for Solaris and Linux */ - option = g_strdup ("-r"); + option = g_strdup ("-rn -A inet -A inet6"); } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (netinfo->protocol))) { /* Only works for Solaris */ - option = g_strdup ("-A inet -ln"); + option = g_strdup ("-A inet -A inet6 -ln"); } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (netinfo->multicast))) { /* It works for Solaris and Linux */ @@ -270,7 +270,7 @@ g_return_if_fail (line != NULL); count = strip_protocol_line (line, &data); - if (count == 7 || count == 8) { + if (count == 5 || count == 6) { #ifdef DEBUG g_print ("%s\t%s:%s\t%s\n", data.protocol, data.ip_src, data.port_src, data.state); @@ -335,17 +335,24 @@ strip_protocol_line (gchar * line, netstat_protocol_data *data) { gint count = 0; - gchar s6[30], s7[30]; + gchar s6[50], laddr[50]; gint n2, n3; - - line = g_strdelimit (line, ":", ' '); + gchar *port; count = sscanf (line, NETSTAT_PROTOCOL_FORMAT, - &(data)->protocol, &n2, &n3, - &(data)->ip_src, &(data)->port_src, - s6, s7, &(data)->state); + &(data)->protocol, &n2, &n3, + laddr, s6, &(data)->state); + + port = g_strrstr (laddr, ":"); + if (port != NULL) { + g_strlcpy (data->ip_src, laddr, 50 * sizeof (gchar)); + data->ip_src[strlen (laddr) - strlen (port)] = '\0'; + port ++; + g_strlcpy (data->port_src, port, 30 * sizeof (gchar)); + } - if (count == 7) { + + if (count == 5) { bzero (&(data)->state, 30); } @@ -409,7 +416,8 @@ g_return_if_fail (line != NULL); count = strip_route_line (line, &data); - if (count == 8) { + + if ((count == 8) || (count == 7)) { #ifdef DEBUG g_print ("%s\t%s:%s\t%d\t%s\n", data.destination, data.gateway, data.netmask, data.metric, @@ -477,13 +485,30 @@ gint count = 0; gchar flags[30]; gint ref, use; + gchar dest[50]; + gchar **items; count = sscanf (line, NETSTAT_ROUTE_FORMAT, &(data)->destination, &(data)->gateway, &(data)->netmask, flags, &(data)->metric, &ref, &use, &(data)->iface); - + + if (count == 6) { + count = sscanf (line, NETSTAT_ROUTE6_FORMAT, + dest, &(data)->netmask, + flags, &(data)->metric, + &ref, &use, &(data)->iface); + + items = g_strsplit (dest, "/", 2); + if (items != NULL) { + g_strlcpy (data->destination, items[0], 50 * sizeof (gchar)); + g_strlcpy (data->netmask, items[1], 50 * sizeof (gchar)); + + g_strfreev (items); + } + } + return count; } Index: netstat.h =================================================================== RCS file: /cvs/gnome/gnome-network/gnome-netinfo/netstat.h,v retrieving revision 1.4 diff -u -u -r1.4 netstat.h --- netstat.h 21 Jul 2003 02:31:57 -0000 1.4 +++ netstat.h 20 Oct 2003 21:41:56 -0000 @@ -25,8 +25,9 @@ #if defined(__linux__) /* proto 0 0 ip port ip port state */ -# define NETSTAT_PROTOCOL_FORMAT "%s %d %d %s %s %s %s %s" -# define NETSTAT_ROUTE_FORMAT "%s %s %s %s %d %d %d %s" +# define NETSTAT_PROTOCOL_FORMAT "%s %d %d %s %s %s" +# define NETSTAT_ROUTE_FORMAT "%s %s %s %s %d %d %d %s" +# define NETSTAT_ROUTE6_FORMAT "%s %s %s %d %d %d %s" # define NETSTAT_MULTICAST_FORMAT "%s %d %s" #endif @@ -42,7 +43,7 @@ struct _netstat_protocol_data { gchar protocol[30]; - gchar ip_src[30]; + gchar ip_src[50]; gchar port_src[30]; // gint port_src; gchar state[30]; @@ -51,8 +52,8 @@ typedef struct _netstat_route_data netstat_route_data; struct _netstat_route_data { - gchar destination[30]; - gchar gateway[30]; + gchar destination[50]; + gchar gateway[50]; gchar netmask[30]; gint metric; gchar iface[30];
Attachment:
signature.asc
Description: Esta parte del mensaje =?ISO-8859-1?Q?est=E1?= firmada digitalmente