El lun, 15-12-2003 a las 19:18, William Jon McCann escribió: > Hi, > > I don't have IPv6 so I can't verify that it works. However, this patch > produces a warning on my system. It can be traced to: > > % netstat -rn -A inet6 > /proc/net/ipv6_route: No such file or directory > INET6 (IPv6) not configured in this system. > % echo $status > 1 > > Quite possibly this is a linux netstat bug since a similar command on > Solaris does not give a warning and a bad exit code. I'll try to follow > up on that. However, for now we should probably not be producing this > warning for the vast majority of users. Perhaps we can do a test to see > if IPv6 is enabled and only use it if it is? I have added a function that check if IPv6 is enabled in the system and only uses -A inet6 when it is possible. I have attached an updated patch. > Other than that please remove the lines you changed instead of > commenting them out. ought, I forgot it :-P > Thanks, > Jon > > Carlos Garcia Campos wrote: > > Hi all, > > > > Two months ago I sent a patch that added IPv6 support for netstat tool. > > Germán approved it but I forgot to apply it :-P so I send now again the > > patch, but updated for the current CVS. > > The patch also fixes a minor bug: the tree_model doesn't change when you > > toggle between protocol and route twice > > > > > > > > > > ------------------------------------------------------------------------ > > > > Index: netstat.c > > =================================================================== > > RCS file: /cvs/gnome/gnome-network/gnome-netinfo/netstat.c,v > > retrieving revision 1.11 > > diff -u -u -r1.11 netstat.c > > --- netstat.c 20 Nov 2003 21:12:43 -0000 1.11 > > +++ netstat.c 9 Dec 2003 17:54:20 -0000 > > @@ -109,11 +109,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 */ > > @@ -266,10 +266,10 @@ > > 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); > > + data.ip_src, data.port_src, data.state); > > #endif /* DEBUG */ > > > > /* Creation of GtkTreeView */ > > @@ -284,41 +284,43 @@ > > > > model = gtk_tree_view_get_model (widget); > > > > - if (protocol_model == NULL || gtk_tree_model_get_n_columns (model) != 4) { > > + /*if (protocol_model == NULL || gtk_tree_model_get_n_columns (model) != 4) {*/ > > + if (protocol_model == NULL || protocol_model != model) { > > clean_gtk_tree_view (widget); > > > > protocol_model = GTK_TREE_MODEL (gtk_list_store_new > > - (4, > > - G_TYPE_STRING, > > - G_TYPE_STRING, > > - G_TYPE_STRING, > > - G_TYPE_STRING)); > > + (4, > > + G_TYPE_STRING, > > + G_TYPE_STRING, > > + G_TYPE_STRING, > > + G_TYPE_STRING)); > > netstat_create_protocol_model (widget); > > > > - gtk_tree_view_set_model (widget, protocol_model); > > + /*gtk_tree_view_set_model (widget, protocol_model);*/ > > } > > - > > + gtk_tree_view_set_model (widget, protocol_model); > > + > > model = gtk_tree_view_get_model (widget); > > > > gtk_tree_view_get_cursor (widget, &path, NULL); > > - > > + > > if (path != NULL) { > > gtk_tree_model_get_iter (model, &sibling, path); > > gtk_list_store_insert_after (GTK_LIST_STORE > > - (model), > > - &iter, > > - &sibling); > > + (model), > > + &iter, > > + &sibling); > > } else { > > gtk_list_store_append (GTK_LIST_STORE > > - (model), &iter); > > + (model), &iter); > > } > > > > gtk_list_store_set (GTK_LIST_STORE (model), &iter, > > - 0, data.protocol, > > - 1, data.ip_src, > > - 2, data.port_src, > > - 3, data.state, -1); > > - > > + 0, data.protocol, > > + 1, data.ip_src, > > + 2, data.port_src, > > + 3, data.state, -1); > > + > > gtk_tree_view_set_model (widget, model); > > path = gtk_tree_model_get_path (model, &iter); > > gtk_tree_view_set_cursor (widget, path, NULL, FALSE); > > @@ -331,17 +333,24 @@ > > strip_protocol_line (gchar * line, netstat_protocol_data *data) > > { > > gint count = 0; > > - gchar s6[30], s7[30]; > > + gchar s6[30], 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); > > + laddr, s6, data->state); > > + > > + port = g_strrstr (laddr, ":"); > > > > - if (count == 7) { > > + 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 == 5) { > > bzero (&(data)->state, 30); > > } > > > > @@ -359,31 +368,31 @@ > > renderer = gtk_cell_renderer_text_new (); > > /* Transport Protocol that runs over */ > > column = > > - gtk_tree_view_column_new_with_attributes > > - (_("Protocol"), renderer, "text", 0, NULL); > > + gtk_tree_view_column_new_with_attributes > > + (_("Protocol"), renderer, "text", 0, NULL); > > gtk_tree_view_append_column (widget, column); > > > > renderer = gtk_cell_renderer_text_new (); > > /* IP address where to accept connections */ > > column = > > - gtk_tree_view_column_new_with_attributes > > - (_("IP Source"), renderer, "text", 1, NULL); > > + gtk_tree_view_column_new_with_attributes > > + (_("IP Source"), renderer, "text", 1, NULL); > > gtk_tree_view_column_set_alignment (column, 0.5); > > gtk_tree_view_append_column (widget, column); > > > > renderer = gtk_cell_renderer_text_new (); > > /* Number of port where the service is listening */ > > column = > > - gtk_tree_view_column_new_with_attributes > > - (_("Port/Service"), renderer, "text", 2, NULL); > > + gtk_tree_view_column_new_with_attributes > > + (_("Port/Service"), renderer, "text", 2, NULL); > > g_object_set (G_OBJECT (renderer), "xalign", 1.0, NULL); > > gtk_tree_view_append_column (widget, column); > > > > renderer = gtk_cell_renderer_text_new (); > > /* State of the service (commonly LISTEN) */ > > column = > > - gtk_tree_view_column_new_with_attributes > > - (_("State"), renderer, "text", 3, NULL); > > + gtk_tree_view_column_new_with_attributes > > + (_("State"), renderer, "text", 3, NULL); > > gtk_tree_view_append_column (widget, column); > > > > /* return model;*/ > > @@ -403,13 +412,13 @@ > > > > g_return_if_fail (GTK_IS_TREE_VIEW (widget)); > > 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, > > - data.iface); > > + data.gateway, data.netmask, data.metric, > > + data.iface); > > #endif /* DEBUG */ > > > > /* Creation of GtkTreeView */ > > @@ -424,19 +433,21 @@ > > > > model = gtk_tree_view_get_model (widget); > > > > - if (route_model == NULL || gtk_tree_model_get_n_columns (model) != 4) { > > + /*if (route_model == NULL || gtk_tree_model_get_n_columns (model) != 4) {*/ > > + if (route_model == NULL || route_model != model) { > > clean_gtk_tree_view (widget); > > > > route_model = GTK_TREE_MODEL (gtk_list_store_new > > - (4, > > - G_TYPE_STRING, > > - G_TYPE_STRING, > > - G_TYPE_STRING, > > - G_TYPE_STRING)); > > + (4, > > + G_TYPE_STRING, > > + G_TYPE_STRING, > > + G_TYPE_STRING, > > + G_TYPE_STRING)); > > netstat_create_route_model (widget); > > > > - gtk_tree_view_set_model (widget, route_model); > > + /*gtk_tree_view_set_model (widget, route_model);*/ > > } > > + gtk_tree_view_set_model (widget, route_model); > > > > model = gtk_tree_view_get_model (widget); > > > > @@ -473,13 +484,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->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; > > } > > > > @@ -492,28 +520,28 @@ > > > > renderer = gtk_cell_renderer_text_new (); > > column = > > - gtk_tree_view_column_new_with_attributes > > - (_("Destination"), renderer, "text", 0, NULL); > > + gtk_tree_view_column_new_with_attributes > > + (_("Destination"), renderer, "text", 0, NULL); > > gtk_tree_view_append_column (widget, column); > > - > > + > > renderer = gtk_cell_renderer_text_new (); > > column = > > - gtk_tree_view_column_new_with_attributes > > - (_("Gateway"), renderer, "text", 1, NULL); > > + gtk_tree_view_column_new_with_attributes > > + (_("Gateway"), renderer, "text", 1, NULL); > > gtk_tree_view_column_set_alignment (column, 0.5); > > gtk_tree_view_append_column (widget, column); > > - > > + > > renderer = gtk_cell_renderer_text_new (); > > column = > > - gtk_tree_view_column_new_with_attributes > > - (_("Netmask"), renderer, "text", 2, NULL); > > + gtk_tree_view_column_new_with_attributes > > + (_("Netmask"), renderer, "text", 2, NULL); > > > > gtk_tree_view_append_column (widget, column); > > - > > + > > renderer = gtk_cell_renderer_text_new (); > > column = > > - gtk_tree_view_column_new_with_attributes > > - (_("Interface"), renderer, "text", 3, NULL); > > + gtk_tree_view_column_new_with_attributes > > + (_("Interface"), renderer, "text", 3, NULL); > > gtk_tree_view_append_column (widget, column); > > } > > /* END ROUTE */ > > @@ -551,7 +579,8 @@ > > > > model = gtk_tree_view_get_model (widget); > > > > - if (multicast_model == NULL || gtk_tree_model_get_n_columns (model) != 3) { > > + /*if (multicast_model == NULL || gtk_tree_model_get_n_columns (model) != 3) {*/ > > + if (multicast_model == NULL || multicast_model != model) { > > clean_gtk_tree_view (widget); > > > > multicast_model = GTK_TREE_MODEL (gtk_list_store_new > > @@ -561,8 +590,9 @@ > > G_TYPE_STRING)); > > netstat_create_multicast_model (widget); > > > > - gtk_tree_view_set_model (widget, multicast_model); > > + /*gtk_tree_view_set_model (widget, multicast_model);*/ > > } > > + gtk_tree_view_set_model (widget, multicast_model); > > > > model = gtk_tree_view_get_model (widget); > > > > @@ -618,23 +648,23 @@ > > renderer = gtk_cell_renderer_text_new (); > > /* Interface of multicast group associated */ > > column = > > - gtk_tree_view_column_new_with_attributes > > - (_("Interface"), renderer, "text", 0, NULL); > > + gtk_tree_view_column_new_with_attributes > > + (_("Interface"), renderer, "text", 0, NULL); > > gtk_tree_view_append_column (widget, column); > > > > renderer = gtk_cell_renderer_text_new (); > > /* Members of multicast group */ > > column = > > - gtk_tree_view_column_new_with_attributes > > - (_("Member"), renderer, "text", 1, NULL); > > + gtk_tree_view_column_new_with_attributes > > + (_("Member"), renderer, "text", 1, NULL); > > g_object_set (G_OBJECT (renderer), "xalign", 0.5, NULL); > > gtk_tree_view_append_column (widget, column); > > - > > + > > renderer = gtk_cell_renderer_text_new (); > > /* Multicast group */ > > column = > > - gtk_tree_view_column_new_with_attributes > > - (_("Group"), renderer, "text", 2, NULL); > > + gtk_tree_view_column_new_with_attributes > > + (_("Group"), renderer, "text", 2, NULL); > > gtk_tree_view_append_column (widget, column); > > } > > /* END MULTICAST */ > > @@ -657,7 +687,7 @@ > > column = gtk_tree_view_get_column (widget, i-1); > > gtk_tree_view_remove_column (widget, column); > > } > > - > > + > > g_list_free (columns); > > } > > > > 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 9 Dec 2003 17:54:20 -0000 > > @@ -25,9 +25,13 @@ > > > > #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_PROTOCOL_FORMAT "%s %d %d %s %s %s %s %s" > > # define NETSTAT_ROUTE_FORMAT "%s %s %s %s %d %d %d %s" > > -# define NETSTAT_MULTICAST_FORMAT "%s %d %s" > > +# define NETSTAT_MULTICAST_FORMAT "%s %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 +46,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 +55,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]; > > Index: ChangeLog > > =================================================================== > > RCS file: /cvs/gnome/gnome-network/gnome-netinfo/ChangeLog,v > > retrieving revision 1.102 > > diff -u -u -r1.102 ChangeLog > > --- ChangeLog 5 Dec 2003 02:27:22 -0000 1.102 > > +++ ChangeLog 9 Dec 2003 17:54:25 -0000 > > @@ -1,3 +1,17 @@ > > +2003-12-09 Carlos García Campos <carlosgc gnome org> > > + > > + * netstat.c (get_active_option, strip_protocol_line, > > + strip_route_line, *_tree_insert): IPv6 support > > + > > + * netstat.c (*_tree_insert): the tree_model doesn't change when > > + you toggle between protocol and route twice > > + > > 2003-12-01 Bastien Nocera <hadess hadess net> > > > > * main.c: (load_whois_widgets_from_xml): we don't have a "user" > > _______________________________________________ > gnome-network-list mailing list > gnome-network-list gnome org > http://mail.gnome.org/mailman/listinfo/gnome-network-list -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= 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.103 diff -u -u -r1.103 ChangeLog --- ChangeLog 15 Dec 2003 19:15:23 -0000 1.103 +++ ChangeLog 15 Dec 2003 22:25:57 -0000 @@ -1,5 +1,12 @@ 2003-12-15 Carlos García Campos <carlosgc gnome org> + * netinfo.[ch] (is_ipv6_enable): added is_ipv6_enable function to know if + IPv6 is enabled in the system + * netstat.[ch] (get_active_option): checks if IPv6 is enabled before use + inet6 protocol + +2003-12-15 Carlos García Campos <carlosgc gnome org> + * info.c (info_get_nic_information): removed invalid g_free() 2003-12-01 Bastien Nocera <hadess hadess net> Index: netinfo.c =================================================================== RCS file: /cvs/gnome/gnome-network/gnome-netinfo/netinfo.c,v retrieving revision 1.17 diff -u -u -r1.17 netinfo.c --- netinfo.c 20 Nov 2003 21:12:43 -0000 1.17 +++ netinfo.c 15 Dec 2003 22:25:57 -0000 @@ -74,6 +74,18 @@ (GNOME_ENTRY (netinfo->user)))); } +gboolean +netinfo_is_ipv6_enable () +{ + struct hostent *host; + + if ((host = gethostbyname2 ("::", AF_INET6)) != NULL) { + return TRUE; + } else { + return FALSE; + } +} + gint netinfo_get_ip_version (Netinfo * netinfo) { Index: netinfo.h =================================================================== RCS file: /cvs/gnome/gnome-network/gnome-netinfo/netinfo.h,v retrieving revision 1.16 diff -u -u -r1.16 netinfo.h --- netinfo.h 19 Nov 2003 16:19:10 -0000 1.16 +++ netinfo.h 15 Dec 2003 22:25:57 -0000 @@ -117,6 +117,7 @@ gushort netinfo_get_count (Netinfo * netinfo); const gchar * netinfo_get_host (Netinfo * netinfo); const gchar * netinfo_get_user (Netinfo * netinfo); +gboolean netinfo_is_ipv6_enable (); gint netinfo_get_ip_version (Netinfo * netinfo); gboolean netinfo_validate_host (Netinfo * netinfo); void netinfo_toggle_button (Netinfo * netinfo); Index: netstat.c =================================================================== RCS file: /cvs/gnome/gnome-network/gnome-netinfo/netstat.c,v retrieving revision 1.11 diff -u -u -r1.11 netstat.c --- netstat.c 20 Nov 2003 21:12:43 -0000 1.11 +++ netstat.c 15 Dec 2003 22:25:57 -0000 @@ -109,11 +109,19 @@ if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (netinfo->routing))) { /* Works for Solaris and Linux */ - option = g_strdup ("-r"); + if (netinfo_is_ipv6_enable ()) { + option = g_strdup ("-rn -A inet -A inet6"); + } else { + option = g_strdup ("-rn -A inet"); + } } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (netinfo->protocol))) { /* Only works for Solaris */ - option = g_strdup ("-A inet -ln"); + if (netinfo_is_ipv6_enable ()) { + option = g_strdup ("-A inet -A inet6 -ln"); + } else { + option = g_strdup ("-A inet -ln"); + } } if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (netinfo->multicast))) { /* It works for Solaris and Linux */ @@ -266,10 +274,10 @@ 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); + data.ip_src, data.port_src, data.state); #endif /* DEBUG */ /* Creation of GtkTreeView */ @@ -284,41 +292,40 @@ model = gtk_tree_view_get_model (widget); - if (protocol_model == NULL || gtk_tree_model_get_n_columns (model) != 4) { + if (protocol_model == NULL || protocol_model != model) { clean_gtk_tree_view (widget); protocol_model = GTK_TREE_MODEL (gtk_list_store_new - (4, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING)); + (4, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING)); netstat_create_protocol_model (widget); - - gtk_tree_view_set_model (widget, protocol_model); } - + gtk_tree_view_set_model (widget, protocol_model); + model = gtk_tree_view_get_model (widget); gtk_tree_view_get_cursor (widget, &path, NULL); - + if (path != NULL) { gtk_tree_model_get_iter (model, &sibling, path); gtk_list_store_insert_after (GTK_LIST_STORE - (model), - &iter, - &sibling); + (model), + &iter, + &sibling); } else { gtk_list_store_append (GTK_LIST_STORE - (model), &iter); + (model), &iter); } gtk_list_store_set (GTK_LIST_STORE (model), &iter, - 0, data.protocol, - 1, data.ip_src, - 2, data.port_src, - 3, data.state, -1); - + 0, data.protocol, + 1, data.ip_src, + 2, data.port_src, + 3, data.state, -1); + gtk_tree_view_set_model (widget, model); path = gtk_tree_model_get_path (model, &iter); gtk_tree_view_set_cursor (widget, path, NULL, FALSE); @@ -331,17 +338,24 @@ strip_protocol_line (gchar * line, netstat_protocol_data *data) { gint count = 0; - gchar s6[30], s7[30]; + gchar s6[30], 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); + laddr, s6, data->state); - if (count == 7) { + 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 == 5) { bzero (&(data)->state, 30); } @@ -359,31 +373,31 @@ renderer = gtk_cell_renderer_text_new (); /* Transport Protocol that runs over */ column = - gtk_tree_view_column_new_with_attributes - (_("Protocol"), renderer, "text", 0, NULL); + gtk_tree_view_column_new_with_attributes + (_("Protocol"), renderer, "text", 0, NULL); gtk_tree_view_append_column (widget, column); renderer = gtk_cell_renderer_text_new (); /* IP address where to accept connections */ column = - gtk_tree_view_column_new_with_attributes - (_("IP Source"), renderer, "text", 1, NULL); + gtk_tree_view_column_new_with_attributes + (_("IP Source"), renderer, "text", 1, NULL); gtk_tree_view_column_set_alignment (column, 0.5); gtk_tree_view_append_column (widget, column); renderer = gtk_cell_renderer_text_new (); /* Number of port where the service is listening */ column = - gtk_tree_view_column_new_with_attributes - (_("Port/Service"), renderer, "text", 2, NULL); + gtk_tree_view_column_new_with_attributes + (_("Port/Service"), renderer, "text", 2, NULL); g_object_set (G_OBJECT (renderer), "xalign", 1.0, NULL); gtk_tree_view_append_column (widget, column); renderer = gtk_cell_renderer_text_new (); /* State of the service (commonly LISTEN) */ column = - gtk_tree_view_column_new_with_attributes - (_("State"), renderer, "text", 3, NULL); + gtk_tree_view_column_new_with_attributes + (_("State"), renderer, "text", 3, NULL); gtk_tree_view_append_column (widget, column); /* return model;*/ @@ -403,13 +417,13 @@ g_return_if_fail (GTK_IS_TREE_VIEW (widget)); 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, - data.iface); + data.gateway, data.netmask, data.metric, + data.iface); #endif /* DEBUG */ /* Creation of GtkTreeView */ @@ -424,19 +438,18 @@ model = gtk_tree_view_get_model (widget); - if (route_model == NULL || gtk_tree_model_get_n_columns (model) != 4) { + if (route_model == NULL || route_model != model) { clean_gtk_tree_view (widget); route_model = GTK_TREE_MODEL (gtk_list_store_new - (4, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING, - G_TYPE_STRING)); + (4, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING)); netstat_create_route_model (widget); - - gtk_tree_view_set_model (widget, route_model); } + gtk_tree_view_set_model (widget, route_model); model = gtk_tree_view_get_model (widget); @@ -473,13 +486,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->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; } @@ -492,28 +522,28 @@ renderer = gtk_cell_renderer_text_new (); column = - gtk_tree_view_column_new_with_attributes - (_("Destination"), renderer, "text", 0, NULL); + gtk_tree_view_column_new_with_attributes + (_("Destination"), renderer, "text", 0, NULL); gtk_tree_view_append_column (widget, column); - + renderer = gtk_cell_renderer_text_new (); column = - gtk_tree_view_column_new_with_attributes - (_("Gateway"), renderer, "text", 1, NULL); + gtk_tree_view_column_new_with_attributes + (_("Gateway"), renderer, "text", 1, NULL); gtk_tree_view_column_set_alignment (column, 0.5); gtk_tree_view_append_column (widget, column); - + renderer = gtk_cell_renderer_text_new (); column = - gtk_tree_view_column_new_with_attributes - (_("Netmask"), renderer, "text", 2, NULL); + gtk_tree_view_column_new_with_attributes + (_("Netmask"), renderer, "text", 2, NULL); gtk_tree_view_append_column (widget, column); - + renderer = gtk_cell_renderer_text_new (); column = - gtk_tree_view_column_new_with_attributes - (_("Interface"), renderer, "text", 3, NULL); + gtk_tree_view_column_new_with_attributes + (_("Interface"), renderer, "text", 3, NULL); gtk_tree_view_append_column (widget, column); } /* END ROUTE */ @@ -551,7 +581,7 @@ model = gtk_tree_view_get_model (widget); - if (multicast_model == NULL || gtk_tree_model_get_n_columns (model) != 3) { + if (multicast_model == NULL || multicast_model != model) { clean_gtk_tree_view (widget); multicast_model = GTK_TREE_MODEL (gtk_list_store_new @@ -560,9 +590,8 @@ G_TYPE_STRING, G_TYPE_STRING)); netstat_create_multicast_model (widget); - - gtk_tree_view_set_model (widget, multicast_model); } + gtk_tree_view_set_model (widget, multicast_model); model = gtk_tree_view_get_model (widget); @@ -618,23 +647,23 @@ renderer = gtk_cell_renderer_text_new (); /* Interface of multicast group associated */ column = - gtk_tree_view_column_new_with_attributes - (_("Interface"), renderer, "text", 0, NULL); + gtk_tree_view_column_new_with_attributes + (_("Interface"), renderer, "text", 0, NULL); gtk_tree_view_append_column (widget, column); renderer = gtk_cell_renderer_text_new (); /* Members of multicast group */ column = - gtk_tree_view_column_new_with_attributes - (_("Member"), renderer, "text", 1, NULL); + gtk_tree_view_column_new_with_attributes + (_("Member"), renderer, "text", 1, NULL); g_object_set (G_OBJECT (renderer), "xalign", 0.5, NULL); gtk_tree_view_append_column (widget, column); - + renderer = gtk_cell_renderer_text_new (); /* Multicast group */ column = - gtk_tree_view_column_new_with_attributes - (_("Group"), renderer, "text", 2, NULL); + gtk_tree_view_column_new_with_attributes + (_("Group"), renderer, "text", 2, NULL); gtk_tree_view_append_column (widget, column); } /* END MULTICAST */ @@ -657,7 +686,7 @@ column = gtk_tree_view_get_column (widget, i-1); gtk_tree_view_remove_column (widget, column); } - + g_list_free (columns); } 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 15 Dec 2003 22:25:57 -0000 @@ -25,9 +25,10 @@ #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_MULTICAST_FORMAT "%s %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