diff -Naur gkrellm-2.2.7/server/monitor.c gkrellm-2.2.7h/server/monitor.c --- gkrellm-2.2.7/server/monitor.c 2005-05-23 22:29:32.000000000 -0600 +++ gkrellm-2.2.7h/server/monitor.c 2005-11-05 12:34:12.000000000 -0700 @@ -625,41 +625,57 @@ gint slen; tcp = (ActiveTCP *) data; - for (list = inet_list; list; list = list->next) +#if 0 + show_tcp("gkrellm_inet_log_tcp_port_data", tcp); +#endif + if (tcp->chain & CHAIN_CONNECT) { - in = (InetData *) list->data; - active_tcp = &in->tcp; - if (tcp->family == AF_INET) - { - ap = (char *)&tcp->remote_addr; - aap = (char *)&active_tcp->remote_addr; - slen = sizeof(struct in_addr); - } -#if defined(INET6) - else if (tcp->family == AF_INET6) + for (list = inet_list; list; list = list->next) { - ap = (char *)&tcp->remote_addr6; - aap = (char *)&active_tcp->remote_addr6; - slen = sizeof(struct in6_addr); - } + in = (InetData *) list->data; + active_tcp = &in->tcp; + if (tcp->family == AF_INET) + { + ap = (char *)&tcp->remote_addr; + aap = (char *)&active_tcp->remote_addr; + slen = sizeof(struct in_addr); + } +#if defined(INET6) + else if (tcp->family == AF_INET6) + { + ap = (char *)&tcp->remote_addr6; + aap = (char *)&active_tcp->remote_addr6; + slen = sizeof(struct in6_addr); + } #endif - else - return; - if ( memcmp(aap, ap, slen) == 0 - && active_tcp->remote_port == tcp->remote_port - && active_tcp->local_port == tcp->local_port - ) - { - in->alive = TRUE; /* Old alive connection still alive */ - return; + else + return; + + if ( memcmp(aap, ap, slen) == 0 + && active_tcp->remote_port == tcp->remote_port + && active_tcp->local_port == tcp->local_port + ) + { + in->alive = TRUE; /* Old alive connection still alive */ + return; + } } + inet_new = TRUE; + in = g_new0(InetData, 1); + in->tcp = *tcp; + in->alive = TRUE; + in->new_connection = TRUE; + inet_list = g_list_append(inet_list, in); + } + else + { + inet_new = TRUE; + in = g_new0(InetData, 1); + in->tcp = *tcp; + in->alive = TRUE; + in->new_connection = TRUE; + inet_list = g_list_append(inet_list, in); } - inet_new = TRUE; - in = g_new0(InetData, 1); - in->tcp = *tcp; - in->alive = TRUE; - in->new_connection = TRUE; - inet_list = g_list_append(inet_list, in); } static void @@ -724,39 +740,56 @@ { in = (InetData *) list->data; tcp = &in->tcp; - if ( tcp->family == AF_INET - && (in->new_connection || first_serve) - ) + if (tcp->chain & CHAIN_CONNECT) { - cp = inet_ntoa(tcp->remote_addr); - sprintf(buf, "+0 %x %s:%x\n", - tcp->local_port, cp, tcp->remote_port); - } + if ( tcp->family == AF_INET + && (in->new_connection || first_serve) + ) + { + cp = inet_ntoa(tcp->remote_addr); + sprintf(buf, "+0 %x %s:%x\n", + tcp->local_port, cp, tcp->remote_port); + } #if defined(INET6) && defined(HAVE_GETADDRINFO) - else if (tcp->family == AF_INET6 - && (in->new_connection || first_serve)) - { - memset(&sin6, 0, sizeof(sin6)); - memcpy(&sin6.sin6_addr, &tcp->remote_addr6, - sizeof(struct in6_addr)); - sin6.sin6_family = AF_INET6; + else if (tcp->family == AF_INET6 + && (in->new_connection || first_serve)) + { + memset(&sin6, 0, sizeof(sin6)); + memcpy(&sin6.sin6_addr, &tcp->remote_addr6, + sizeof(struct in6_addr)); + sin6.sin6_family = AF_INET6; #ifdef SIN6_LEN - sin6.sin6_len = sizeof(struct sockaddr_in6); + sin6.sin6_len = sizeof(struct sockaddr_in6); #endif - if (getnameinfo((struct sockaddr *)&sin6, - sizeof(struct sockaddr_in6), - addrbuf, sizeof(addrbuf), - NULL, 0, - NI_NUMERICHOST|NI_WITHSCOPEID) - != 0) + if (getnameinfo((struct sockaddr *)&sin6, + sizeof(struct sockaddr_in6), + addrbuf, sizeof(addrbuf), + NULL, 0, + NI_NUMERICHOST|NI_WITHSCOPEID) + != 0) + continue; + snprintf(buf, sizeof(buf), "+6 %x [%s]:%x\n", + tcp->local_port, addrbuf, + tcp->remote_port); + } +#endif + else continue; - snprintf(buf, sizeof(buf), "+6 %x [%s]:%x\n", - tcp->local_port, addrbuf, - tcp->remote_port); } -#endif else - continue; + { + if (in->new_connection || first_serve) + { + snprintf(buf, sizeof(buf), "*F %x:%x %x:%x %d:%d:%d %Lu:%Lu %s\n", + tcp->local_port, tcp->local_port_hi, + tcp->remote_port, tcp->remote_port_hi, + tcp->chain, tcp->target, tcp->type, tcp->pkts, tcp->bytes, tcp->interface); + in->alive = FALSE; +#if 0 +fprintf(stderr, "serving buf=%s", buf); +#endif + } + } gkrellmd_serve_data(mon, buf); } diff -Naur gkrellm-2.2.7/src/chart.c gkrellm-2.2.7h/src/chart.c --- gkrellm-2.2.7/src/chart.c 2005-05-23 21:38:55.000000000 -0600 +++ gkrellm-2.2.7h/src/chart.c 2005-11-04 10:36:15.000000000 -0700 @@ -66,7 +66,7 @@ return chart_list; } -gint +gint64 gkrellm_get_chart_scalemax(GkrellmChart *cp) { if (!cp) @@ -74,7 +74,7 @@ return cp->scale_max; } -gint +gint64 gkrellm_get_current_chartdata(GkrellmChartdata *cd) { if (!cd) @@ -82,7 +82,7 @@ return cd->data[cd->chart->position]; } -gint +gint64 gkrellm_get_chartdata_data(GkrellmChartdata *cd, gint index) { gint x; @@ -248,6 +248,23 @@ cd->draw_style = dstyle; } +gboolean gkrellm_get_chartdata_draw_style(GkrellmChartdata *cd) + { + if (!cd) + return 0; + return cd->draw_style; + } + +void gkrellm_chartdata_draw_style_connect(GkrellmChartdata *cd, + void (*func)(gpointer), gpointer data) + { + if (cd) + { + cd->cb_draw_style = func; + cd->cb_draw_style_data = data; + } + } + void gkrellm_set_chartdata_flags(GkrellmChartdata *cd, gint flags) { @@ -256,7 +273,7 @@ } static gint -chartdata_ycoord(GkrellmChart *cp, GkrellmChartdata *cd, gint yd) +chartdata_ycoord(GkrellmChart *cp, GkrellmChartdata *cd, gint64 yd) { glong y; guint64 Y; @@ -270,7 +287,7 @@ y = Y / cp->scale_max; } else - y = ((glong) yd * cd->h / cp->scale_max); + y = (yd * cd->h / cp->scale_max); if (y < 0) y = 0; @@ -366,7 +383,8 @@ { GList *list; GkrellmChartdata *cd; - gint n, x, y, y0, y1, yN, yI; + gint n, x, y, y0, y1; + gint64 yN, yI; gint current_split; gboolean need_next_split = FALSE; @@ -515,7 +533,7 @@ /* See the README for description of auto grid resolution behavior. */ static void -set_auto_grid_resolution(GkrellmChart *cp, gint maxval) +set_auto_grid_resolution(GkrellmChart *cp, gint64 maxval) { GkrellmChartconfig *cf = cp->config; gint grids, grid_res, maxval_base; @@ -533,7 +551,7 @@ cp->maxval_auto = maxval; grids = cf->fixed_grids; - if (grids == 0) /* Auto grids mode */ + if (!grids) /* Auto grids mode */ grid_res = gkrellm_125_sequence(cp->maxval_auto_base, cf->sequence_125, cf->low, cf->high, TRUE, FALSE); else @@ -568,7 +586,7 @@ setup_chart_scalemax(GkrellmChart *cp) { GkrellmChartconfig *cf = cp->config; - glong scalemax; + gint64 scalemax; gint grid_res, i0; /* maxval may change at any gkrellm_store_chartdata(), so at each chart @@ -680,7 +698,7 @@ cd->w = w; if (cd->data) g_free(cd->data); - cd->data = (gint *) g_new0(gint, w); + cd->data = (gint64 *) g_new0(gint64, w); cd->maxval = 0; cp->position = cp->w - 1; cp->tail = cp->position; @@ -712,7 +730,7 @@ { GList *list; GkrellmChartdata *cd; - gint N, I; + gint64 N, I; gint i, current_split; gboolean need_next_split = FALSE; @@ -800,7 +818,8 @@ GList *list; GkrellmChartdata *cd; gulong range, total_diff; - gint n, N_discard, I_discard, N, I; + gint n; + guint64 N, I, N_discard, I_discard; gint active_split, current_split; gboolean need_scan = FALSE; @@ -810,7 +829,7 @@ for (list = cp->cd_list; list; list = list->next) { cd = (GkrellmChartdata *) list->data; - cd->current = va_arg(args, gulong); + cd->current = va_arg(args, guint64); if (!cd->monotonic) { cd->previous = 0; @@ -843,7 +862,7 @@ { cd = (GkrellmChartdata *) list->data; cd->discard = cd->data[cp->tail]; - cd->data[n] = (gint)(cd->current - cd->previous); + cd->data[n] = (gint64)(cd->current - cd->previous); cd->previous = cd->current; /* If using totals, scale the stored data to range between 0 and the @@ -892,7 +911,9 @@ else if (N > cd->maxval) cd->maxval = N; } - if (N + I > cp->maxval) + if (N_discard + I_discard >= cd->maxval) + need_scan = TRUE; + else if (N + I > cp->maxval) cp->maxval = N + I; } else if (cd->draw_style == CHARTDATA_LINE) @@ -1202,7 +1223,7 @@ gdk_draw_drawable(cp->pixmap, _GK.draw1_GC, cp->bg_pixmap, x, y, x, y, w + ts->effect, h + ts->effect); - gkrellm_draw_string(cp->pixmap, ts, x, y - y_ink, s); + gkrellm_draw_string(cp->pixmap, ts, x, y - y_ink, s); return x + w + ts->effect; } @@ -1934,7 +1955,7 @@ }; gint -gkrellm_125_sequence(gint value, gboolean use125, +gkrellm_125_sequence(gint64 value, gboolean use125, gint low, gint high, gboolean snap_to_table, gboolean roundup) { @@ -2073,10 +2094,11 @@ gkrellm_chartconfig_grid_resolution_connect(GkrellmChartconfig *cf, void (*func)(gpointer), gpointer data) { - if (!cf) - return; - cf->cb_grid_resolution = func; - cf->cb_grid_resolution_data = data; + if (cf) + { + cf->cb_grid_resolution = func; + cf->cb_grid_resolution_data = data; + } } void @@ -2101,9 +2123,9 @@ if (map_sequence) { cf->low = 1; - cf->low = (gfloat) gkrellm_125_sequence((gint) low, cf->sequence_125, + cf->low = (gfloat) gkrellm_125_sequence((gint64) low, cf->sequence_125, low, high, TRUE, FALSE); - cf->high = (gfloat) gkrellm_125_sequence((gint) high, + cf->high = (gfloat) gkrellm_125_sequence((gint64) high, cf->sequence_125, low, high, TRUE, TRUE); cf->step0 = 1.0; cf->step1 = 1.0; @@ -2131,6 +2153,14 @@ gkrellm_dup_string(&cf->grid_resolution_label, label); } +gboolean +gkrellm_get_chartconfig_auto_grid_resolution(GkrellmChartconfig *cf) + { + if (!cf) + return 0; + return cf->auto_grid_resolution; + } + void gkrellm_set_chartconfig_auto_grid_resolution(GkrellmChartconfig *cf, gboolean ato) { @@ -2139,12 +2169,43 @@ } void +gkrellm_chartconfig_auto_grid_resolution_connect(GkrellmChartconfig *cf, + void (*func)(gpointer), gpointer data) + { + if (cf) + { + cf->cb_auto_grid_resolution = func; + cf->cb_auto_grid_resolution_data = data; + } + } + + +void gkrellm_set_chartconfig_auto_resolution_stick(GkrellmChartconfig *cf, gboolean stick) { if (cf) cf->auto_resolution_stick = stick; } +gboolean +gkrellm_get_chartconfig_auto_resolution_stick(GkrellmChartconfig *cf) + { + if (!cf) + return 0; + return cf->auto_resolution_stick; + } + +void +gkrellm_chartconfig_auto_resolution_stick_connect(GkrellmChartconfig *cf, + void (*func)(gpointer), gpointer data) + { + if (cf) + { + cf->cb_auto_resolution_stick = func; + cf->cb_auto_resolution_stick_data = data; + } + } + void gkrellm_set_chartconfig_sequence_125(GkrellmChartconfig *cf, gboolean seq) { @@ -2152,6 +2213,25 @@ cf->sequence_125 = seq; } +gboolean +gkrellm_get_chartconfig_sequence_125(GkrellmChartconfig *cf) + { + if (!cf) + return 0; + return cf->sequence_125; + } + +void +gkrellm_chartconfig_sequence_125_connect(GkrellmChartconfig *cf, + void (*func)(gpointer), gpointer data) + { + if (cf) + { + cf->cb_sequence_125 = func; + cf->cb_sequence_125_data = data; + } + } + void gkrellm_set_chartconfig_fixed_grids(GkrellmChartconfig *cf, gint fixed_grids) { @@ -2172,10 +2252,11 @@ gkrellm_chartconfig_fixed_grids_connect(GkrellmChartconfig *cf, void (*func)(gpointer), gpointer data) { - if (!cf) - return; - cf->cb_fixed_grids = func; - cf->cb_fixed_grids_data = data; + if (cf) + { + cf->cb_fixed_grids = func; + cf->cb_fixed_grids_data = data; + } } gint @@ -2190,10 +2271,11 @@ gkrellm_chartconfig_height_connect(GkrellmChartconfig *cf, void (*func)(gpointer), gpointer data) { - if (!cf) - return; - cf->cb_height = func; - cf->cb_height_data = data; + if (cf) + { + cf->cb_height = func; + cf->cb_height_data = data; + } } void @@ -2330,25 +2412,36 @@ { _GK.config_modified = TRUE; cd->draw_style = GTK_TOGGLE_BUTTON(widget)->active; + if (cd->cb_draw_style) + (*cd->cb_draw_style)(cd, cd->cb_draw_style_data); gkrellm_rescale_chart(cd->chart); } static void cb_auto_resolution(GtkWidget *widget, GkrellmChart *cp) { - GtkWidget *button; + GtkWidget *button; GkrellmChartconfig *cf = cp->config; + gint new; - _GK.config_modified = TRUE; - cf->auto_grid_resolution = GTK_TOGGLE_BUTTON(widget)->active; + new = GTK_TOGGLE_BUTTON(widget)->active; - set_resolution_menubar_items_sensitivity(cf); - button = cf->grid_resolution_spin_button; - if (cf->auto_grid_resolution) - gtk_widget_set_sensitive(button, FALSE); - else - gtk_widget_set_sensitive(button, TRUE); - gkrellm_rescale_chart(cp); + if (new != cf->auto_grid_resolution) + { + _GK.config_modified = TRUE; + + cf->auto_grid_resolution = new; + if (cf->cb_auto_grid_resolution && !cf->cb_block) + (*cf->cb_auto_grid_resolution)(cf, cf->cb_auto_grid_resolution_data); + + set_resolution_menubar_items_sensitivity(cf); + button = cf->grid_resolution_spin_button; + if (cf->auto_grid_resolution) + gtk_widget_set_sensitive(button, FALSE); + else + gtk_widget_set_sensitive(button, TRUE); + gkrellm_rescale_chart(cp); + } } static void @@ -2356,9 +2449,82 @@ { _GK.config_modified = TRUE; cd->inverted = GTK_TOGGLE_BUTTON(widget)->active; + if (cd->cb_inverted) + (*cd->cb_inverted)(cd, cd->cb_inverted_data); gkrellm_rescale_chart(cd->chart); } +void gkrellm_set_chartdata_inverted(GkrellmChartdata *cd, gboolean inverted) + { + if (cd) + cd->inverted = inverted; + } + +gboolean gkrellm_get_chartdata_inverted(GkrellmChartdata *cd) + { + if (!cd) + return 0; + return cd->inverted; + } + +void gkrellm_chartdata_inverted_connect(GkrellmChartdata *cd, + void (*func)(gpointer), gpointer data) + { + if (cd) + { + cd->cb_inverted = func; + cd->cb_inverted_data = data; + } + } + +void gkrellm_set_chartdata_split_chart(GkrellmChartdata *cd, gboolean split_chart) + { + if (cd) + cd->split_chart = split_chart; + } + +gboolean gkrellm_get_chartdata_split_chart(GkrellmChartdata *cd) + { + if (!cd) + return 0; + return cd->split_chart; + } + +void gkrellm_chartdata_split_chart_connect(GkrellmChartdata *cd, + void (*func)(gpointer), gpointer data) + { + if (cd) + { + cd->cb_split_chart = func; + cd->cb_split_chart_data = data; + } + } + +void gkrellm_set_chartdata_split_fraction(GkrellmChartdata *cd, gfloat split_fraction) + { + if (cd) + { + cd->split_fraction = split_fraction; + } + } + +gfloat gkrellm_get_chartdata_split_fraction(GkrellmChartdata *cd) + { + if (!cd) + return 0; + return cd->split_fraction; + } + +void gkrellm_chartdata_split_fraction_connect(GkrellmChartdata *cd, + void (*func)(gpointer), gpointer data) + { + if (cd) + { + cd->cb_split_fraction = func; + cd->cb_split_fraction_data = data; + } + } + static void cb_hide(GtkWidget *widget, GkrellmChartdata *cd) { @@ -2373,6 +2539,8 @@ { _GK.config_modified = TRUE; cd->split_chart = GTK_TOGGLE_BUTTON(widget)->active; + if (cd->cb_split_chart) + (*cd->cb_split_chart)(cd, cd->cb_split_chart_data); gtk_widget_set_sensitive(cd->split_fraction_spin_button, cd->split_chart); set_chartdata_split_heights(cd->chart); gkrellm_rescale_chart(cd->chart); @@ -2386,6 +2554,8 @@ _GK.config_modified = TRUE; spin = GTK_SPIN_BUTTON(cd->split_fraction_spin_button); cd->split_fraction = gtk_spin_button_get_value(spin); + if (cd->cb_split_fraction) + (*cd->cb_split_fraction)(cd, cd->cb_split_fraction_data); set_chartdata_split_heights(cd->chart); gkrellm_rescale_chart(cd->chart); } @@ -2410,6 +2580,8 @@ case 1: active = GTK_CHECK_MENU_ITEM(widget)->active; cf->auto_resolution_stick = active; + if (cf->cb_auto_resolution_stick && !cf->cb_block) + (*cf->cb_auto_resolution_stick)(cf, cf->cb_auto_resolution_stick_data); cp->maxval_auto_base = 0; break; case 2: @@ -2417,12 +2589,16 @@ if (cf->sequence_125 && active) return; cf->sequence_125 = active; + if (cf->cb_sequence_125 && !cf->cb_block) + (*cf->cb_sequence_125)(cf, cf->cb_sequence_125_data); break; case 3: active = GTK_CHECK_MENU_ITEM(widget)->active; if (!cf->sequence_125 && active) return; cf->sequence_125 = !active; + if (cf->cb_sequence_125 && !cf->cb_block) + (*cf->cb_sequence_125)(cf, cf->cb_sequence_125_data); grid_res = gkrellm_125_sequence(cf->grid_resolution, cf->sequence_125, cf->low, cf->high, TRUE, FALSE); @@ -2611,7 +2787,7 @@ gkrellm_gtk_spin_button(vbox1, &button, (gfloat) cf->fixed_grids, 0, 5, 1.0, 1.0, 0, 50, cb_chart_fixed_grids, cp, FALSE, - _("0: Auto 1-5: Constant")); + _("0: Auto 1-5: Constant")); cf->fixed_grids_spin_button = button; } @@ -2735,3 +2911,4 @@ printf("\n"); } } + diff -Naur gkrellm-2.2.7/src/client.c gkrellm-2.2.7h/src/client.c --- gkrellm-2.2.7/src/client.c 2005-05-23 22:28:22.000000000 -0600 +++ gkrellm-2.2.7h/src/client.c 2005-11-03 11:58:45.000000000 -0700 @@ -557,6 +557,12 @@ #endif gint n, slen; + bzero(&tcp, sizeof(ActiveTCP)); + +#if 0 + fprintf(stderr, "%s\n", line); +#endif + if (*(line + 1) == '0') { n = sscanf(line + 3, "%x %127[^:]:%x", &tcp.local_port, @@ -587,6 +593,25 @@ tcp.family = AF_INET6; } #endif + else if (*(line + 1) == 'F') + { + tcp.state = 0; + tcp.family = 0; + tcp.new_hit = 0; + n = sscanf(line + 3, "%x:%x %x:%x %d:%d:%d %Lu:%Lu %7s", + &tcp.local_port, &tcp.local_port_hi, + &tcp.remote_port, &tcp.remote_port_hi, + &tcp.chain, &tcp.target, &tcp.type, + &tcp.pkts, &tcp.bytes, tcp.interface); +#if 0 + fprintf(stderr, "%s\n", line); + show_tcp("client_inet_line_from_server", &tcp); +#endif + if (n != 10) + return; + gkrellm_inet_log_tcp_port_data(&tcp); + } + if (*line == '+') { t = g_new0(ActiveTCP, 1); @@ -1820,10 +1845,11 @@ _GK.server_port = GKRELLMD_SERVER_PORT; client_fd = gkrellm_connect_to(_GK.server, _GK.server_port); - if (client_fd < 0) { + if (client_fd < 0) + { printf("%s\n", _("Unable to connect.")); return FALSE; - } + } snprintf(buf, sizeof(buf), "gkrellm %d.%d.%d%s\n", GKRELLM_VERSION_MAJOR, GKRELLM_VERSION_MINOR, diff -Naur gkrellm-2.2.7/src/cpu.c gkrellm-2.2.7h/src/cpu.c --- gkrellm-2.2.7/src/cpu.c 2005-05-23 21:39:28.000000000 -0600 +++ gkrellm-2.2.7h/src/cpu.c 2005-11-03 13:27:53.000000000 -0700 @@ -453,7 +453,7 @@ total = cpu->user + cpu->nice + cpu->sys + cpu->idle; if (GK.second_tick) { - gkrellm_store_chartdata(cp, total, cpu->sys, cpu->user, cpu->nice); + gkrellm_store_chartdata(cp, total, (guint64) cpu->sys, (guint64) cpu->user, (guint64) cpu->nice); refresh_cpu_chart(cpu); alert_value = cpu->sys + cpu->user; diff -Naur gkrellm-2.2.7/src/disk.c gkrellm-2.2.7h/src/disk.c --- gkrellm-2.2.7/src/disk.c 2005-05-23 21:39:49.000000000 -0600 +++ gkrellm-2.2.7h/src/disk.c 2005-11-03 13:27:53.000000000 -0700 @@ -594,7 +594,7 @@ if (GK.second_tick) { gkrellm_store_chartdata(cp, 0, - (gulong) disk->wb, (gulong) disk->rb); + (guint64) disk->wb, (guint64) disk->rb); if (disk->alert) { bytes = 0; diff -Naur gkrellm-2.2.7/src/gkrellm.h gkrellm-2.2.7h/src/gkrellm.h --- gkrellm-2.2.7/src/gkrellm.h 2005-05-23 21:43:21.000000000 -0600 +++ gkrellm-2.2.7h/src/gkrellm.h 2005-11-04 09:47:51.000000000 -0700 @@ -396,7 +396,7 @@ gboolean scroll_text_cache_off; gint spare0; - gboolean transparency; + gint transparency; gint themed; /* Non zero if theme has custom assignments */ GkrellmBorder border; /* Border for background panel image */ @@ -546,17 +546,28 @@ | value * spin_factor so spin buttons may have non-integer settings. */ gint grid_resolution; - gboolean auto_grid_resolution; - gboolean auto_resolution_stick; - gboolean sequence_125; void (*cb_grid_resolution)(); gpointer cb_grid_resolution_data; GtkWidget *grid_resolution_spin_button; + gchar *grid_resolution_label; + + gboolean auto_grid_resolution; + void (*cb_auto_grid_resolution)(); + gpointer cb_auto_grid_resolution_data; + + gboolean auto_resolution_stick; + void (*cb_auto_resolution_stick)(); + gpointer cb_auto_resolution_stick_data; + + gboolean sequence_125; + void (*cb_sequence_125)(); + gpointer cb_sequence_125_data; GtkWidget *auto_resolution_control_menubar; GtkItemFactory *auto_resolution_item_factory; - gchar *grid_resolution_label; + gboolean adjustment_is_set; gboolean map_sequence; + gfloat spin_factor; gfloat low, /* Stuff for the grid_resolution spin adjustment */ high, @@ -568,6 +579,7 @@ gboolean fixed_grids; void (*cb_fixed_grids)(); gpointer cb_fixed_grids_data; + GtkWidget *fixed_grids_spin_button; GList *cd_list; /* Same list as in parent GkrellmChart */ @@ -616,7 +628,7 @@ } GkrellmTextRun; -typedef struct +typedef struct GkrellmChart { GtkWidget *box; /* Container box this chart is packed into */ GtkWidget *drawing_area; @@ -642,7 +654,7 @@ gint alloc_width; gint scale_max; - gint maxval, + gint64 maxval, maxval_auto, maxval_auto_base, maxval_peak; @@ -683,6 +695,7 @@ GkrellmStyle *style; gpointer monitor; + struct GkrellmChart *overlay; /* This chart is an overlay of the chart pointed to */ } GkrellmChart; @@ -704,13 +717,13 @@ GkrellmChart *chart; /* GkrellmChart this data belong to */ gchar *label; - gulong current, + guint64 current, previous, discard; gboolean monotonic; GkrellmChartlayer layer; /* The image + grid for this data layer */ GdkBitmap *data_bitmap; /* Draw data here, use as clipmask for layer*/ - gint *data; + gint64 *data; gint draw_style; gboolean inverted; @@ -721,13 +734,22 @@ split_share; GtkWidget *split_fraction_spin_button; + void (*cb_draw_style)(); + gpointer cb_draw_style_data; + void (*cb_inverted)(); + gpointer cb_inverted_data; + void (*cb_split_chart)(); + gpointer cb_split_chart_data; + void (*cb_split_fraction)(); + gpointer cb_split_fraction_data; + gint y_p, y_pp; gboolean y_p_valid; gint y, /* Each data layer draws at an offset y and */ h, /* within height h of its parent GkrellmChart*/ w; /* Width of data allocated. */ - gint maxval; + guint64 maxval; } GkrellmChartdata; diff -Naur gkrellm-2.2.7/src/gkrellm-private.h gkrellm-2.2.7h/src/gkrellm-private.h --- gkrellm-2.2.7/src/gkrellm-private.h 2005-05-23 21:43:06.000000000 -0600 +++ gkrellm-2.2.7h/src/gkrellm-private.h 2005-11-01 08:33:24.000000000 -0700 @@ -475,5 +475,3 @@ gint gkrellm_client_server_connect_state(void); void gkrellm_client_mode_connect_thread(void); gint gkrellm_client_server_get_net_timer(void); - - diff -Naur gkrellm-2.2.7/src/gkrellm-public-proto.h gkrellm-2.2.7h/src/gkrellm-public-proto.h --- gkrellm-2.2.7/src/gkrellm-public-proto.h 2005-05-23 21:43:15.000000000 -0600 +++ gkrellm-2.2.7h/src/gkrellm-public-proto.h 2005-11-01 14:50:15.000000000 -0700 @@ -67,7 +67,7 @@ gint gkrellm_chart_width(void); void gkrellm_set_chart_height_default(GkrellmChart *, gint); void gkrellm_set_chart_height(GkrellmChart *, gint); -gint gkrellm_get_chart_scalemax(GkrellmChart *); +gint64 gkrellm_get_chart_scalemax(GkrellmChart *); void gkrellm_render_data_pixmap(GkrellmPiximage *, GdkPixmap **, GdkColor *, gint); void gkrellm_render_data_grid_pixmap(GkrellmPiximage *, @@ -84,10 +84,8 @@ void gkrellm_draw_chartdata(GkrellmChart *); void gkrellm_monotonic_chartdata(GkrellmChartdata *, gboolean); gboolean gkrellm_get_chartdata_hide(GkrellmChartdata *); -gint gkrellm_get_current_chartdata(GkrellmChartdata *); -gint gkrellm_get_chartdata_data(GkrellmChartdata *, gint); -void gkrellm_set_chartdata_draw_style(GkrellmChartdata *, gint); -void gkrellm_set_chartdata_draw_style_default(GkrellmChartdata *, gint); +gint64 gkrellm_get_current_chartdata(GkrellmChartdata *); +gint64 gkrellm_get_chartdata_data(GkrellmChartdata *, gint); void gkrellm_set_chartdata_flags(GkrellmChartdata *, gint); void gkrellm_scale_chartdata(GkrellmChartdata *, gint, gint); void gkrellm_offset_chartdata(GkrellmChartdata *, gint); @@ -97,32 +95,69 @@ */ void gkrellm_chartconfig_window_create(GkrellmChart *); void gkrellm_chartconfig_window_destroy(GkrellmChart *); + +void gkrellm_set_chartconfig_flags(GkrellmChartconfig *, gint); + void gkrellm_chartconfig_grid_resolution_adjustment( GkrellmChartconfig *, gboolean, gfloat, gfloat, gfloat, gfloat, gfloat, gint, gint); + void gkrellm_set_chartconfig_grid_resolution(GkrellmChartconfig *, gint); gint gkrellm_get_chartconfig_grid_resolution(GkrellmChartconfig *); void gkrellm_chartconfig_grid_resolution_connect( GkrellmChartconfig *, void (*fn)(), gpointer); -void gkrellm_set_chartconfig_flags(GkrellmChartconfig *, gint); - void gkrellm_chartconfig_grid_resolution_label( GkrellmChartconfig *, gchar *); -void gkrellm_set_chartconfig_auto_grid_resolution( - GkrellmChartconfig *, gboolean); + +void gkrellm_set_chartconfig_auto_grid_resolution(GkrellmChartconfig *, + gboolean); +gboolean gkrellm_get_chartconfig_auto_grid_resolution(GkrellmChartconfig *); +void gkrellm_chartconfig_auto_grid_resolution_connect( + GkrellmChartconfig *, void (*fn)(), gpointer); + void gkrellm_set_chartconfig_auto_resolution_stick( GkrellmChartconfig *, gboolean); +gboolean gkrellm_get_chartconfig_auto_resolution_stick(GkrellmChartconfig *); +void gkrellm_chartconfig_auto_resolution_stick_connect( + GkrellmChartconfig *, void (*fn)(), gpointer); + void gkrellm_set_chartconfig_sequence_125(GkrellmChartconfig *, gboolean); +gboolean gkrellm_get_chartconfig_sequence_125(GkrellmChartconfig *); +void gkrellm_chartconfig_sequence_125_connect( + GkrellmChartconfig *, void (*fn)(), gpointer); + void gkrellm_set_chartconfig_fixed_grids(GkrellmChartconfig *, gint); gint gkrellm_get_chartconfig_fixed_grids(GkrellmChartconfig *); void gkrellm_chartconfig_fixed_grids_connect(GkrellmChartconfig *, void (*fn)(), gpointer); + gint gkrellm_get_chartconfig_height(GkrellmChartconfig *); void gkrellm_chartconfig_height_connect(GkrellmChartconfig *, void (*fn)(), gpointer); + + +void gkrellm_set_chartdata_draw_style(GkrellmChartdata *, gint); +void gkrellm_set_chartdata_draw_style_default(GkrellmChartdata *, gint); +gint gkrellm_get_chartdata_draw_style(GkrellmChartdata *); +void gkrellm_chartdata_draw_style_connect(GkrellmChartdata *, void (*fn)(), gpointer); + +void gkrellm_set_chartdata_inverted(GkrellmChartdata *, gboolean); +gboolean gkrellm_get_chartdata_inverted(GkrellmChartdata *); +void gkrellm_chartdata_inverted_connect(GkrellmChartdata *, void (*fn)(), gpointer); + +void gkrellm_set_chartdata_split_chart(GkrellmChartdata *, gboolean); +gboolean gkrellm_get_chartdata_split_chart(GkrellmChartdata *); +void gkrellm_chartdata_split_chart_connect(GkrellmChartdata *, void (*fn)(), gpointer); + +void gkrellm_set_chartdata_split_fraction(GkrellmChartdata *, gfloat); +gfloat gkrellm_get_chartdata_split_fraction(GkrellmChartdata *); +void gkrellm_chartdata_split_fraction_connect(GkrellmChartdata *, void (*fn)(), gpointer); + + void gkrellm_chartconfig_callback_block(GkrellmChartconfig *, gboolean); + void gkrellm_save_chartconfig(FILE *, GkrellmChartconfig *, gchar *, gchar *); void gkrellm_load_chartconfig(GkrellmChartconfig **, gchar *, gint); @@ -529,7 +564,7 @@ gchar *gkrellm_make_config_file_name(gchar *, gchar *); gchar *gkrellm_make_data_file_name(gchar *, gchar *); struct tm *gkrellm_get_current_time(void); -gint gkrellm_125_sequence(gint, gboolean, gint, gint, +gint gkrellm_125_sequence(gint64, gboolean, gint, gint, gboolean, gboolean); void gkrellm_save_all(void); diff -Naur gkrellm-2.2.7/src/inet.c gkrellm-2.2.7h/src/inet.c --- gkrellm-2.2.7/src/inet.c 2005-05-23 21:40:29.000000000 -0600 +++ gkrellm-2.2.7h/src/inet.c 2005-11-04 12:41:13.000000000 -0700 @@ -34,11 +34,21 @@ GkrellmChart *chart_hour; GkrellmChartconfig *chart_config_minute; GkrellmChartconfig *chart_config_hour; + GkrellmChart *chart_minute_pkts; + GkrellmChart *chart_hour_pkts; + GkrellmChartconfig *chart_config_minute_pkts; + GkrellmChartconfig *chart_config_hour_pkts; + GkrellmChart *chart_minute_bytes; + GkrellmChart *chart_hour_bytes; + GkrellmChartconfig *chart_config_minute_bytes; + GkrellmChartconfig *chart_config_hour_bytes; GkrellmPanel *panel; gboolean hour_mode; gint cd_length; - gboolean extra_info; + gboolean extra_info; // 0 no text or 1 text + gint display_mode; // 0 connections, 1 packets, 2 bytes + GkrellmLauncher launch; GtkWidget *launch_entry, *tooltip_entry; @@ -58,23 +68,47 @@ gchar *label0; gint active0; - gint prev_active0; - gulong hits0_minute, + gint prev_active0; + guint64 pkts0; + guint64 prev_pkts0; + guint64 bytes0; + guint64 prev_bytes0; + guint64 hits0_minute, hits0_hour; + guint64 pkts0_minute, + pkts0_hour, + bytes0_minute, + bytes0_hour; gboolean data0_is_range; - gulong port0_0, + gboolean data0_outbound; + + glong port0_0, port0_1; + gchar *interface0; gchar *label1; gint active1; - gint prev_active1; - gulong hits1_minute, + gint prev_active1; + guint64 pkts1; + guint64 prev_pkts1; + guint64 bytes1; + guint64 prev_bytes1; + guint64 hits1_minute, hits1_hour; + guint64 pkts1_minute, + pkts1_hour, + bytes1_minute, + bytes1_hour; gboolean data1_is_range; - gulong port1_0, + gboolean data1_outbound; + + glong port1_0, port1_1; + gchar *interface1; gulong krell_hits; + guint64 krell_pkts; + guint64 krell_bytes; } InetMon; @@ -88,6 +122,7 @@ static GtkWidget *inet_vbox; static GdkImage *grid; +static GtkWidget *delete_button; static gchar *inet_data_dir; static gchar *text_format, @@ -159,6 +194,87 @@ } void +update_iptables_counts(InetMon *in, ActiveTCP *tcp, gint test) + { + guint64 cnt; + if ((cnt = tcp->pkts)) + { + in->krell_pkts += cnt; + + if (test >= 4) + { + in->pkts1 += cnt; + in->pkts1_minute += cnt; + in->pkts1_hour += cnt; + } + else + { + in->pkts0 += cnt; + in->pkts0_minute += cnt; + in->pkts0_hour += cnt; + } + } + + if ((cnt = tcp->bytes)) + { + in->krell_bytes += cnt; + + if (test >= 4) + { + in->bytes1 += cnt; + in->bytes1_minute += cnt; + in->bytes1_hour += cnt; + } + else + { + in->bytes0 += cnt; + in->bytes0_minute += cnt; + in->bytes0_hour += cnt; + } + } +#if 0 + if (!(tcp->chain & CHAIN_CONNECT)) + show_tcp("update_iptables_counts", tcp); +#endif + } + +void +check_iptables_range(InetMon *in, ActiveTCP *tcp, glong port) + { + if (!strcmp(in->interface0, "all") || !strcmp(in->interface0, tcp->interface)) + { + if ((in->data0_outbound && (tcp->chain & CHAIN_OUTPUT)) || + (!in->data0_outbound && (tcp->chain & CHAIN_INPUT))) + { + if (!in->data0_is_range && in->port0_0 == port) + update_iptables_counts(in, tcp, 2); + + else if (!in->data0_is_range && in->port0_1 == port) + update_iptables_counts(in, tcp, 3); + + else if ( in->data0_is_range && in->port0_0 <= port && port <= in->port0_1) + update_iptables_counts(in, tcp, 2); + } + } + + if (!strcmp(in->interface1, "all") || !strcmp(in->interface1, tcp->interface)) + { + if ((in->data1_outbound && (tcp->chain & CHAIN_OUTPUT)) || + (!in->data1_outbound && (tcp->chain & CHAIN_INPUT))) + { + if (!in->data1_is_range && in->port1_0 == port) + update_iptables_counts(in, tcp, 6); + + else if (!in->data1_is_range && in->port1_1 == port) + update_iptables_counts(in, tcp, 7); + + else if ( in->data1_is_range && in->port1_0 <= port && port <= in->port1_1) + update_iptables_counts(in, tcp, 6); + } + } + } + +void gkrellm_inet_log_tcp_port_data(gpointer data) { GList *list; @@ -167,39 +283,216 @@ gint krell_hit; tcp = (ActiveTCP *) data; + +#if 0 + if (!(tcp->chain & CHAIN_CONNECT)) + show_tcp("gkrellm_inet_log_tcp_port_data", tcp); +#endif + for (list = inet_mon_list; list; list = list->next) { krell_hit = 0; in = (InetMon *) list->data; - if ( (!in->data0_is_range - && ( in->port0_0 == tcp->local_port - || in->port0_1 == tcp->local_port)) - || (in->data0_is_range - && tcp->local_port >= in->port0_0 - && tcp->local_port <= in->port0_1) - ) + + if (tcp->chain & CHAIN_CONNECT) { - ++in->active0; - active_tcp = _log_active_port(tcp); - krell_hit = active_tcp->new_hit; - in->hits0_minute += krell_hit; - in->hits0_hour += krell_hit; - } - if ( (!in->data1_is_range - && ( in->port1_0 == tcp->local_port - || in->port1_1 == tcp->local_port)) - || (in->data1_is_range - && tcp->local_port >= in->port1_0 - && tcp->local_port <= in->port1_1) - ) + if ( (!in->data0_is_range + && ( in->port0_0 == tcp->local_port + || in->port0_1 == tcp->local_port)) + || (in->data0_is_range + && tcp->local_port >= in->port0_0 + && tcp->local_port <= in->port0_1) + ) + { + ++in->active0; + active_tcp = _log_active_port(tcp); + krell_hit = active_tcp->new_hit; + in->hits0_minute += krell_hit; + in->hits0_hour += krell_hit; + } + if ( (!in->data1_is_range + && ( in->port1_0 == tcp->local_port + || in->port1_1 == tcp->local_port)) + || (in->data1_is_range + && tcp->local_port >= in->port1_0 + && tcp->local_port <= in->port1_1) + ) + { + ++in->active1; + active_tcp = _log_active_port(tcp); + krell_hit = active_tcp->new_hit; + in->hits1_minute += krell_hit; + in->hits1_hour += krell_hit; + } + in->krell_hits += krell_hit; + } + else { - ++in->active1; - active_tcp = _log_active_port(tcp); - krell_hit = active_tcp->new_hit; - in->hits1_minute += krell_hit; - in->hits1_hour += krell_hit; +#if 0 + fprintf(stderr, "checking %s dir=%d ports=%ld:%ld range=%d on %s\n", in->label0, in->data0_outbound, in->port0_0, in->port0_1, + in->data0_is_range, in->interface0); + fprintf(stderr, "checking %s dir=%d ports=%ld:%ld range=%d on %s\n", in->label1, in->data1_outbound, in->port1_0, in->port1_1, + in->data1_is_range, in->interface1); +#endif + if ((tcp->target & (TARGET_EST | TARGET_RELATED)) == (TARGET_EST | TARGET_RELATED)) + { + check_iptables_range(in, tcp, PORT_RELEST); + } + else if (tcp->target & TARGET_EST) + { + check_iptables_range(in, tcp, PORT_EST); + } + else if (tcp->target & TARGET_RELATED) + { + check_iptables_range(in, tcp, PORT_RELATED); + } + else if (tcp->target & TARGET_NEW) + { + check_iptables_range(in, tcp, PORT_NEW); + } + + else if (tcp->target & (TARGET_ACCEPT | TARGET_USER)) + { + if (in->data0_outbound) + { +#if 0 +fprintf(stderr, "0: dir=%d ports=%ld:%ld range=%d tcp rem=%d:%d if=%s\n", in->data0_outbound, in->port0_0, in->port0_1, in->data0_is_range, + tcp->remote_port, tcp->remote_port_hi, tcp->interface); +#endif + if (!strcmp(in->interface0, "all") || !strcmp(in->interface0, tcp->interface)) + { + // If the remote IPtables rule is a generic rule, then only matches if user is tracking that specific + // generic range - generally much more useful for local port comparisons if you are running or using a + // service in the unpriviliged port area. + + if ((tcp->remote_port == 0 || tcp->remote_port == 1024) && tcp->remote_port_hi == 65535) + { + if (in->data0_is_range && tcp->remote_port == in->port0_0 && + tcp->remote_port_hi == in->port0_1) + update_iptables_counts(in, tcp, 0); + } + else + { + if (!in->data0_is_range && in->port0_0 && + in->port0_0 >= tcp->remote_port && in->port0_0 <= tcp->remote_port_hi) + update_iptables_counts(in, tcp, 0); + + else if (!in->data0_is_range && in->port0_1 && + in->port0_1 >= tcp->remote_port && in->port0_1 <= tcp->remote_port_hi) + update_iptables_counts(in, tcp, 1); + + else if (in->data0_is_range && !(tcp->remote_port > in->port0_1 || tcp->remote_port_hi < in->port0_0)) + update_iptables_counts(in, tcp, 0); + } + } + } + else + { +#if 0 +fprintf(stderr, "0: dir=%d ports=%ld:%ld range=%d tcp lcl=%d:%d if=%s\n", in->data0_outbound, in->port0_0, in->port0_1, in->data0_is_range, + tcp->local_port, tcp->local_port_hi, tcp->interface); +#endif + if (!strcmp(in->interface0, "all") || !strcmp(in->interface0, tcp->interface)) + { + if ((tcp->local_port == 0 || tcp->local_port == 1024) && tcp->local_port_hi == 65535) + { + if (in->data0_is_range && tcp->local_port == in->port0_0 && + tcp->local_port_hi == in->port0_1) + update_iptables_counts(in, tcp, 2); + } + else + { + if (!in->data0_is_range && in->port0_0 && + in->port0_0 >= tcp->local_port && in->port0_0 <= tcp->local_port_hi) + update_iptables_counts(in, tcp, 2); + + else if (!in->data0_is_range && in->port0_1 && + in->port0_1 >= tcp->local_port && in->port0_1 <= tcp->local_port_hi) + update_iptables_counts(in, tcp, 3); + + else if (in->data0_is_range && !(tcp->local_port > in->port0_1 || tcp->local_port_hi < in->port0_0)) + update_iptables_counts(in, tcp, 2); + } + } + } + + if (in->data1_outbound) + { +#if 0 +fprintf(stderr, "1: dir=%d ports=%ld:%ld range=%d tcp rem=%d:%d,if=%s\n", in->data1_outbound, in->port1_0, in->port1_1, in->data1_is_range, + tcp->remote_port, tcp->remote_port_hi, tcp->interface); +#endif + if (!strcmp(in->interface1, "all") || !strcmp(in->interface1, tcp->interface)) + { + if ((tcp->remote_port == 0 || tcp->remote_port == 1024) && tcp->remote_port_hi == 65535) + { + if (in->data1_is_range && tcp->remote_port == in->port1_0 && + tcp->remote_port_hi == in->port1_1) + update_iptables_counts(in, tcp, 4); + } + else + { + if (!in->data1_is_range && in->port1_0 && + in->port1_0 >= tcp->remote_port && in->port1_0 <= tcp->remote_port_hi) + update_iptables_counts(in, tcp, 4); + + else if (!in->data1_is_range && in->port1_1 && + in->port1_1 >= tcp->remote_port && in->port1_1 <= tcp->remote_port_hi) + update_iptables_counts(in, tcp, 5); + + else if (in->data1_is_range && !(tcp->remote_port > in->port1_1 || tcp->remote_port_hi < in->port1_0)) + update_iptables_counts(in, tcp, 4); + } + } + } + else + { +#if 0 +fprintf(stderr, "1: dir=%d ports=%ld:%ld range=%d tcp lcl=%d:%d if=%s\n", in->data1_outbound, in->port1_0, in->port1_1, in->data1_is_range, + tcp->local_port, tcp->local_port_hi, tcp->interface); +#endif + if (!strcmp(in->interface1, "all") || !strcmp(in->interface1, tcp->interface)) + { + if ((tcp->local_port == 0 || tcp->local_port == 1024) && tcp->local_port_hi == 65535) + { + if (in->data1_is_range && tcp->local_port == in->port1_0 && + tcp->local_port_hi == in->port1_1) + update_iptables_counts(in, tcp, 6); + } + else + { + if (!in->data1_is_range && in->port1_0 && + in->port1_0 >= tcp->local_port && in->port1_0 <= tcp->local_port_hi) + update_iptables_counts(in, tcp, 6); + + else if (!in->data1_is_range && in->port1_1 && + in->port1_1 >= tcp->local_port && in->port1_1 <= tcp->local_port_hi) + update_iptables_counts(in, tcp, 7); + + else if (in->data1_is_range && !(tcp->local_port > in->port1_1 || tcp->local_port_hi < in->port1_0)) + update_iptables_counts(in, tcp, 6); + } + } + } + } + + else if (tcp->target & TARGET_DROP) + { + check_iptables_range(in, tcp, PORT_DROP); + } + else if (tcp->target & TARGET_LOG) + { + check_iptables_range(in, tcp, PORT_LOG); + } + else if (tcp->target & TARGET_QUEUE) + { + check_iptables_range(in, tcp, PORT_QUEUE); + } + else if (tcp->target & TARGET_RETURN) + { + check_iptables_range(in, tcp, PORT_RETURN); + } } - in->krell_hits += krell_hit; } /* Defer setting new hit to 0 until here so multiple inet charts can | monitor the same port number. The above active_port will be the @@ -229,18 +522,19 @@ /* ======================================================================== */ -#define DUMP_IN(in,tag) printf("%s: %s %s %ld %ld %ld %ld\n", \ +#define DUMP_IN(in,tag) printf("%s: %s %s %ld %ld %ld %ld %s %s\n", \ tag, in->label0, in->label1, \ - in->port0_0, in->port0_1, in->port1_0, in->port1_1); + in->port0_0, in->port0_1, in->port1_0, in->port1_1, in->interface0, in->interface1); static void format_chart_text(InetMon *in, gchar *src_string, gchar *buf, gint size) { GList *list; - GkrellmChart *cp; - GkrellmChartdata *cd; + GkrellmChart *cp; + GkrellmChartdata *cd; gchar c, *s, *s1; - gint len, value, n, i, w; + gint len, n, i, w; + gint64 value; if (!buf || size < 1) return; @@ -260,7 +554,20 @@ if ((c = *(s + 1)) == 'M') value = gkrellm_get_chart_scalemax(cp); else if (c == 'a' && *in->label0) - value = in->active0; + { + switch (in->display_mode) + { + case 0: + value = in->active0; + break; + case 1: + value = in->pkts0; + break; + case 2: + value = in->bytes0; + break; + } + } else if (c == 'l' && *in->label0) s1 = in->label0; else if (c == 'c' && *(s + 2)) @@ -268,21 +575,56 @@ i = 0; sscanf(s + 2, "%d%n", &n, &i); s += i; - --n; - if (n > w || n < 0) - n = w; - list = in->hour_mode ? - in->chart_hour->cd_list : in->chart_minute->cd_list; - cd = (GkrellmChartdata *) list->data; + if (*in->label0) { - value = in->hour_mode ? in->hits0_hour : in->hits0_minute; - for ( ; n > 0; --n) - value += gkrellm_get_chartdata_data(cd, w - n); + --n; + if (n > w || n < 0) + n = w; + switch (in->display_mode) + { + case 0: + list = in->hour_mode ? + in->chart_hour->cd_list : in->chart_minute->cd_list; + cd = (GkrellmChartdata *) list->data; + value = in->hour_mode ? in->hits0_hour : in->hits0_minute; + for ( ; n > 0; --n) + value += gkrellm_get_chartdata_data(cd, w - n); + break; + case 1: + list = in->hour_mode ? + in->chart_hour_pkts->cd_list : in->chart_minute_pkts->cd_list; + cd = (GkrellmChartdata *) list->data; + value = in->hour_mode ? in->pkts0_hour : in->pkts0_minute; + for ( ; n > 0; --n) + value += gkrellm_get_chartdata_data(cd, w - n); + break; + case 2: + list = in->hour_mode ? + in->chart_hour_bytes->cd_list : in->chart_minute_bytes->cd_list; + cd = (GkrellmChartdata *) list->data; + value = in->hour_mode ? in->bytes0_hour : in->bytes0_minute; + for ( ; n > 0; --n) + value += gkrellm_get_chartdata_data(cd, w - n); + break; + } } } else if (c == 'A' && *in->label1) - value = in->active1; + { + switch (in->display_mode) + { + case 0: + value = in->active1; + break; + case 1: + value = in->pkts1; + break; + case 2: + value = in->bytes1; + break; + } + } else if (c == 'L' && *in->label1) s1 = in->label1; else if (c == 'C' && *(s + 2)) @@ -290,23 +632,100 @@ i = 0; sscanf(s + 2, "%d%n", &n, &i); s += i; - --n; - if (n > w || n < 0) - n = w; - list = in->hour_mode ? - in->chart_hour->cd_list : in->chart_minute->cd_list; - if (list->next) - list = list->next; - cd = (GkrellmChartdata *) list->data; + if (*in->label1) { - value = in->hour_mode ? in->hits1_hour : in->hits1_minute; - for ( ; n > 0; --n) - value += gkrellm_get_chartdata_data(cd, w - n); + --n; + if (n > w || n < 0) + n = w; + switch (in->display_mode) + { + case 0: + list = in->hour_mode ? + in->chart_hour->cd_list : in->chart_minute->cd_list; + if (list->next) + list = list->next; + cd = (GkrellmChartdata *) list->data; + value = in->hour_mode ? in->hits1_hour : in->hits1_minute; + for ( ; n > 0; --n) + value += gkrellm_get_chartdata_data(cd, w - n); + break; + case 1: + list = in->hour_mode ? + in->chart_hour_pkts->cd_list : in->chart_minute_pkts->cd_list; + if (list->next) + list = list->next; + cd = (GkrellmChartdata *) list->data; + value = in->hour_mode ? in->pkts1_hour : in->pkts1_minute; + for ( ; n > 0; --n) + value += gkrellm_get_chartdata_data(cd, w - n); + break; + case 2: + list = in->hour_mode ? + in->chart_hour_bytes->cd_list : in->chart_minute_bytes->cd_list; + if (list->next) + list = list->next; + cd = (GkrellmChartdata *) list->data; + value = in->hour_mode ? in->bytes1_hour : in->bytes1_minute; + for ( ; n > 0; --n) + value += gkrellm_get_chartdata_data(cd, w - n); + break; + } } } + if (value >= 0) - len = snprintf(buf, size, "%d", value); + { + gint index = 0; + gdouble svalue = 0; + char *vsuffix = " kMGTPEYZ"; + if (value < 1e3) + { + index = 0; + svalue = value; + } + else if (value < 1e6) + { + index = 1; + svalue = value / 1e3; + } + else if (value < 1e9) + { + index = 2; + svalue = value / 1e6; + } + else if (value < 1e12) + { + index = 3; + svalue = value / 1e9; + } + else if (value < 1e15) + { + index = 4; + svalue = value / 1e12; + } + else if (value < 1e18) + { + index = 5; + svalue = value / 1e15; + } + else if (value < 1e21) + { + index = 6; + svalue = value / 1e18; + } + else if (value < 1e24) + { + index = 7; + svalue = value / 1e21; + } + else + { + index = 8; + svalue = value / 1e24; + } + len = snprintf(buf, size, "%.3lg%c", svalue, *(vsuffix+index)); + } else len = snprintf(buf, size, "%s", s1); ++s; @@ -430,7 +849,7 @@ strftime(buf, sizeof(buf), "%a", &tm); buf[1] = '\0'; gkrellm_draw_chart_label(in->chart, ts, - cp->x + n, in->chart->h - 4, buf); + cp->x + n, in->chart->h - 12, buf); } if (--tm.tm_hour < 0) { @@ -471,28 +890,102 @@ draw_inet_extra(in); gkrellm_draw_chart_to_screen(cp); in->prev_active0 = in->active0; + in->prev_pkts0 = in->pkts0; + in->prev_bytes0 = in->bytes0; in->prev_active1 = in->active1; + in->prev_pkts1 = in->pkts1; + in->prev_bytes1 = in->bytes1; } static void select_hour_or_minute_chart(InetMon *in) { gkrellm_freeze_side_frame_packing(); - if (in->hour_mode && in->chart == in->chart_minute) + gkrellm_chartconfig_window_destroy(in->chart); + + if (in->hour_mode) { - gkrellm_chart_hide(in->chart_minute, FALSE); - gkrellm_chart_show(in->chart_hour, FALSE); - in->chart = in->chart_hour; - gkrellm_chartconfig_window_destroy(in->chart_minute); + switch (in->display_mode) + { + case 0: + gkrellm_chart_hide(in->chart_minute_bytes, FALSE); + gkrellm_chart_hide(in->chart_hour_bytes, FALSE); + gkrellm_chart_hide(in->chart_minute_pkts, FALSE); + gkrellm_chart_hide(in->chart_hour_pkts, FALSE); + gkrellm_chart_hide(in->chart_minute, FALSE); + gkrellm_chart_show(in->chart_hour, FALSE); + in->chart = in->chart_hour; + break; + case 1: + gkrellm_chart_hide(in->chart_minute, FALSE); + gkrellm_chart_hide(in->chart_hour, FALSE); + gkrellm_chart_hide(in->chart_minute_bytes, FALSE); + gkrellm_chart_hide(in->chart_hour_bytes, FALSE); + gkrellm_chart_hide(in->chart_minute_pkts, FALSE); + gkrellm_chart_show(in->chart_hour_pkts, FALSE); + in->chart = in->chart_hour_pkts; + break; + case 2: + gkrellm_chart_hide(in->chart_minute_pkts, FALSE); + gkrellm_chart_hide(in->chart_hour_pkts, FALSE); + gkrellm_chart_hide(in->chart_minute, FALSE); + gkrellm_chart_hide(in->chart_hour, FALSE); + gkrellm_chart_hide(in->chart_minute_bytes, FALSE); + gkrellm_chart_show(in->chart_hour_bytes, FALSE); + in->chart = in->chart_hour_bytes; + break; + } } - else if (!in->hour_mode && in->chart == in->chart_hour) + else { - gkrellm_chart_hide(in->chart_hour, FALSE); - gkrellm_chart_show(in->chart_minute, FALSE); - in->chart = in->chart_minute; - gkrellm_chartconfig_window_destroy(in->chart_hour); + switch (in->display_mode) + { + case 0: + gkrellm_chart_hide(in->chart_hour_bytes, FALSE); + gkrellm_chart_hide(in->chart_minute_bytes, FALSE); + gkrellm_chart_hide(in->chart_hour_pkts, FALSE); + gkrellm_chart_hide(in->chart_minute_pkts, FALSE); + gkrellm_chart_hide(in->chart_hour, FALSE); + gkrellm_chart_show(in->chart_minute, FALSE); + in->chart = in->chart_minute; + break; + case 1: + gkrellm_chart_hide(in->chart_hour, FALSE); + gkrellm_chart_hide(in->chart_minute, FALSE); + gkrellm_chart_hide(in->chart_hour_bytes, FALSE); + gkrellm_chart_hide(in->chart_minute_bytes, FALSE); + gkrellm_chart_hide(in->chart_hour_pkts, FALSE); + gkrellm_chart_show(in->chart_minute_pkts, FALSE); + in->chart = in->chart_minute_pkts; + break; + case 2: + gkrellm_chart_hide(in->chart_hour_pkts, FALSE); + gkrellm_chart_hide(in->chart_minute_pkts, FALSE); + gkrellm_chart_hide(in->chart_hour, FALSE); + gkrellm_chart_hide(in->chart_minute, FALSE); + gkrellm_chart_hide(in->chart_hour_bytes, FALSE); + gkrellm_chart_show(in->chart_minute_bytes, FALSE); + in->chart = in->chart_minute_bytes; + break; + } } gkrellm_thaw_side_frame_packing(); + + // Set them up as overlays of the main chart + + if (in->chart != in->chart_minute) + in->chart_minute->overlay = in->chart; + if (in->chart != in->chart_hour) + in->chart_hour->overlay = in->chart; + if (in->chart != in->chart_minute_pkts) + in->chart_minute_pkts->overlay = in->chart; + if (in->chart != in->chart_hour_pkts) + in->chart_hour_pkts->overlay = in->chart; + if (in->chart != in->chart_minute_bytes) + in->chart_minute_bytes->overlay = in->chart; + if (in->chart != in->chart_hour_bytes) + in->chart_hour_bytes->overlay = in->chart; + in->chart->overlay = NULL; } static void @@ -515,7 +1008,11 @@ { in = (InetMon *) list->data; in->active0 = 0; + in->pkts0 = 0; + in->bytes0 = 0; in->active1 = 0; + in->pkts1 = 0; + in->bytes1 = 0; } /* Assume all connections are dead, then read_tcp_data() will set | still alive ones back to alive. Then I can prune really dead ones. @@ -552,34 +1049,66 @@ if (GK.hour_tick) { if (!*in->label0) + { in->hits0_hour = in->hits1_hour; + in->pkts0_hour = in->pkts1_hour; + in->bytes0_hour = in->bytes1_hour; + } gkrellm_store_chartdata(in->chart_hour, 0, in->hits0_hour, in->hits1_hour); + gkrellm_store_chartdata(in->chart_hour_pkts, 0, + in->pkts0_hour, in->pkts1_hour); + gkrellm_store_chartdata(in->chart_hour_bytes, 0, + in->bytes0_hour, in->bytes1_hour); in->hits0_hour = in->hits1_hour = 0; + in->pkts0_hour = in->pkts1_hour = 0; + in->bytes0_hour = in->bytes1_hour = 0; if (GK.day_tick) /* Make room for vertical day grid */ { - gkrellm_store_chartdata(in->chart_hour, 0, 0, 0); - gkrellm_store_chartdata(in->chart_hour, 0, 0, 0); + gkrellm_store_chartdata(in->chart_hour, 0, 0ULL, 0ULL); + gkrellm_store_chartdata(in->chart_hour, 0, 0ULL, 0ULL); + gkrellm_store_chartdata(in->chart_hour_pkts, 0, 0ULL, 0ULL); + gkrellm_store_chartdata(in->chart_hour_pkts, 0, 0ULL, 0ULL); + gkrellm_store_chartdata(in->chart_hour_bytes, 0, 0ULL, 0ULL); + gkrellm_store_chartdata(in->chart_hour_bytes, 0, 0ULL, 0ULL); } } if (GK.minute_tick) { if (!*in->label0) + { in->hits0_minute = in->hits1_minute; + in->pkts0_minute = in->pkts1_minute; + in->bytes0_minute = in->bytes1_minute; + } gkrellm_store_chartdata(in->chart_minute, 0, in->hits0_minute, in->hits1_minute); + gkrellm_store_chartdata(in->chart_minute_pkts, 0, + in->pkts0_minute, in->pkts1_minute); + gkrellm_store_chartdata(in->chart_minute_bytes, 0, + in->bytes0_minute, in->bytes1_minute); in->hits0_minute = in->hits1_minute = 0; + in->pkts0_minute = in->pkts1_minute = 0; + in->bytes0_minute = in->bytes1_minute = 0; if (GK.hour_tick) /* Make room for vertical hour grid */ { - gkrellm_store_chartdata(in->chart_minute, 0, 0, 0); - gkrellm_store_chartdata(in->chart_minute, 0, 0, 0); + gkrellm_store_chartdata(in->chart_minute, 0, 0ULL, 0ULL); + gkrellm_store_chartdata(in->chart_minute, 0, 0ULL, 0ULL); + gkrellm_store_chartdata(in->chart_minute_pkts, 0, 0ULL, 0ULL); + gkrellm_store_chartdata(in->chart_minute_pkts, 0, 0ULL, 0ULL); + gkrellm_store_chartdata(in->chart_minute_bytes, 0, 0ULL, 0ULL); + gkrellm_store_chartdata(in->chart_minute_bytes, 0, 0ULL, 0ULL); } gkrellm_refresh_chart(in->chart); draw_inet_mark_data(in, 1); } else if ( GK.second_tick - && ( in->prev_active0 != in->active0 - || in->prev_active1 != in->active1 + && ( (in->display_mode == 0 && (in->prev_active0 != in->active0 + || in->prev_active1 != in->active1)) || + (in->display_mode == 1 && (in->prev_pkts0 != in->pkts0 + || in->prev_pkts1 != in->pkts1)) || + (in->display_mode == 2 && (in->prev_bytes0 != in->bytes0 + || in->prev_bytes1 != in->bytes1)) ) ) draw_inet_chart(in); /* Just to update extra info draw */ @@ -593,7 +1122,19 @@ i = D_MISC_BUTTON_OUT; gkrellm_set_decal_button_index(in->list_button, i); - gkrellm_update_krell(in->panel, KRELL(in->panel), in->krell_hits); + switch (in->display_mode) + { + case 0: + gkrellm_update_krell(in->panel, KRELL(in->panel), in->krell_hits); + break; + case 1: + gkrellm_update_krell(in->panel, KRELL(in->panel), in->krell_pkts); + break; + case 2: + gkrellm_update_krell(in->panel, KRELL(in->panel), in->krell_bytes); + break; + } + gkrellm_draw_panel_layers(in->panel); if (in->connection_string_event) @@ -698,7 +1239,7 @@ static void cb_list_button(GkrellmDecalbutton *button) - { + { InetMon *in = (InetMon *) button->data; GList *list; ActiveTCP *tcp, *tcp_save; @@ -743,6 +1284,16 @@ pixmap = in->chart_minute->pixmap; else if (widget == in->chart_hour->drawing_area) pixmap = in->chart_hour->pixmap; + + else if (widget == in->chart_minute_pkts->drawing_area) + pixmap = in->chart_minute_pkts->pixmap; + else if (widget == in->chart_hour_pkts->drawing_area) + pixmap = in->chart_hour_pkts->pixmap; + + else if (widget == in->chart_minute_bytes->drawing_area) + pixmap = in->chart_minute_bytes->pixmap; + else if (widget == in->chart_hour_bytes->drawing_area) + pixmap = in->chart_hour_bytes->pixmap; if (pixmap) { gdk_draw_drawable(widget->window, gkrellm_draw_GC(1), pixmap, @@ -754,6 +1305,33 @@ return FALSE; } +static void +display_new_chart(InetMon *in, gint retitle_panel) + { + if (retitle_panel && in->name) + { + gchar *vtype = "HPB"; + gchar *tstr; + + if (strncmp(in->name, "H-", 2) == 0 || strncmp(in->name, "P-", 2) == 0 || strncmp(in->name, "B-", 2) == 0) + { + tstr = g_strdup_printf(_("%c-%s"), *(vtype+in->display_mode), in->name + 2); + } + else + { + tstr = g_strdup_printf(_("%c-%s"), *(vtype+in->display_mode), in->name); + } + g_free(in->name); + in->name = tstr; + gkrellm_panel_configure(in->panel, in->name, gkrellm_panel_style(style_id)); + gkrellm_draw_panel_label(in->panel); + } + + select_hour_or_minute_chart(in); + gkrellm_rescale_chart(in->chart); + gkrellm_config_modified(); + } + static gint cb_inet_extra(GtkWidget *widget, GdkEventButton *ev) { @@ -765,21 +1343,70 @@ in = (InetMon *) list->data; if (widget != in->chart->drawing_area) continue; - if (ev->button == 1 && ev->type == GDK_BUTTON_PRESS) + + // Alt button moves to the previous type without changing the text presence or absence + + if (ev->button == 1 && (ev->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) == (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) { - in->extra_info = !in->extra_info; - gkrellm_refresh_chart(in->chart); - gkrellm_config_modified(); + if (--in->display_mode < 0) + in->display_mode = 2; + display_new_chart(in, 1); + } + + // Control button one moves to the next type without changing the text presence or absence + + else if (ev->button == 1 && (ev->state & GDK_CONTROL_MASK)) + { + if (++in->display_mode == 3) + in->display_mode = 0; + display_new_chart(in, 1); + } + + // Shift button one moves back in the sequence + + else if (ev->button == 1 && (ev->state & GDK_SHIFT_MASK)) + { + if (in->extra_info) + { + in->extra_info = FALSE; + display_new_chart(in, 0); + } + else + { + in->extra_info = TRUE; + if (--in->display_mode < 0) + in->display_mode = 2; + display_new_chart(in, 1); + } + } + + // Normal button one moves ahead in the sequence + + else if (ev->button == 1 && ev->type == GDK_BUTTON_PRESS) + { + if (in->extra_info) + { + in->extra_info = FALSE; + if (++in->display_mode == 3) + in->display_mode = 0; + display_new_chart(in, 1); + } + else + { + in->extra_info = TRUE; + display_new_chart(in, 0); + } } + + // Button 2 switches the hour and minute setting + else if (ev->button == 2) { in->hour_mode = !in->hour_mode; - select_hour_or_minute_chart(in); - gkrellm_rescale_chart(in->chart); + display_new_chart(in, 0); } - else if ( ev->button == 3 - || (ev->button == 1 && ev->type == GDK_2BUTTON_PRESS) - ) + + else if (ev->button == 3) gkrellm_chartconfig_window_create(in->chart); break; } @@ -797,6 +1424,479 @@ /* Lock the hour and minute heights together. */ static void +cb_inet_draw_style(GkrellmChartdata *cd, InetMon *in) + { + gint h; + GList *list; + GkrellmChartdata *td; + + h = gkrellm_get_chartdata_draw_style(cd); + + // User changed inet0 - change inet0's of other's of this type + + if (cd == in->chart_minute->cd_list->data || + cd == in->chart_hour->cd_list->data || + cd == in->chart_minute_pkts->cd_list->data || + cd == in->chart_hour_pkts->cd_list->data || + cd == in->chart_minute_bytes->cd_list->data || + cd == in->chart_hour_bytes->cd_list->data) + { + list = in->chart_minute->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_draw_style(td) != h) + gkrellm_set_chartdata_draw_style(td, h); + + list = in->chart_hour->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_draw_style(td) != h) + gkrellm_set_chartdata_draw_style(td, h); + + list = in->chart_minute_pkts->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_draw_style(td) != h) + gkrellm_set_chartdata_draw_style(td, h); + + list = in->chart_hour_pkts->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_draw_style(td) != h) + gkrellm_set_chartdata_draw_style(td, h); + + list = in->chart_minute_bytes->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_draw_style(td) != h) + gkrellm_set_chartdata_draw_style(td, h); + + list = in->chart_hour_bytes->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_draw_style(td) != h) + gkrellm_set_chartdata_draw_style(td, h); + } + else + { + list = in->chart_minute->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_draw_style(td) != h) + gkrellm_set_chartdata_draw_style(td, h); + + list = in->chart_hour->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_draw_style(td) != h) + gkrellm_set_chartdata_draw_style(td, h); + + list = in->chart_minute_pkts->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_draw_style(td) != h) + gkrellm_set_chartdata_draw_style(td, h); + + list = in->chart_hour_pkts->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_draw_style(td) != h) + gkrellm_set_chartdata_draw_style(td, h); + + list = in->chart_minute_bytes->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_draw_style(td) != h) + gkrellm_set_chartdata_draw_style(td, h); + + list = in->chart_hour_bytes->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_draw_style(td) != h) + gkrellm_set_chartdata_draw_style(td, h); + } + } + +static void +cb_inet_inverted(GkrellmChartdata *cd, InetMon *in) + { + gint h; + GList *list; + GkrellmChartdata *td; + + h = gkrellm_get_chartdata_inverted(cd); + + // User changed inet0 - change inet0's of other's of this type + if (cd == in->chart_minute->cd_list->data || + cd == in->chart_hour->cd_list->data || + cd == in->chart_minute_pkts->cd_list->data || + cd == in->chart_hour_pkts->cd_list->data || + cd == in->chart_minute_bytes->cd_list->data || + cd == in->chart_hour_bytes->cd_list->data) + { + list = in->chart_minute->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_inverted(td) != h) + gkrellm_set_chartdata_inverted(td, h); + + list = in->chart_hour->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_inverted(td) != h) + gkrellm_set_chartdata_inverted(td, h); + + list = in->chart_minute_pkts->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_inverted(td) != h) + gkrellm_set_chartdata_inverted(td, h); + + list = in->chart_hour_pkts->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_inverted(td) != h) + gkrellm_set_chartdata_inverted(td, h); + + list = in->chart_minute_bytes->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_inverted(td) != h) + gkrellm_set_chartdata_inverted(td, h); + + list = in->chart_hour_bytes->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_inverted(td) != h) + gkrellm_set_chartdata_inverted(td, h); + } + else + { + list = in->chart_minute->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_inverted(td) != h) + gkrellm_set_chartdata_inverted(td, h); + + list = in->chart_hour->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_inverted(td) != h) + gkrellm_set_chartdata_inverted(td, h); + + list = in->chart_minute_pkts->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_inverted(td) != h) + gkrellm_set_chartdata_inverted(td, h); + + list = in->chart_hour_pkts->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_inverted(td) != h) + gkrellm_set_chartdata_inverted(td, h); + + list = in->chart_minute_bytes->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_inverted(td) != h) + gkrellm_set_chartdata_inverted(td, h); + + list = in->chart_hour_bytes->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_inverted(td) != h) + gkrellm_set_chartdata_inverted(td, h); + } + } + +static void +cb_inet_split_chart(GkrellmChartdata *cd, InetMon *in) + { + gint h; + GList *list; + GkrellmChartdata *td; + + h = gkrellm_get_chartdata_split_chart(cd); + + // User changed inet0 - change inet0's of other's of this type + if (cd == in->chart_minute->cd_list->data || + cd == in->chart_hour->cd_list->data || + cd == in->chart_minute_pkts->cd_list->data || + cd == in->chart_hour_pkts->cd_list->data || + cd == in->chart_minute_bytes->cd_list->data || + cd == in->chart_hour_bytes->cd_list->data) + { + list = in->chart_minute->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_chart(td) != h) + gkrellm_set_chartdata_split_chart(td, h); + + list = in->chart_hour->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_chart(td) != h) + gkrellm_set_chartdata_split_chart(td, h); + + list = in->chart_minute_pkts->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_chart(td) != h) + gkrellm_set_chartdata_split_chart(td, h); + + list = in->chart_hour_pkts->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_chart(td) != h) + gkrellm_set_chartdata_split_chart(td, h); + + list = in->chart_minute_bytes->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_chart(td) != h) + gkrellm_set_chartdata_split_chart(td, h); + + list = in->chart_hour_bytes->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_chart(td) != h) + gkrellm_set_chartdata_split_chart(td, h); + } + else + { + list = in->chart_minute->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_chart(td) != h) + gkrellm_set_chartdata_split_chart(td, h); + + list = in->chart_hour->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_chart(td) != h) + gkrellm_set_chartdata_split_chart(td, h); + + list = in->chart_minute_pkts->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_chart(td) != h) + gkrellm_set_chartdata_split_chart(td, h); + + list = in->chart_hour_pkts->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_chart(td) != h) + gkrellm_set_chartdata_split_chart(td, h); + + list = in->chart_minute_bytes->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_chart(td) != h) + gkrellm_set_chartdata_split_chart(td, h); + + list = in->chart_hour_bytes->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_chart(td) != h) + gkrellm_set_chartdata_split_chart(td, h); + } + } + +static void +cb_inet_split_fraction(GkrellmChartdata *cd, InetMon *in) + { + gfloat h; + GList *list; + GkrellmChartdata *td; + + h = gkrellm_get_chartdata_split_fraction(cd); + + // User changed inet0 - change inet0's of other's of this type + if (cd == in->chart_minute->cd_list->data || + cd == in->chart_hour->cd_list->data || + cd == in->chart_minute_pkts->cd_list->data || + cd == in->chart_hour_pkts->cd_list->data || + cd == in->chart_minute_bytes->cd_list->data || + cd == in->chart_hour_bytes->cd_list->data) + { + list = in->chart_minute->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_fraction(td) != h) + gkrellm_set_chartdata_split_fraction(td, h); + + list = in->chart_hour->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_fraction(td) != h) + gkrellm_set_chartdata_split_fraction(td, h); + + list = in->chart_minute_pkts->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_fraction(td) != h) + gkrellm_set_chartdata_split_fraction(td, h); + + list = in->chart_hour_pkts->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_fraction(td) != h) + gkrellm_set_chartdata_split_fraction(td, h); + + list = in->chart_minute_bytes->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_fraction(td) != h) + gkrellm_set_chartdata_split_fraction(td, h); + + list = in->chart_hour_bytes->cd_list; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_fraction(td) != h) + gkrellm_set_chartdata_split_fraction(td, h); + } + else + { + list = in->chart_minute->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_fraction(td) != h) + gkrellm_set_chartdata_split_fraction(td, h); + + list = in->chart_hour->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_fraction(td) != h) + gkrellm_set_chartdata_split_fraction(td, h); + + list = in->chart_minute_pkts->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_fraction(td) != h) + gkrellm_set_chartdata_split_fraction(td, h); + + list = in->chart_hour_pkts->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_fraction(td) != h) + gkrellm_set_chartdata_split_fraction(td, h); + + list = in->chart_minute_bytes->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_fraction(td) != h) + gkrellm_set_chartdata_split_fraction(td, h); + + list = in->chart_hour_bytes->cd_list; + if (list->next) + list = list->next; + td = (GkrellmChartdata *) list->data; + if (gkrellm_get_chartdata_split_fraction(td) != h) + gkrellm_set_chartdata_split_fraction(td, h); + } + } + +static void +cb_inet_grid_resolution(GkrellmChartconfig *cf, InetMon *in) + { + gint h; + + h = gkrellm_get_chartconfig_grid_resolution(cf); + if (in->chart_config_minute->grid_resolution != h) + gkrellm_set_chartconfig_grid_resolution(in->chart_config_minute, h); + if (in->chart_config_hour->grid_resolution != h) + gkrellm_set_chartconfig_grid_resolution(in->chart_config_hour, h); + if (in->chart_config_minute_pkts->grid_resolution != h) + gkrellm_set_chartconfig_grid_resolution(in->chart_config_minute_pkts, h); + if (in->chart_config_hour_pkts->grid_resolution != h) + gkrellm_set_chartconfig_grid_resolution(in->chart_config_hour_pkts, h); + if (in->chart_config_minute_bytes->grid_resolution != h) + gkrellm_set_chartconfig_grid_resolution(in->chart_config_minute_bytes, h); + if (in->chart_config_hour_bytes->grid_resolution != h) + gkrellm_set_chartconfig_grid_resolution(in->chart_config_hour_bytes, h); + } + +static void +cb_inet_auto_grid_resolution(GkrellmChartconfig *cf, InetMon *in) + { + gboolean h; + + h = gkrellm_get_chartconfig_auto_grid_resolution(cf); + if (in->chart_config_minute->auto_grid_resolution != h) + gkrellm_set_chartconfig_auto_grid_resolution(in->chart_config_minute, h); + if (in->chart_config_hour->auto_grid_resolution != h) + gkrellm_set_chartconfig_auto_grid_resolution(in->chart_config_hour, h); + if (in->chart_config_minute_pkts->auto_grid_resolution != h) + gkrellm_set_chartconfig_auto_grid_resolution(in->chart_config_minute_pkts, h); + if (in->chart_config_hour_pkts->auto_grid_resolution != h) + gkrellm_set_chartconfig_auto_grid_resolution(in->chart_config_hour_pkts, h); + if (in->chart_config_minute_bytes->auto_grid_resolution != h) + gkrellm_set_chartconfig_auto_grid_resolution(in->chart_config_minute_bytes, h); + if (in->chart_config_hour_bytes->auto_grid_resolution != h) + gkrellm_set_chartconfig_auto_grid_resolution(in->chart_config_hour_bytes, h); + } + +static void +cb_inet_auto_resolution_stick(GkrellmChartconfig *cf, InetMon *in) + { + gboolean h; + + h = gkrellm_get_chartconfig_auto_resolution_stick(cf); + if (in->chart_config_minute->auto_resolution_stick != h) + gkrellm_set_chartconfig_auto_resolution_stick(in->chart_config_minute, h); + if (in->chart_config_hour->auto_resolution_stick != h) + gkrellm_set_chartconfig_auto_resolution_stick(in->chart_config_hour, h); + if (in->chart_config_minute_pkts->auto_resolution_stick != h) + gkrellm_set_chartconfig_auto_resolution_stick(in->chart_config_minute_pkts, h); + if (in->chart_config_hour_pkts->auto_resolution_stick != h) + gkrellm_set_chartconfig_auto_resolution_stick(in->chart_config_hour_pkts, h); + if (in->chart_config_minute_bytes->auto_resolution_stick != h) + gkrellm_set_chartconfig_auto_resolution_stick(in->chart_config_minute_bytes, h); + if (in->chart_config_hour_bytes->auto_resolution_stick != h) + gkrellm_set_chartconfig_auto_resolution_stick(in->chart_config_hour_bytes, h); + } + +static void +cb_inet_sequence_125(GkrellmChartconfig *cf, InetMon *in) + { + gboolean h; + + h = gkrellm_get_chartconfig_sequence_125(cf); + if (in->chart_config_minute->sequence_125 != h) + gkrellm_set_chartconfig_sequence_125(in->chart_config_minute, h); + if (in->chart_config_hour->sequence_125 != h) + gkrellm_set_chartconfig_sequence_125(in->chart_config_hour, h); + if (in->chart_config_minute_pkts->sequence_125 != h) + gkrellm_set_chartconfig_sequence_125(in->chart_config_minute_pkts, h); + if (in->chart_config_hour_pkts->sequence_125 != h) + gkrellm_set_chartconfig_sequence_125(in->chart_config_hour_pkts, h); + if (in->chart_config_minute_bytes->sequence_125 != h) + gkrellm_set_chartconfig_sequence_125(in->chart_config_minute_bytes, h); + if (in->chart_config_hour_bytes->sequence_125 != h) + gkrellm_set_chartconfig_sequence_125(in->chart_config_hour_bytes, h); + } + +static void +cb_inet_fixed_grids(GkrellmChartconfig *cf, InetMon *in) + { + gint h; + + h = gkrellm_get_chartconfig_fixed_grids(cf); + if (in->chart_config_minute->fixed_grids != h) + gkrellm_set_chartconfig_fixed_grids(in->chart_config_minute, h); + if (in->chart_config_hour->fixed_grids != h) + gkrellm_set_chartconfig_fixed_grids(in->chart_config_hour, h); + if (in->chart_config_minute_pkts->fixed_grids != h) + gkrellm_set_chartconfig_fixed_grids(in->chart_config_minute_pkts, h); + if (in->chart_config_hour_pkts->fixed_grids != h) + gkrellm_set_chartconfig_fixed_grids(in->chart_config_hour_pkts, h); + if (in->chart_config_minute_bytes->fixed_grids != h) + gkrellm_set_chartconfig_fixed_grids(in->chart_config_minute_bytes, h); + if (in->chart_config_hour_bytes->fixed_grids != h) + gkrellm_set_chartconfig_fixed_grids(in->chart_config_hour_bytes, h); + } + +static void cb_inet_height(GkrellmChartconfig *cf, InetMon *in) { gint h; @@ -806,6 +1906,14 @@ gkrellm_set_chart_height(in->chart_minute, h); if (in->chart_hour->h != h) gkrellm_set_chart_height(in->chart_hour, h); + if (in->chart_minute_pkts->h != h) + gkrellm_set_chart_height(in->chart_minute_pkts, h); + if (in->chart_hour_pkts->h != h) + gkrellm_set_chart_height(in->chart_hour_pkts, h); + if (in->chart_minute_bytes->h != h) + gkrellm_set_chart_height(in->chart_minute_bytes, h); + if (in->chart_hour_bytes->h != h) + gkrellm_set_chart_height(in->chart_hour_bytes, h); } static void @@ -816,17 +1924,31 @@ g_free(in->name); g_free(in->label0); g_free(in->label1); + g_free(in->interface0); + g_free(in->interface1); if (in->launch.command) g_free(in->launch.command); if (in->launch.button) gkrellm_destroy_button(in->launch.button); - in->launch.tooltip = NULL; + in->launch.tooltip = NULL; g_free(in->mark_data); /* The panel doesn't live in the chart struct, so destroy it separately */ gkrellm_panel_destroy(in->panel); + gkrellm_chartconfig_destroy(&in->chart_config_minute_bytes); + gkrellm_chart_destroy(in->chart_minute_bytes); + + gkrellm_chartconfig_destroy(&in->chart_config_hour_bytes); + gkrellm_chart_destroy(in->chart_hour_bytes); + + gkrellm_chartconfig_destroy(&in->chart_config_minute_pkts); + gkrellm_chart_destroy(in->chart_minute_pkts); + + gkrellm_chartconfig_destroy(&in->chart_config_hour_pkts); + gkrellm_chart_destroy(in->chart_hour_pkts); + gkrellm_chartconfig_destroy(&in->chart_config_minute); gkrellm_chart_destroy(in->chart_minute); @@ -864,6 +1986,10 @@ { cd = gkrellm_add_chartdata(cp, src_pixmap, grid_pixmap, in->label0); gkrellm_monotonic_chartdata(cd, FALSE); + gkrellm_chartdata_draw_style_connect(cd, cb_inet_draw_style, in); + gkrellm_chartdata_inverted_connect(cd, cb_inet_inverted, in); + gkrellm_chartdata_split_chart_connect(cd, cb_inet_split_chart, in); + gkrellm_chartdata_split_fraction_connect(cd, cb_inet_split_fraction, in); } src_pixmap = gkrellm_data_in_pixmap(); grid_pixmap = gkrellm_data_in_grid_pixmap(); @@ -871,6 +1997,10 @@ { cd = gkrellm_add_chartdata(cp, src_pixmap, grid_pixmap, in->label1); gkrellm_monotonic_chartdata(cd, FALSE); + gkrellm_chartdata_draw_style_connect(cd, cb_inet_draw_style, in); + gkrellm_chartdata_inverted_connect(cd, cb_inet_inverted, in); + gkrellm_chartdata_split_chart_connect(cd, cb_inet_split_chart, in); + gkrellm_chartdata_split_fraction_connect(cd, cb_inet_split_fraction, in); } gkrellm_set_draw_chart_function(cp, draw_inet_chart, in); @@ -878,6 +2008,12 @@ | in connecting to grid or resolution changes. */ gkrellm_chartconfig_height_connect(cf, cb_inet_height, in); + gkrellm_chartconfig_fixed_grids_connect(cf, cb_inet_fixed_grids, in); + gkrellm_chartconfig_auto_grid_resolution_connect(cf, cb_inet_auto_grid_resolution, in); + gkrellm_chartconfig_grid_resolution_connect(cf, cb_inet_grid_resolution, in); + gkrellm_chartconfig_auto_resolution_stick_connect(cf, cb_inet_auto_resolution_stick, in); + gkrellm_chartconfig_sequence_125_connect(cf, cb_inet_sequence_125, in); + gkrellm_chartconfig_grid_resolution_adjustment(cf, TRUE, 0, (gfloat) MIN_GRID_RES, (gfloat) MAX_GRID_RES, 0, 0, 0, 70); if (gkrellm_get_chartconfig_grid_resolution(cf) < MIN_GRID_RES) @@ -915,9 +2051,14 @@ in->vbox = vbox; in->chart_minute = gkrellm_chart_new0(); in->chart_hour = gkrellm_chart_new0(); + in->chart_minute_pkts = gkrellm_chart_new0(); + in->chart_hour_pkts = gkrellm_chart_new0(); + in->chart_minute_bytes = gkrellm_chart_new0(); + in->chart_hour_bytes = gkrellm_chart_new0(); in->panel = gkrellm_panel_new0(); in->chart = in->chart_minute; - in->name = g_strdup_printf(_("inet%d"), n_inet_monitors++); + if (!in->name) + in->name = g_strdup_printf(_("inet%d"), n_inet_monitors++); } else { @@ -925,14 +2066,40 @@ gkrellm_destroy_decal_list(in->panel); gkrellm_destroy_krell_list(in->panel); } + if (in->chart_config_hour && in->chart_config_minute) in->chart_config_hour->h = in->chart_config_minute->h; + + if (in->chart_config_minute_pkts && in->chart_config_minute) + in->chart_config_minute_pkts->h = in->chart_config_minute->h; + if (in->chart_config_hour_pkts && in->chart_config_minute) + in->chart_config_hour_pkts->h = in->chart_config_minute->h; + + if (in->chart_config_minute_bytes && in->chart_config_minute) + in->chart_config_minute_bytes->h = in->chart_config_minute->h; + if (in->chart_config_hour_bytes && in->chart_config_minute) + in->chart_config_hour_bytes->h = in->chart_config_minute->h; + chart_create(in, in->chart_minute, &in->chart_config_minute, first_create); gkrellm_chartconfig_grid_resolution_label(in->chart_config_minute, _("TCP hits per minute")); chart_create(in, in->chart_hour, &in->chart_config_hour, first_create); gkrellm_chartconfig_grid_resolution_label(in->chart_config_hour, _("TCP hits per hour")); + + chart_create(in, in->chart_minute_pkts, &in->chart_config_minute_pkts, first_create); + gkrellm_chartconfig_grid_resolution_label(in->chart_config_minute_pkts, + _("Packets per minute")); + chart_create(in, in->chart_hour_pkts, &in->chart_config_hour_pkts, first_create); + gkrellm_chartconfig_grid_resolution_label(in->chart_config_hour_pkts, + _("Packets per hour")); + + chart_create(in, in->chart_minute_bytes, &in->chart_config_minute_bytes, first_create); + gkrellm_chartconfig_grid_resolution_label(in->chart_config_minute_bytes, + _("Bytes per minute")); + chart_create(in, in->chart_hour_bytes, &in->chart_config_hour_bytes, first_create); + gkrellm_chartconfig_grid_resolution_label(in->chart_config_hour_bytes, + _("Bytes per hour")); cp = in->chart; p = in->panel; @@ -972,7 +2139,11 @@ G_CALLBACK(cb_panel_press), NULL); gtk_widget_show(vbox); + gkrellm_chart_hide(in->chart_minute_pkts, FALSE); + gkrellm_chart_hide(in->chart_minute_bytes, FALSE); gkrellm_chart_hide(in->chart_hour, FALSE); + gkrellm_chart_hide(in->chart_hour_pkts, FALSE); + gkrellm_chart_hide(in->chart_hour_bytes, FALSE); } gkrellm_setup_launcher(p, &in->launch, CHART_PANEL_TYPE, 4); @@ -981,7 +2152,10 @@ in->mark_data = g_new0(gshort, cp->w); if (! first_create) + { + select_hour_or_minute_chart(in); gkrellm_rescale_chart(in->chart); + } } static void @@ -1039,7 +2213,7 @@ GList *list; InetMon *in; gchar buf[128]; - gchar *l0, *l1; + gchar *l0, *l1, *i0, *i1; gint i; for (i = 0, list = inet_mon_list; list; list = list->next, ++i) @@ -1047,17 +2221,32 @@ in = (InetMon *) list->data; l0 = (*in->label0) ? in->label0: "NONE"; l1 = (*in->label1) ? in->label1: "NONE"; - fprintf(f, "%s monitor %s %s %lu %lu %s %lu %lu %d %d %d\n", + i0 = (*in->interface0) ? in->interface0 : "all"; + i1 = (*in->interface1) ? in->interface1 : "all"; + fprintf(f, "%s monitor %s %s %ld %ld %s %ld %ld %d %d %d %d %d %d %s %s\n", INET_CONFIG_KEYWORD, in->name, l0, in->port0_0, in->port0_1, l1, in->port1_0, in->port1_1, - in->extra_info, in->data0_is_range, in->data1_is_range); + in->extra_info, in->display_mode, in->data0_is_range, in->data1_is_range, + in->data0_outbound, in->data1_outbound, in->interface0, in->interface1); snprintf(buf, sizeof(buf), "%s:minute", in->name); gkrellm_save_chartconfig(f, in->chart_config_minute, INET_CONFIG_KEYWORD, buf); snprintf(buf, sizeof(buf), "%s:hour", in->name); gkrellm_save_chartconfig(f, in->chart_config_hour, INET_CONFIG_KEYWORD, buf); + snprintf(buf, sizeof(buf), "%s:minute_pkts", in->name); + gkrellm_save_chartconfig(f, in->chart_config_minute_pkts, + INET_CONFIG_KEYWORD, buf); + snprintf(buf, sizeof(buf), "%s:hour_pkts", in->name); + gkrellm_save_chartconfig(f, in->chart_config_hour_pkts, + INET_CONFIG_KEYWORD, buf); + snprintf(buf, sizeof(buf), "%s:minute_bytes", in->name); + gkrellm_save_chartconfig(f, in->chart_config_minute_bytes, + INET_CONFIG_KEYWORD, buf); + snprintf(buf, sizeof(buf), "%s:hour_bytes", in->name); + gkrellm_save_chartconfig(f, in->chart_config_hour_bytes, + INET_CONFIG_KEYWORD, buf); if (in->launch.command) fprintf(f, "%s launch %s %s\n", INET_CONFIG_KEYWORD, in->name, in->launch.command); @@ -1079,12 +2268,12 @@ if (!*in->label0) { - in->port0_1 = in->port0_1 = in->data0_is_range = 0; + in->port0_1 = in->port0_1 = in->data0_is_range = in->data0_outbound = 0; --cd_length; } if (!*in->label1) { - in->port1_1 = in->port1_1 = in->data1_is_range = 0; + in->port1_1 = in->port1_1 = in->data1_is_range = in->data1_outbound = 0; --cd_length; } if (in->data0_is_range && (in->port0_1 < in->port0_0)) @@ -1108,7 +2297,7 @@ InetMon *in; gchar config[32], name[32]; gchar item[CFG_BUFSIZE]; - gchar label0[16], label1[16]; + gchar label0[16], label1[16], interface0[8], interface1[8]; gchar *hr_min; gint n; @@ -1133,28 +2322,41 @@ in = g_new0(InetMon, 1); label0[0] = '\0'; label1[0] = '\0'; - sscanf(item, "%15s %lu %lu %15s %lu %lu %d %d %d", + strcpy(interface0, "all"); + strcpy(interface1, "all"); + sscanf(item, "%15s %ld %ld %15s %ld %ld %d %d %d %d %d %d %7s %7s", label0, &in->port0_0, &in->port0_1, label1, &in->port1_0, &in->port1_1, - &in->extra_info, &in->data0_is_range, &in->data1_is_range); + &in->extra_info, &in->display_mode, &in->data0_is_range, &in->data1_is_range, + &in->data0_outbound, &in->data1_outbound, interface0, interface1); if (!strcmp(label0, "NONE")) label0[0] = '\0'; if (!strcmp(label1, "NONE")) label1[0] = '\0'; in->label0 = g_strdup(label0); in->label1 = g_strdup(label1); + in->interface0 = g_strdup(interface0); + in->interface1 = g_strdup(interface1); in->cd_length = fix_ports(in); if (in->cd_length > 0) { + if (in->name) + g_free(in->name); in->name = g_strdup(name); in->chart_config_minute = gkrellm_chartconfig_new0(); in->chart_config_hour = gkrellm_chartconfig_new0(); + in->chart_config_minute_pkts = gkrellm_chartconfig_new0(); + in->chart_config_hour_pkts = gkrellm_chartconfig_new0(); + in->chart_config_minute_bytes = gkrellm_chartconfig_new0(); + in->chart_config_hour_bytes = gkrellm_chartconfig_new0(); inet_mon_list = g_list_append(inet_mon_list, in); } else /* Bogus config line */ { g_free(in->label0); g_free(in->label1); + g_free(in->interface0); + g_free(in->interface1); g_free(in); } return; @@ -1169,11 +2371,35 @@ if (hr_min && !strcmp(hr_min, "minute")) gkrellm_load_chartconfig(&in->chart_config_minute, item, in->cd_length); + if (hr_min && !strcmp(hr_min, "hour_pkts")) + gkrellm_load_chartconfig(&in->chart_config_hour_pkts, item, + in->cd_length); + if (hr_min && !strcmp(hr_min, "minute_pkts")) + gkrellm_load_chartconfig(&in->chart_config_minute_pkts, item, + in->cd_length); + if (hr_min && !strcmp(hr_min, "hour_bytes")) + gkrellm_load_chartconfig(&in->chart_config_hour_bytes, item, + in->cd_length); + if (hr_min && !strcmp(hr_min, "minute_bytes")) + gkrellm_load_chartconfig(&in->chart_config_minute_bytes, item, + in->cd_length); } else if (!strcmp(config, "launch")) gkrellm_dup_string(&in->launch.command, item); else if (!strcmp(config, "tooltip")) + { + gchar *rbrace; + gkrellm_dup_string(&in->launch.tooltip_comment, item); + if (item && *item == '[' && (rbrace = strstr(item, "]"))) + { + *rbrace = '\0'; + if (in->name) + g_free(in->name); + in->name = g_strdup(item + 1); + *rbrace = ']'; + } + } } @@ -1188,7 +2414,8 @@ { struct tm *tm; gchar data[64]; - gint n, in, out, cur_slot, skew, day; + gint n, cur_slot, skew, day; + gint64 in, out; tm = gkrellm_get_current_time(); day = tm->tm_yday - yday; @@ -1222,7 +2449,7 @@ | Charts will circular buff fill until data runs out. */ out = in = 0; - sscanf(data, "%d %d", &out, &in); + sscanf(data, "%Ld %Ld", &out, &in); gkrellm_store_chartdata(cp, 0, out, in); } /* Need to store zero data for time slots not in read data to bring @@ -1235,18 +2462,18 @@ { while (n-- > 0) { - gkrellm_store_chartdata(cp, 0, 0, 0); + gkrellm_store_chartdata(cp, 0, 0ULL, 0ULL); if (minute_chart && min++ == 0) { - gkrellm_store_chartdata(cp, 0, 0, 0); - gkrellm_store_chartdata(cp, 0, 0, 0); + gkrellm_store_chartdata(cp, 0, 0ULL, 0ULL); + gkrellm_store_chartdata(cp, 0, 0ULL, 0ULL); if (min == 60) min = 0; } else if (!minute_chart && hour++ == 0) { - gkrellm_store_chartdata(cp, 0, 0, 0); - gkrellm_store_chartdata(cp, 0, 0, 0); + gkrellm_store_chartdata(cp, 0, 0ULL, 0ULL); + gkrellm_store_chartdata(cp, 0, 0ULL, 0ULL); if (hour == 24) hour = 0; } @@ -1264,7 +2491,7 @@ for (n = 0; n < cp->w; ++n) { for (list = cp->cd_list; list; list = list->next) - fprintf(f, "%d ", + fprintf(f, "%Ld ", gkrellm_get_chartdata_data((GkrellmChartdata *) list->data, n)); fprintf(f, "\n"); } @@ -1310,11 +2537,19 @@ | chart data array, and then save the chart data. */ fputs("hits0_minute hits1_minute hits0_hour hits1_hour\n", f); - fprintf(f, "%ld %ld %ld %ld\n", + fprintf(f, "%Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu\n", in->hits0_minute, in->hits1_minute, - in->hits0_hour, in->hits1_hour); + in->hits0_hour, in->hits1_hour, + in->pkts0_minute, in->pkts1_minute, + in->pkts0_hour, in->pkts1_hour, + in->bytes0_minute, in->bytes1_minute, + in->bytes0_hour, in->bytes1_hour); write_inet_data(in->chart_minute, f); write_inet_data(in->chart_hour, f); + write_inet_data(in->chart_minute_pkts, f); + write_inet_data(in->chart_hour_pkts, f); + write_inet_data(in->chart_minute_bytes, f); + write_inet_data(in->chart_hour_bytes, f); fclose(f); } } @@ -1343,9 +2578,13 @@ sscanf(buf, "%d %d %d %d", &min, &hour, &yday, &len); fgets(buf, sizeof(buf), f); /* Comment line */ fgets(buf, sizeof(buf), f); - sscanf(buf, "%ld %ld %ld %ld", + sscanf(buf, "%Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu", &in->hits0_minute, &in->hits1_minute, - &in->hits0_hour, &in->hits1_hour); + &in->hits0_hour, &in->hits1_hour, + &in->pkts0_minute, &in->pkts1_minute, + &in->pkts0_hour, &in->pkts1_hour, + &in->bytes0_minute, &in->bytes1_minute, + &in->bytes0_hour, &in->bytes1_hour); skew = read_inet_data(in->chart_minute, f, 1, min, hour, yday, len); if (skew > 0) /* Current minute slot is different from saved */ @@ -1355,7 +2594,24 @@ if (skew > 0) /* Current hour slot is different from saved */ in->hits0_hour = in->hits1_hour = 0; + skew = read_inet_data(in->chart_minute_pkts, f, 1, min, hour, yday, len); + if (skew > 0) /* Current minute slot is different from saved */ + in->pkts0_minute = in->pkts1_minute = 0; + + skew = read_inet_data(in->chart_hour_pkts, f, 0, min, hour, yday, len); + if (skew > 0) /* Current hour slot is different from saved */ + in->pkts0_hour = in->pkts1_hour = 0; + + skew = read_inet_data(in->chart_minute_bytes, f, 1, min, hour, yday, len); + if (skew > 0) /* Current minute slot is different from saved */ + in->bytes0_minute = in->bytes1_minute = 0; + + skew = read_inet_data(in->chart_hour_bytes, f, 0, min, hour, yday, len); + if (skew > 0) /* Current hour slot is different from saved */ + in->bytes0_hour = in->bytes1_hour = 0; + fclose(f); + select_hour_or_minute_chart(in); gkrellm_rescale_chart(in->chart); } } @@ -1365,15 +2621,20 @@ enum { + NAME_COLUMN, LABEL0_COLUMN, PORT00_COLUMN, PORT01_COLUMN, RANGE0_COLUMN, + TYPE0_COLUMN, + INTERFACE0_COLUMN, SPACER_COLUMN, LABEL1_COLUMN, PORT10_COLUMN, PORT11_COLUMN, RANGE1_COLUMN, + TYPE1_COLUMN, + INTERFACE1_COLUMN, DUMMY_COLUMN, INET_COLUMN, N_COLUMNS @@ -1384,6 +2645,8 @@ static GtkTreeSelection *selection; +static GtkWidget *name_entry; + static GtkWidget *label0_entry, *label1_entry; static GtkWidget *port0_0_entry, @@ -1396,6 +2659,12 @@ static GtkWidget *data0_range_button, *data1_range_button; +static GtkWidget *data0_outbound, + *data1_outbound; + +static GtkWidget *interface0_entry, + *interface1_entry; + static GtkWidget *text_format_combo; @@ -1409,15 +2678,20 @@ snprintf(p10, sizeof(p10), "%d", (int) in->port1_0); snprintf(p11, sizeof(p11), "%d", (int) in->port1_1); gtk_list_store_set(store, iter, + NAME_COLUMN, in->name, LABEL0_COLUMN, in->label0, PORT00_COLUMN, p00, PORT01_COLUMN, p01, - SPACER_COLUMN, "", RANGE0_COLUMN, in->data0_is_range, + TYPE0_COLUMN, in->data0_outbound, + INTERFACE0_COLUMN, in->interface0, + SPACER_COLUMN, "", LABEL1_COLUMN, in->label1, PORT10_COLUMN, p10, PORT11_COLUMN, p11, RANGE1_COLUMN, in->data1_is_range, + TYPE1_COLUMN, in->data1_outbound, + INTERFACE1_COLUMN, in->interface1, DUMMY_COLUMN, "", -1); } @@ -1431,9 +2705,10 @@ InetMon *in; store = gtk_list_store_new(N_COLUMNS, - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING, - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_STRING, + G_TYPE_STRING, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); for (list = inet_mon_list; list; list = list->next) { @@ -1451,9 +2726,15 @@ { gtk_tree_row_reference_free(row_reference); if (model && path) + { row_reference = gtk_tree_row_reference_new(model, path); + gtk_widget_set_sensitive(delete_button, TRUE); + } else + { row_reference = NULL; + gtk_widget_set_sensitive(delete_button, FALSE); + } } static InetMon * @@ -1471,14 +2752,19 @@ } in = g_new0(InetMon, 1); gtk_tree_model_get(model, iter, + NAME_COLUMN, &in->name, LABEL0_COLUMN, &in->label0, PORT00_COLUMN, &ports[0], PORT01_COLUMN, &ports[1], RANGE0_COLUMN, &in->data0_is_range, + TYPE0_COLUMN, &in->data0_outbound, + INTERFACE0_COLUMN, &in->interface0, LABEL1_COLUMN, &in->label1, PORT10_COLUMN, &ports[2], PORT11_COLUMN, &ports[3], RANGE1_COLUMN, &in->data1_is_range, + TYPE1_COLUMN, &in->data1_outbound, + INTERFACE1_COLUMN, &in->interface1, -1); in->port0_0 = atoi(ports[0]); in->port0_1 = atoi(ports[1]); @@ -1493,16 +2779,24 @@ static void reset_entries(void) { + gtk_entry_set_text(GTK_ENTRY(name_entry), ""); + gtk_entry_set_text(GTK_ENTRY(label0_entry), ""); gtk_entry_set_text(GTK_ENTRY(port0_0_entry), "0"); gtk_entry_set_text(GTK_ENTRY(port0_1_entry), "0"); + gtk_entry_set_text(GTK_ENTRY(label1_entry), ""); gtk_entry_set_text(GTK_ENTRY(port1_0_entry), "0"); gtk_entry_set_text(GTK_ENTRY(port1_1_entry), "0"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data0_range_button), 0); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data1_range_button), 0); + gtk_entry_set_text(GTK_ENTRY(interface0_entry), ""); + gtk_entry_set_text(GTK_ENTRY(interface1_entry), ""); + change_row_reference(NULL, NULL); + gtk_widget_set_sensitive(delete_button, FALSE); gtk_tree_selection_unselect_all(selection); } @@ -1528,21 +2822,33 @@ in = inet_new_from_model(model, &iter, ports); + gtk_entry_set_text(GTK_ENTRY(name_entry), in->name); + gtk_entry_set_text(GTK_ENTRY(label0_entry), in->label0); gtk_entry_set_text(GTK_ENTRY(port0_0_entry), ports[0]); gtk_entry_set_text(GTK_ENTRY(port0_1_entry), ports[1]); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data0_range_button), in->data0_is_range); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data0_outbound), + in->data0_outbound); + gtk_entry_set_text(GTK_ENTRY(interface0_entry), in->interface0); gtk_entry_set_text(GTK_ENTRY(label1_entry), in->label1); gtk_entry_set_text(GTK_ENTRY(port1_0_entry), ports[2]); gtk_entry_set_text(GTK_ENTRY(port1_1_entry), ports[3]); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data1_range_button), in->data1_is_range); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data1_outbound), + in->data1_outbound); + gtk_entry_set_text(GTK_ENTRY(interface1_entry), in->interface1); + + g_free(in->name); g_free(in->label0); g_free(in->label1); for (i = 0; i < 4; ++i) g_free(ports[i]); + g_free(in->interface0); + g_free(in->interface1); } static void @@ -1550,7 +2856,7 @@ { gkrellm_apply_launcher(&in->launch_entry, &in->tooltip_entry, in->panel, &in->launch, gkrellm_launch_button_cb); - } + } static void add_launch_entry(GtkWidget *vbox, InetMon *in) @@ -1609,6 +2915,17 @@ in_tmp->chart_config_minute = NULL; in->chart_config_hour = in_tmp->chart_config_hour; in_tmp->chart_config_hour = NULL; + + in->chart_config_minute_pkts = in_tmp->chart_config_minute_pkts; + in_tmp->chart_config_minute_pkts = NULL; + in->chart_config_hour_pkts = in_tmp->chart_config_hour_pkts; + in_tmp->chart_config_hour_pkts = NULL; + + in->chart_config_minute_bytes = in_tmp->chart_config_minute_bytes; + in_tmp->chart_config_minute_bytes = NULL; + in->chart_config_hour_bytes = in_tmp->chart_config_hour_bytes; + in_tmp->chart_config_hour_bytes = NULL; + in->extra_info = in_tmp->extra_info; in->hour_mode = in_tmp->hour_mode; } @@ -1620,6 +2937,20 @@ in->chart_config_minute, TRUE); gkrellm_set_chartconfig_auto_grid_resolution( in->chart_config_hour, TRUE); + + in->chart_config_minute_pkts = gkrellm_chartconfig_new0(); + in->chart_config_hour_pkts = gkrellm_chartconfig_new0(); + gkrellm_set_chartconfig_auto_grid_resolution( + in->chart_config_minute_pkts, TRUE); + gkrellm_set_chartconfig_auto_grid_resolution( + in->chart_config_hour_pkts, TRUE); + + in->chart_config_minute_bytes = gkrellm_chartconfig_new0(); + in->chart_config_hour_bytes = gkrellm_chartconfig_new0(); + gkrellm_set_chartconfig_auto_grid_resolution( + in->chart_config_minute_bytes, TRUE); + gkrellm_set_chartconfig_auto_grid_resolution( + in->chart_config_hour_bytes, TRUE); in->extra_info = TRUE; } if (in_tmp) @@ -1649,6 +2980,8 @@ for (list = inet_mon_list; list; list = list->next) { in = (InetMon *) list->data; + select_hour_or_minute_chart(in); + gkrellm_rescale_chart(in->chart); draw_inet_chart(in); add_launch_entry(launch_vbox, in); } @@ -1677,7 +3010,14 @@ in = g_new0(InetMon, 1); in->data0_is_range = GTK_TOGGLE_BUTTON(data0_range_button)->active; + in->data0_outbound = GTK_TOGGLE_BUTTON(data0_outbound)->active; + in->data1_is_range = GTK_TOGGLE_BUTTON(data1_range_button)->active; + in->data1_outbound = GTK_TOGGLE_BUTTON(data1_outbound)->active; + + in->name = gkrellm_gtk_entry_get_text(&name_entry); + in->interface0 = gkrellm_gtk_entry_get_text(&interface0_entry); + in->interface1 = gkrellm_gtk_entry_get_text(&interface1_entry); in->label0 = gkrellm_gtk_entry_get_text(&label0_entry); if (*(in->label0)) @@ -1824,34 +3164,31 @@ vbox = gkrellm_gtk_framed_notebook_page(tabs, _("Ports")); - table = gtk_table_new(6, 7, FALSE /*homogeneous*/); + table = gtk_table_new(7, 9, FALSE /*homogeneous*/); gtk_table_set_col_spacings(GTK_TABLE(table), 5); gtk_box_pack_start(GTK_BOX(vbox), table, FALSE, FALSE, 3); label = gtk_label_new(_("Data0")); - gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 3, 0, 1); - separator = gtk_hseparator_new(); - gtk_table_attach_defaults(GTK_TABLE(table), separator, 0, 3, 1, 2); - label = gtk_label_new(_("Data1")); - gtk_table_attach_defaults(GTK_TABLE(table), label, 4, 7, 0, 1); - separator = gtk_hseparator_new(); - gtk_table_attach_defaults(GTK_TABLE(table), separator, 4, 7, 1, 2); - - separator = gtk_vseparator_new(); - gtk_table_attach_defaults(GTK_TABLE(table), separator, 3, 4, 0, 6); - + gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 4, 0, 1); label = gtk_label_new(_("Label")); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3); label = gtk_label_new(_("Port0")); gtk_table_attach_defaults(GTK_TABLE(table), label, 1, 2, 2, 3); label = gtk_label_new(_("Port1")); gtk_table_attach_defaults(GTK_TABLE(table), label, 2, 3, 2, 3); + label = gtk_label_new(_("Interface")); + gtk_table_attach_defaults(GTK_TABLE(table), label, 3, 4, 2, 3); + + label = gtk_label_new(_("Data1")); + gtk_table_attach_defaults(GTK_TABLE(table), label, 5, 9, 0, 1); label = gtk_label_new(_("Label")); - gtk_table_attach_defaults(GTK_TABLE(table), label, 4, 5, 2, 3); - label = gtk_label_new(_("Port0")); gtk_table_attach_defaults(GTK_TABLE(table), label, 5, 6, 2, 3); - label = gtk_label_new(_("Port1")); + label = gtk_label_new(_("Port0")); gtk_table_attach_defaults(GTK_TABLE(table), label, 6, 7, 2, 3); + label = gtk_label_new(_("Port1")); + gtk_table_attach_defaults(GTK_TABLE(table), label, 7, 8, 2, 3); + label = gtk_label_new(_("Interface")); + gtk_table_attach_defaults(GTK_TABLE(table), label, 8, 9, 2, 3); label0_entry = gtk_entry_new(); gtk_entry_set_max_length(GTK_ENTRY(label0_entry), 8); @@ -1865,42 +3202,67 @@ gtk_entry_set_max_length(GTK_ENTRY(port0_1_entry), 8); gtk_widget_set_size_request(port0_1_entry, 32, -1); gtk_table_attach_defaults(GTK_TABLE(table), port0_1_entry, 2, 3, 3, 4); + interface0_entry = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(interface0_entry), 7); + gtk_widget_set_size_request(interface0_entry, 32, -1); + gtk_table_attach_defaults(GTK_TABLE(table), interface0_entry, 3, 4, 3, 4); label1_entry = gtk_entry_new(); gtk_entry_set_max_length(GTK_ENTRY(label1_entry), 8); gtk_widget_set_size_request(label1_entry, 32, -1); - gtk_table_attach_defaults(GTK_TABLE(table), label1_entry, 4, 5, 3, 4); + gtk_table_attach_defaults(GTK_TABLE(table), label1_entry, 5, 6, 3, 4); port1_0_entry = gtk_entry_new(); gtk_entry_set_max_length(GTK_ENTRY(port1_0_entry), 8); gtk_widget_set_size_request(port1_0_entry, 32, -1); - gtk_table_attach_defaults(GTK_TABLE(table), port1_0_entry, 5, 6, 3, 4); + gtk_table_attach_defaults(GTK_TABLE(table), port1_0_entry, 6, 7, 3, 4); port1_1_entry = gtk_entry_new(); gtk_entry_set_max_length(GTK_ENTRY(port1_1_entry), 8); gtk_widget_set_size_request(port1_1_entry, 32, -1); - gtk_table_attach_defaults(GTK_TABLE(table), port1_1_entry, 6, 7, 3, 4); + gtk_table_attach_defaults(GTK_TABLE(table), port1_1_entry, 7, 8, 3, 4); + interface1_entry = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(interface1_entry), 7); + gtk_widget_set_size_request(interface1_entry, 32, -1); + gtk_table_attach_defaults(GTK_TABLE(table), interface1_entry, 8, 9, 3, 4); hbox = gtk_hbox_new(FALSE, 2); - gtk_table_attach_defaults(GTK_TABLE(table), hbox, 0, 3, 4, 5); + gtk_table_attach_defaults(GTK_TABLE(table), hbox, 0, 4, 4, 5); gkrellm_gtk_check_button(hbox, &data0_range_button, 0, TRUE, 0, - _("Port0 - Port1 is a range")); + _("Range")); + gkrellm_gtk_check_button(hbox, &data0_outbound, 0, TRUE, 0, + _("Outbound")); hbox = gtk_hbox_new(FALSE, 2); - gtk_table_attach_defaults(GTK_TABLE(table), hbox, 4, 7, 4, 5); + gtk_table_attach_defaults(GTK_TABLE(table), hbox, 5, 9, 4, 5); gkrellm_gtk_check_button(hbox, &data1_range_button, 0, TRUE, 0, - _("Port0 - Port1 is a range")); + _("Range")); + gkrellm_gtk_check_button(hbox, &data1_outbound, 0, TRUE, 0, + _("Outbound")); separator = gtk_hseparator_new(); - gtk_table_attach_defaults(GTK_TABLE(table), separator, 0, 7, 5, 6); + gtk_table_attach_defaults(GTK_TABLE(table), separator, 0, 9, 1, 2); + separator = gtk_vseparator_new(); + gtk_table_attach_defaults(GTK_TABLE(table), separator, 4, 5, 0, 6); + separator = gtk_hseparator_new(); + gtk_table_attach_defaults(GTK_TABLE(table), separator, 0, 9, 5, 6); + + label = gtk_label_new(_("Panel Name")); + gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 6, 7); + name_entry = gtk_entry_new(); + gtk_entry_set_max_length(GTK_ENTRY(name_entry), 15); + gtk_widget_set_size_request(name_entry, 32, -1); + gtk_table_attach_defaults(GTK_TABLE(table), name_entry, 1, 4, 6, 7); hbox = gtk_hbutton_box_new(); gtk_button_box_set_layout(GTK_BUTTON_BOX(hbox), GTK_BUTTONBOX_END); gtk_box_set_spacing(GTK_BOX(hbox), 5); - gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + gtk_table_attach_defaults(GTK_TABLE(table), hbox, 5, 9, 6, 7); +// gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); - button = gtk_button_new_from_stock(GTK_STOCK_DELETE); - g_signal_connect(G_OBJECT(button), "clicked", + delete_button = gtk_button_new_from_stock(GTK_STOCK_DELETE); + g_signal_connect(G_OBJECT(delete_button), "clicked", G_CALLBACK(cb_delete), NULL); - gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(hbox), delete_button, TRUE, TRUE, 0); + gtk_widget_set_sensitive(delete_button, FALSE); /* everybody knows about CNTL click, right? */ // button = gtk_button_new_from_stock(GTK_STOCK_NEW); @@ -1931,6 +3293,10 @@ G_CALLBACK(cb_drag_end), NULL); renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_insert_column_with_attributes(treeview, -1, _("Name"), + renderer, + "text", NAME_COLUMN, NULL); + renderer = gtk_cell_renderer_text_new(); gtk_tree_view_insert_column_with_attributes(treeview, -1, _("Label"), renderer, "text", LABEL0_COLUMN, NULL); @@ -1944,6 +3310,18 @@ gtk_tree_view_insert_column_with_attributes(treeview, -1, _("Port1"), renderer, "text", PORT01_COLUMN, NULL); + renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_insert_column_with_attributes(treeview, -1, _("Range"), + renderer, + "text", RANGE0_COLUMN, NULL); + renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_insert_column_with_attributes(treeview, -1, _("Outbound"), + renderer, + "text", TYPE0_COLUMN, NULL); + renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_insert_column_with_attributes(treeview, -1, _("Interface"), + renderer, + "text", INTERFACE0_COLUMN, NULL); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_insert_column_with_attributes(treeview, -1, " ", @@ -1964,6 +3342,18 @@ gtk_tree_view_insert_column_with_attributes(treeview, -1, _("Port1"), renderer, "text", PORT11_COLUMN, NULL); + renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_insert_column_with_attributes(treeview, -1, _("Range"), + renderer, + "text", RANGE1_COLUMN, NULL); + renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_insert_column_with_attributes(treeview, -1, _("Outbound"), + renderer, + "text", TYPE1_COLUMN, NULL); + renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_insert_column_with_attributes(treeview, -1, _("Interface"), + renderer, + "text", INTERFACE0_COLUMN, NULL); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_insert_column_with_attributes(treeview, -1, " ", diff -Naur gkrellm-2.2.7/src/inet.h gkrellm-2.2.7h/src/inet.h --- gkrellm-2.2.7/src/inet.h 2005-05-23 21:43:42.000000000 -0600 +++ gkrellm-2.2.7h/src/inet.h 2005-11-03 06:40:22.000000000 -0700 @@ -75,17 +75,62 @@ #define TCP_DEAD 0 #define TCP_ALIVE 1 +#define CHAIN_CONNECT 1 // Monitor connections +#define CHAIN_INPUT 2 // Recorded packets from input chain +#define CHAIN_FORWARD 4 // Recorded packets from forward chain +#define CHAIN_OUTPUT 8 // Recorded packets from output chain +#define CHAIN_MAX 0 // Used as array limit for byte and packet count history in inet.c + +#define TARGET_ACCEPT 1 // Processed packet +#define TARGET_QUEUE 2 // Queue packet to user space (if supported) +#define TARGET_RETURN 4 // Return to previous rule set +#define TARGET_DROP 8 // Dropped packets +#define TARGET_LOG 16 // Log to /var/log/messages +#define TARGET_NEW 32 // New and accept +#define TARGET_RELATED 64 // Related and accept +#define TARGET_EST 128 // Established and accept +#define TARGET_USER 256 // Other target - typically a user convenience chain + +#define TYPE_ICMP 0 +#define TYPE_UDP 1 +#define TYPE_TCP 2 +#define TYPE_ANY 3 + +#define PORT_QUEUE -1 +#define PORT_RETURN -2 +#define PORT_DROP -3 +#define PORT_LOG -4 +#define PORT_NEW -5 +#define PORT_RELATED -6 +#define PORT_EST -7 +#define PORT_RELEST -8 + typedef struct { gint state; gint family; + gint local_port; + gint local_port_hi; // for iptables range only + struct in_addr remote_addr; #if defined(INET6) struct in6_addr remote_addr6; #endif gint remote_port; + gint remote_port_hi; // for iptables range only + gint new_hit; + + gint chain; // chain type (CONNECT/INPUT/OUTPUT/FORWARD) + gint target; // line target (ACCEPT/QUEUE/RETURN/DROP/LOG/USER) + gint type; // port type + + guint64 pkts; // packet count delta + guint64 bytes; // byte count delta + + char interface[8]; // Short name like lo, ppp0, eth0, eth1, etcetera } ActiveTCP; +extern void show_tcp(gchar *, ActiveTCP *); diff -Naur gkrellm-2.2.7/src/mail.c gkrellm-2.2.7h/src/mail.c --- gkrellm-2.2.7/src/mail.c 2005-05-23 21:38:10.000000000 -0600 +++ gkrellm-2.2.7h/src/mail.c 2005-11-02 11:16:52.000000000 -0700 @@ -831,11 +831,11 @@ do_cram_md5(ConnInfo *conn, char *command, Mailbox *mbox, char *strip) { int len; - unsigned char buf1[1024]; - unsigned char msg_id[768]; - unsigned char response[16]; - unsigned char reply[1024]; - unsigned char *respdata; + gchar buf1[1024]; + gchar msg_id[768]; + gchar response[16]; + gchar reply[1024]; + gchar *respdata; snprintf(buf1, sizeof(buf1), "%s CRAM-MD5\r\n", command); server_command(conn, mbox, buf1); @@ -883,8 +883,8 @@ * (including angle-brackets). */ - hmac_md5(mbox->account->password, strlen(mbox->account->password), - msg_id, strlen(msg_id), response, sizeof(response)); + hmac_md5((unsigned char *) mbox->account->password, strlen(mbox->account->password), + (unsigned char *) msg_id, strlen(msg_id), (unsigned char *) response, sizeof(response)); snprintf(reply, sizeof(reply), "%s %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", @@ -894,7 +894,7 @@ response[8], response[9], response[10], response[11], response[12], response[13], response[14], response[15]); - to64frombits(buf1, reply, strlen(reply)); + to64frombits((unsigned char *) buf1, (unsigned char *) reply, strlen(reply)); len = strlen(buf1); if (len + 3 > sizeof(buf1)) @@ -924,7 +924,7 @@ if (_GK.debug_level & DEBUG_MAIL) dumpSmbNtlmAuthRequest(stdout, &request); memset(msgbuf, 0, sizeof(msgbuf)); - to64frombits(msgbuf, (unsigned char *)&request, SmbLength(&request)); + to64frombits((unsigned char *) msgbuf, (unsigned char *)&request, SmbLength(&request)); len = strlen(msgbuf); if (len + 3 > sizeof(msgbuf)) return FALSE; @@ -951,7 +951,7 @@ if (_GK.debug_level & DEBUG_MAIL) dumpSmbNtlmAuthResponse(stdout, &response); memset(msgbuf, 0, sizeof msgbuf); - to64frombits(msgbuf, (unsigned char *)&response, SmbLength(&response)); + to64frombits((unsigned char *) msgbuf, (unsigned char *)&response, SmbLength(&response)); len = strlen(msgbuf); if (len + 3 > sizeof(msgbuf)) return FALSE; diff -Naur gkrellm-2.2.7/src/main.c gkrellm-2.2.7h/src/main.c --- gkrellm-2.2.7/src/main.c 2005-05-23 21:40:46.000000000 -0600 +++ gkrellm-2.2.7h/src/main.c 2005-11-01 10:00:13.000000000 -0700 @@ -1787,10 +1787,17 @@ " -d, --debug-level n Turn debugging on for selective code sections.\n" "\ndebug-level numbers are (bitwise OR to debug multiple sections):\n" -" 0x10 mail\n" -" 0x20 net\n" -" 0x40 timer button\n" -" 0x80 sensors\n\n" +" 0x1 system dependencies\n" +" 0x10 mail\n" +" 0x20 net\n" +" 0x40 timer button\n" +" 0x80 sensors\n" +" 0x800 inet\n" +" 0x1000 client\n" +" 0x2000 gui\n" +" 0x4000 position\n" +" 0x8000 battery\n" +" 0x10000 chart text\n\n" ); static void diff -Naur gkrellm-2.2.7/src/mem.c gkrellm-2.2.7h/src/mem.c --- gkrellm-2.2.7/src/mem.c 2005-05-23 21:40:57.000000000 -0600 +++ gkrellm-2.2.7h/src/mem.c 2005-11-03 13:27:53.000000000 -0700 @@ -444,7 +444,7 @@ if ((cp = mc->chart) != NULL && GK.second_tick) { - gkrellm_store_chartdata(cp, 0, mc->page_out, mc->page_in); + gkrellm_store_chartdata(cp, 0, (guint64) mc->page_out, (guint64) mc->page_in); refresh_chart(mc); } } @@ -650,7 +650,7 @@ grids = gkrellm_get_chartconfig_fixed_grids(cp->config); res = gkrellm_get_chartconfig_grid_resolution(cp->config); } - if (grids == 0) + if (!grids) grids = FULL_SCALE_GRIDS; if (swap.krell_delta) diff -Naur gkrellm-2.2.7/src/net.c gkrellm-2.2.7h/src/net.c --- gkrellm-2.2.7/src/net.c 2005-05-23 21:41:02.000000000 -0600 +++ gkrellm-2.2.7h/src/net.c 2005-11-03 13:27:53.000000000 -0700 @@ -2089,7 +2089,7 @@ net->tx_old = net->tx; if (GK.second_tick) { - gkrellm_store_chartdata(net->chart, 0, net->tx, net->rx); + gkrellm_store_chartdata(net->chart, 0, (guint64) net->tx, (guint64) net->rx); net->rx_current = gkrellm_get_current_chartdata(net->rx_cd); net->tx_current = gkrellm_get_current_chartdata(net->tx_cd); rxd = (gdouble) net->rx_current; diff -Naur gkrellm-2.2.7/src/proc.c gkrellm-2.2.7h/src/proc.c --- gkrellm-2.2.7/src/proc.c 2005-05-23 21:41:42.000000000 -0600 +++ gkrellm-2.2.7h/src/proc.c 2005-11-03 13:27:53.000000000 -0700 @@ -139,7 +139,7 @@ len = snprintf(buf, size, "%.1f", (gfloat) gkrellm_get_chart_scalemax(cp) / LOAD_SCALING); else if (c == 'F' && fork_scaling > 0) - len = snprintf(buf, size, "%d", + len = snprintf(buf, size, "%Lu", gkrellm_get_chart_scalemax(cp) / fork_scaling); else if (c == 'H') len = snprintf(buf, size, "%s", gkrellm_sys_get_host_name()); @@ -266,7 +266,7 @@ | Scale the forks number by fork_scaling. See setup_proc_scaling(). */ load = (int) (LOAD_SCALING * proc.fload); - gkrellm_store_chartdata(cp, 0, load, fork_scaling * proc.n_forks); + gkrellm_store_chartdata(cp, 0, (guint64) load, (guint64) fork_scaling * proc.n_forks); refresh_proc_chart(cp); gkrellm_check_alert(load_alert, proc.fload); gkrellm_check_alert(processes_alert, proc.n_processes); diff -Naur gkrellm-2.2.7/src/sysdeps/linux.c gkrellm-2.2.7h/src/sysdeps/linux.c --- gkrellm-2.2.7/src/sysdeps/linux.c 2005-05-23 21:45:02.000000000 -0600 +++ gkrellm-2.2.7h/src/sysdeps/linux.c 2005-11-03 10:40:24.000000000 -0700 @@ -597,7 +597,7 @@ fgets(buf, sizeof(buf), f); disk[0] = '\0'; part[0] = '\0'; - + while ((fgets(buf, sizeof(buf), f)) != NULL) { major = 0; @@ -773,14 +773,314 @@ #define PROC_NET_TCP6_FILE "/proc/net/tcp6" #endif +// To reduce server traffic, we maintain information about the most recent invocation of the iptables program and only log packets to inet.c if there is a change +// in the packet or byte count of the rule. The first hit on each rule serves to initialize the counts for the rule. Subsequent changes are passed on. + +typedef struct giptableshistory + { + gint local_port; + gint local_port_hi; + gint remote_port; + gint remote_port_hi; + + gint chain; // chain type (CONNECT/INPUT/OUTPUT/FORWARD) + gint target; // line target (ACCEPT/QUEUE/RETURN/DROP/LOG/USER) + gint type; // rule type (ICMP/UDP/TCP/ANY) + gchar interface[8]; // all, ppp0, eth0, eth1, etcetera + + gint new; + + guint64 pkts; // Previous count of packets matching port and target for all rules + guint64 bytes; + + guint64 n_pkts; // Current count of packets matching port and target for all rules + guint64 n_bytes; + + struct giptableshistory *next; + } GIPTablesHistory; + +GIPTablesHistory *iptables_start = NULL, *iptables_last = NULL; + +void +record_iptables_history(int local_port, int local_port_hi, int remote_port, int remote_port_hi, int chain, int target, int type, gchar *interface, guint64 pkts, guint64 bytes) + { + static GIPTablesHistory *at = NULL; + + // Unless the firewall is altered, then the nodes should move along in sequence with each iteration. + // Keep the node pointer matched up as the report is read and don't do anything special unless the packet or byte + // count changes. + + if (at && + at->local_port == local_port && at->local_port_hi == local_port_hi && + at->remote_port == remote_port && at->remote_port_hi == remote_port_hi && + at->chain == chain && + at->target == target && + at->type == type && + !strcmp(at->interface, interface)) + { + at->n_pkts += pkts; + at->n_bytes += bytes; + at = at->next; + return; + } + + + // If the user has added rules to the rule set in some particular chain, a new entry will be added at the end of the list + // so first go back to square one to look for existing entries that match. + + at = iptables_start; + while (at) + { + if (at->local_port == local_port && at->local_port_hi == local_port_hi && + at->remote_port == remote_port && at->remote_port_hi == remote_port_hi && + at->chain == chain && + at->target == target && + at->type == type && + !strcmp(at->interface, interface)) + { + at->n_pkts += pkts; + at->n_bytes += bytes; + at = at->next; + return; + } + + at = at->next; + } + + // No matching node to track this rule's history was found. + // If you can allocate another node, the current iptables information is synced into it and automatically sent on for + // logging the first packet and byte count information for the rule + + if ((at = g_new0(GIPTablesHistory, 1))) + { + if (iptables_last) + { + iptables_last = iptables_last->next = at; + } + else + { + iptables_start = iptables_last = at; + } + at->local_port = local_port; + at->local_port_hi = local_port_hi; + at->remote_port = remote_port; + at->remote_port_hi = remote_port_hi; + at->chain = chain; + at->target = target; + at->type = type; + interface[7] = '\0'; // Truncate to the first 7 characters + strcpy(at->interface, interface); + at->n_pkts = pkts; + at->n_bytes = bytes; + at->new = 1; + at = NULL; + return; + } + } + +void +show_tcp(gchar *where, ActiveTCP *tcp) + { + fprintf(stderr, "%s, %d:%d %d:%d chain=%x target=%x type=%d interface=%s pkts=%Ld bytes=%Ld\n", where, + tcp->local_port, tcp->local_port_hi, tcp->remote_port, tcp->remote_port_hi, + tcp->chain, tcp->target, tcp->type, tcp->interface, tcp->pkts, tcp->bytes); + } + + +void +update_new_iptables_history(void) + { + GIPTablesHistory *at = iptables_start; + ActiveTCP tcp; + + tcp.family = AF_INET; + tcp.state = TCP_ALIVE; + + while (at) + { + if (at->n_pkts != at->pkts || at->n_bytes != at->bytes) + { + if (!at->new) + { + tcp.local_port = at->local_port; + tcp.local_port_hi = at->local_port_hi; + tcp.remote_port = at->remote_port; + tcp.remote_port_hi = at->remote_port_hi; + + tcp.chain = at->chain; + tcp.target = at->target; + tcp.type = at->type; + strcpy(tcp.interface, at->interface); + + tcp.pkts = at->n_pkts - at->pkts; + tcp.bytes = at->n_bytes - at->bytes; +#if 0 + show_tcp("update_new_iptables_history", &tcp); +#endif + gkrellm_inet_log_tcp_port_data(&tcp); + } + else + at->new = 0; + + at->pkts = at->n_pkts; + at->bytes = at->n_bytes; + } + + at->n_pkts = 0; + at->n_bytes = 0; + at = at->next; + } + } + +typedef struct gipchainhistory + { + char *name; + gint type; // INPUT, OUTPUT, FORWARD, USER + gint target; // ACCEPT, QUEUE, RETURN, DROP, LOG, USER + gchar interface[8]; // all, ppp0, eth0, eth1, etcetera + + struct gipchainhistory *next; + } GIPChainHistory; + +GIPChainHistory *iptables_chain_start = NULL, *iptables_chain_last = NULL; + + +int +parse_chains(gchar *source, gchar *chain_name, int chain_type, gchar *interface) + { + char name[64]; + char tmp[64]; + gchar *bufp; + guint64 tval; + int target = 0; + char new_interface[64]; + + GIPChainHistory *at; + + at = iptables_chain_start; + while (at) + { + if (!strcmp(at->name, chain_name)) + { + at->type |= chain_type; + if (!*at->interface && interface && *interface) + { + strcpy(at->interface, interface); + } + break; + } + at = at->next; + } + + if (!at) + return 0; + + sprintf(name, "Chain %s ", chain_name); + bufp = strstr(source, name); + if (bufp) + { + bufp = strstr(bufp, "\n") + 1; // skip Chain xxx () line + bufp = strstr(bufp, "\n") + 1; // skip pkts bytes... line + while (*bufp && *bufp != '\n') + { + int i; + + sscanf(bufp, "%Lu %n", &tval, &i); // Skip packet count + bufp += i; + sscanf(bufp, "%Lu %n", &tval, &i); // Skip byte count + bufp += i; + sscanf(bufp, "%[^ ] %n", name, &i); + bufp += i; + sscanf(bufp, "%[^ ] %n", tmp, &i); // Skip service + bufp += i; + sscanf(bufp, "%[^ ] %n", tmp, &i); // Skip options + bufp += i; + *new_interface = '\0'; + sscanf(bufp, "%[^ ] %n", tmp, &i); // Read in interface + bufp += i; + if (strcmp(tmp, "*")) // If not *, then use that interface name instead of any + strcpy(new_interface, tmp); + sscanf(bufp, "%[^ ] %n", tmp, &i); // Read out interface + bufp += i; + if (strcmp(tmp, "*")) // If not *, then use that interface name instead of any + strcpy(new_interface, tmp); + + if (!strcmp(name, "ACCEPT")) + target |= TARGET_ACCEPT; + else if (!strcmp(name, "QUEUE")) + target |= TARGET_QUEUE; + else if (!strcmp(name, "RETURN")) + target |= TARGET_RETURN; + else if (!strcmp(name, "DROP")) + target |= TARGET_DROP; + else if (!strcmp(name, "LOG")) + target |= TARGET_LOG; + else { + if (*new_interface && (!interface || !*interface)) + target |= parse_chains(source, name, chain_type, new_interface); + else + target |= parse_chains(source, name, chain_type, interface); + } + bufp = strstr(bufp, "\n") + 1; + } + } + + at->target |= target; + + return target; + } + + +GIPChainHistory +*find_iptables_chain(gchar *target) + { + GIPChainHistory *at = iptables_chain_start; + + while (at) + { + if (!strcmp(at->name, target)) + return at; + at = at->next; + } + + if ((at = g_new0(GIPChainHistory, 1))) + { + at->type = CHAIN_MAX; + + if ((at->name = g_strdup(target))) + { + if (iptables_chain_last) + { + iptables_chain_last = iptables_chain_last->next = at; + } + else + { + iptables_chain_start = iptables_chain_last = at; + } + } + else + { + g_free(at); + at = NULL; + } + } + + return at; + } + + void gkrellm_sys_inet_read_tcp_data(void) { - FILE *f; - ActiveTCP tcp; - gchar buf[512]; - gint tcp_status; - gulong addr; + FILE *f; + ActiveTCP tcp; + gchar buf[512]; + gint tcp_status; + gulong addr; + static int disable_iptables; + + bzero(&tcp, sizeof(ActiveTCP)); + tcp.chain = CHAIN_CONNECT; if ((f = fopen(PROC_NET_TCP_FILE, "r")) != NULL) { @@ -819,6 +1119,354 @@ fclose(f); } #endif /* INET6 */ + + // For iptables to run so you can get statistics, you must be running as root :( If gkrellm/gkrellmd is running with reduced privileges, then you get + // a zero length stdout stream instead of actual information. If you see this, then turn off iptables completely for minimum impact on the + // system. A su wrapper would be one solution :< or just let gkrellm/gkrellmd stay as root. + + // It would be nice to just do a zero stats after each read, but that would be intrusive, so the calling program must keep track of each rules + // packet and byte counts and find the difference. + + if (!disable_iptables && (f = popen("/sbin/iptables -L -v -n -x", "r")) != NULL) + { + gchar *output; + gint i; + + int local_port; + int local_port_hi; + int remote_port; + int remote_port_hi; + + int chain = 0; + int target; + int type; + + guint64 pkts; + guint64 bytes; + + gchar *bufp, *nbufp, *tbufp; + gchar interface[64], new_interface[64]; + gchar name[512]; + + // Find out the size of the output of the iptables command + + output = NULL; + i = 0; + while (fgets(buf, sizeof(buf), f) == buf) + { + int length = strlen(buf); + + if (i) + { + output = realloc(output, i + length + 1); + } + else + { + output = malloc(length + 1); + } + + if (output) + { + strcpy(output + i, buf); + i += length; + } + else + break; + } + pclose(f); + + + // Create a buffer to hold the output - if you succeed, do the processing - make sure you have a null termination at the end + if (output) + { +#if 0 + fprintf(stderr, "%s\n", output); +#endif + bufp = output; + while (bufp && *bufp) + { + bufp = strstr(bufp, "Chain "); + if (bufp) + { + bufp += 6; + sscanf(bufp, "%[^ ]", name); + find_iptables_chain(name); + } + } + + parse_chains(output, "INPUT", CHAIN_INPUT, NULL); + parse_chains(output, "FORWARD", CHAIN_FORWARD, NULL); + parse_chains(output, "OUTPUT", CHAIN_OUTPUT, NULL); + + bufp = output; + while (bufp && *bufp) + { + if (*bufp == '\n') // If a blank line is found, skip to the next line. + { + bufp++; + continue; + } + + if (!strncmp(bufp, "Chain", 5)) + { + GIPChainHistory *at; + + bufp += 6; + sscanf(bufp, "%[^ ]", name); + + at = find_iptables_chain(name); + if (at) + { + chain = at->type; // Update whether the chain is input, output, forward, or some combination + if (*at->interface) + strcpy(interface, at->interface); + else + strcpy(interface, "all"); + } + else + { + chain = CHAIN_MAX; + strcpy(interface, "all"); + } + + bufp = strstr(bufp, "\n") + 1; + continue; + } + + if (!strncmp(bufp, " pkts", 8)) + { + bufp = strstr(bufp, "\n") + 1; + continue; + } + + if ((nbufp = strstr(bufp, "\n"))) + *nbufp = '\0'; + + sscanf(bufp, "%Lu %n", &pkts, &i); + + // If the packet count is 0, then we can ignore all other information on the line. + + if (pkts) + { + bufp += i; + sscanf(bufp, "%Lu %n", &bytes, &i); + bufp += i; + sscanf(bufp, "%[^ ] %n", name, &i); + bufp += i; + + strcpy(new_interface, interface); + + if (strcmp(name, "ACCEPT") == 0) + target = TARGET_ACCEPT; + else if (strcmp(name, "DROP") == 0) + target = TARGET_DROP; + else if (strcmp(name, "QUEUE") == 0) + target = TARGET_QUEUE; + else if (strcmp(name, "RETURN") == 0) + target = TARGET_RETURN; + else if (strcmp(name, "LOG") == 0) + target = TARGET_LOG; + else + { + GIPChainHistory *at; + + target = TARGET_USER; + if ((at = find_iptables_chain(name))) + { + target |= at->target; + } + } + + sscanf(bufp, "%[^ ] %n", name, &i); + bufp += i; + + if (!strcmp(name, "icmp")) + type = TYPE_ICMP; + else if (!strcmp(name, "udp")) + type = TYPE_UDP; + else if (!strcmp(name, "tcp")) + type = TYPE_TCP; + else + type = TYPE_ANY; + + sscanf(bufp, "%[^ ] %n", name, &i); // Skip options + bufp += i; + + sscanf(bufp, "%[^ ] %n", name, &i); // Read in interface + bufp += i; + if (strcmp(name, "*")) // If not *, then use that interface name instead of any + strcpy(new_interface, name); + + sscanf(bufp, "%[^ ] %n", name, &i); // Read out interface + bufp += i; + if (strcmp(name, "*")) // If not *, then use that interface name instead of any + strcpy(new_interface, name); + + local_port = remote_port = 0; // Default to full range in case no rule specifies anything else + local_port_hi = remote_port_hi = 65535; + + // On input, source is remote port and destination is local + + if (type == TYPE_ICMP) + { + if ((tbufp = strstr(bufp, " type "))) + { + sscanf(tbufp + 6, "%d", &local_port); + local_port_hi = local_port; + } + if ((tbufp = strstr(bufp, " code "))) + { + sscanf(tbufp + 6, "%d", &remote_port); + remote_port_hi = remote_port; + } + } + + else if (!chain || (chain & (CHAIN_INPUT | CHAIN_FORWARD))) + { + if ((tbufp = strstr(bufp, " spt:"))) + { + sscanf(tbufp + 5, "%d", &remote_port); + remote_port_hi = remote_port; + } + else if ((tbufp = strstr(bufp, " spts:"))) + sscanf(tbufp + 6, "%d:%d", &remote_port, &remote_port_hi); + else if ((tbufp = strstr(bufp, " sports "))) + { + int min = 65535; + int max = 0; + int port; + tbufp += 8; + do { + port = strtol(tbufp, &tbufp, 0); + if (port < min) + min = port; + if (port > max) + max = port; + if (*tbufp == ',') + tbufp++; + } while (isdigit(*tbufp)); + + remote_port = min; + remote_port_hi = max; + } + + if ((tbufp = strstr(bufp, " dpt:"))) + { + sscanf(tbufp + 5, "%d", &local_port); + local_port_hi = local_port; + } + else if ((tbufp = strstr(bufp, " dpts:"))) + sscanf(tbufp + 6, "%d:%d", &local_port, &local_port_hi); + else if ((tbufp = strstr(bufp, " dports "))) + { + int min = 65535; + int max = 0; + int port; + tbufp += 8; + do { + port = strtol(tbufp, &tbufp, 0); + if (port < min) + min = port; + if (port > max) + max = port; + if (*tbufp == ',') + tbufp++; + } while (isdigit(*tbufp)); + + local_port = min; + local_port_hi = max; + } + else if (target & TARGET_ACCEPT) + { + if (strstr(bufp, "NEW")) + target |= TARGET_NEW; + if (strstr(bufp, "ESTABLISHED")) + target |= TARGET_EST; + if (strstr(bufp, "RELATED")) + target |= TARGET_RELATED; + } + } + else // Source/Destination sense reverses local/remote for output. + { + if ((tbufp = strstr(bufp, " spt:"))) + { + sscanf(tbufp + 5, "%d", &local_port); + local_port_hi = local_port; + } + else if ((tbufp = strstr(bufp, " spts:"))) + sscanf(tbufp + 6, "%d:%d", &local_port, &local_port_hi); + else if ((tbufp = strstr(bufp, " sports "))) + { + int min = 65535; + int max = 0; + int port; + tbufp += 8; + do { + port = strtol(tbufp, &tbufp, 0); + if (port < min) + min = port; + if (port > max) + max = port; + if (*tbufp == ',') + tbufp++; + } while (isdigit(*tbufp)); + + local_port = min; + local_port_hi = max; + } + + if ((tbufp = strstr(bufp, " dpt:"))) + { + sscanf(tbufp + 5, "%d", &remote_port); + remote_port_hi = remote_port; + } + else if ((tbufp = strstr(bufp, " dpts:"))) + sscanf(tbufp + 6, "%d:%d", &remote_port, &remote_port_hi); + else if ((tbufp = strstr(bufp, " dports "))) + { + int min = 65535; + int max = 0; + int port; + tbufp += 8; + do { + port