Example #1
0
static void
draw_detailed(void)
{
	int start_pos, end_pos, i;
	intf_t *intf;
	double rx, tx;
	char *rx_u, *tx_u;
	int attr_flag = 0;

	intf = get_current_intf();

	if (NULL == intf)
		return;
	
	move(row, 40);
	addch(ACS_TTEE);
	move(row, 0);
	
#ifndef DISABLE_OVERFLOW_WORKAROUND
	if (intf->i_rx_bytes.r_overflows)
		rx = sumup((intf->i_rx_bytes.r_overflows * OVERFLOW_LIMIT) +
			intf->i_rx_bytes.r_total, &rx_u);
#endif
	else
		rx = sumup(intf->i_rx_bytes.r_total, &rx_u);

#ifndef DISABLE_OVERFLOW_WORKAROUND
	if (intf->i_tx_bytes.r_overflows)
		tx = sumup((intf->i_tx_bytes.r_overflows * OVERFLOW_LIMIT) +
			intf->i_tx_bytes.r_total, &tx_u);
#endif
	else
		tx = sumup(intf->i_tx_bytes.r_total, &tx_u);

	NEXT_ROW;
	start_pos = row;
	putl("                      RX          TX                             RX          TX");

	NEXT_ROW;
	putl(" Bytes:        %9.1f %s%8.1f %s    Packets:    %11llu %11llu",
		rx, rx_u, tx, tx_u,
		intf->i_rx_packets.r_total, intf->i_tx_packets.r_total);

	foreach_attr(intf, draw_attr_detail, &attr_flag);

	end_pos = row;
	for (i = start_pos; i <= end_pos; i++) {
		move(i, 40);
		addch(ACS_VLINE);
	}
	move(end_pos, 0);
}
 /** Return the number of hits in the past 5 minutes.
     @param timestamp - The current timestamp (in seconds granularity). */
 int getHits(int timestamp) {
     int cursum = 0, prevsum = 0;
     int curid = timestamp%300;
     if(!curid)
         curid = 300;
     if(curid < previd || (curid == previd && prestmp < timestamp) || timestamp - prestmp > 300)
         flusharr(timestamp - prestmp > 300);
     cursum += sumup(prev_arr, 300);
     cursum += sumup(cur_arr, curid);
     prevsum += sumup(prev_arr, curid);
     updatetime(curid, timestamp);
     return cursum-prevsum;
 }
Example #3
0
static void
print_details(intf_t *i)
{
	double rx, tx;
	char *rx_u, *tx_u;
	
	if (i->i_handle)
		printf(" %s (%u)\n", i->i_name, i->i_handle);
	else
		printf(" %s\n", i->i_name);

	rx = sumup(i->i_rx_bytes.r_total, &rx_u);
	tx = sumup(i->i_tx_bytes.r_total, &tx_u);

	printf("  Bytes:         %12.2f %s %12.2f %s\n",
		rx, rx_u, tx, tx_u);
	printf("  Packets:       %12llu     %12llu\n",
		i->i_rx_packets.r_total, i->i_tx_packets.r_total);

	foreach_attr(i, print_attr_detail, NULL);
}
Example #4
0
static void
draw_intf_list_entry(intf_t *intf, node_t *node)
{
	float rx, tx;
	char *rx_u, *tx_u;
	char pad[IFNAMSIZ + 32];
	
	rx = sumup(intf->i_rx_bytes.r_tps, &rx_u);
	tx = sumup(intf->i_tx_bytes.r_tps, &tx_u);

	memset(pad, ' ', sizeof(pad));
	pad[sizeof(pad) - 1] = '\0';
	if (intf->i_level >= 15)
		strcpy(&pad[sizeof(pad) - 1], intf->i_name);
	else
		strcpy(&pad[2 * intf->i_level], intf->i_name);

	NEXT_ROW;

	if (intf->i_index == node->n_selected && node == get_current_node()) {
		if (c_use_colors)
			attrset(COLOR_PAIR(LAYOUT_SELECTED) | layout[LAYOUT_SELECTED].attr);
		else
			attron(A_REVERSE);
	}
	
	printw("  %-3d%s", intf->i_index, intf->i_folded ? "+" : " ");

	if (intf->i_index == node->n_selected && node == get_current_node()) {
		if (c_use_colors)
			attrset(COLOR_PAIR(LAYOUT_LIST) | layout[LAYOUT_LIST].attr);
		else
			attroff(A_REVERSE);
	}

	
	putl("%-20s %10.2f%s %10d %10.2f%s %10d", pad,
		rx, rx_u, intf->i_rx_packets.r_tps,
		tx, tx_u, intf->i_tx_packets.r_tps);
}
Example #5
0
static void
print_intf(intf_t *i)
{
	double rx, tx;
	char *rx_u, *tx_u;
	char pad[IFNAMSIZ + 32];
	
	if (get_print_header())
		printf("Interface JackSnake                   RX Rate        RX #    TX Rate        TX #\n");

	rx = sumup(i->i_rx_bytes.r_tps, &rx_u);
	tx = sumup(i->i_tx_bytes.r_tps, &tx_u);

	memset(pad, ' ', sizeof(pad));
	pad[sizeof(pad) - 1] = '\0';
	if (i->i_level >= 15)
		strcpy(&pad[sizeof(pad) - 1], i->i_name);
	else
		strcpy(&pad[2 * i->i_level], i->i_name);

	printf("%-24s%10.2f%s%10.1f%10.2f%s%10.1f\n", pad,
		rx, rx_u, (float) i->i_rx_packets.r_tps,
		tx, tx_u, (float) i->i_tx_packets.r_tps);
}
Example #6
0
int main(void) {
    double  goukei;                         /* 加總 */
    double  x[5];
    int  i;
    int  nx = sizeof(x) / sizeof(x[0]); /*陣列x的元素個數*/

    for (i = 0; i < nx; i++) {
        printf("x[%d] : ", i);
        scanf("%lf", &x[i]);
    }

    goukei = sumup(x);
    printf("合計=%f\n", goukei);

    return (0);
}