/* * show the data in a joined window */ static void curses_connection_data_join(void) { char src[MAX_ASCII_ADDR_LEN]; char dst[MAX_ASCII_ADDR_LEN]; char title[64]; DEBUG_MSG("curses_connection_data_join"); if (wdg_conndata) { struct conn_object *tmp_conn = curr_conn; wdg_destroy_object(&wdg_conndata); curses_destroy_conndata(); curr_conn = tmp_conn; } /* don't timeout this connection */ curr_conn->flags |= CONN_VIEWING; wdg_create_object(&wdg_conndata, WDG_COMPOUND, WDG_OBJ_WANT_FOCUS); wdg_set_color(wdg_conndata, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(wdg_conndata, WDG_COLOR_WINDOW, EC_COLOR); wdg_set_color(wdg_conndata, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_color(wdg_conndata, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_set_title(wdg_conndata, "Connection data", WDG_ALIGN_LEFT); wdg_set_size(wdg_conndata, 1, 2, -1, SYSMSG_WIN_SIZE - 1); wdg_create_object(&wdg_join, WDG_SCROLL, 0); snprintf(title, 64, "%s:%d - %s:%d", ip_addr_ntoa(&curr_conn->L3_addr1, src), ntohs(curr_conn->L4_addr1), ip_addr_ntoa(&curr_conn->L3_addr2, dst), ntohs(curr_conn->L4_addr2)); wdg_set_title(wdg_join, title, WDG_ALIGN_LEFT); wdg_set_color(wdg_join, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_set_color(wdg_join, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_size(wdg_join, 2, 3, -2, SYSMSG_WIN_SIZE - 2); /* set the buffers */ wdg_scroll_set_lines(wdg_join, GBL_CONF->connection_buffer / (current_screen.cols / 2) ); /* link the widget together within the compound */ wdg_compound_add(wdg_conndata, wdg_join); /* add the destroy callback */ wdg_add_destroy_key(wdg_conndata, CTRL('Q'), curses_destroy_conndata); /* * do not add inject callback because we can determine where to inject in * joined mode... */ wdg_compound_add_callback(wdg_conndata, 'j', curses_connection_data_split); wdg_compound_add_callback(wdg_conndata, 'k', curses_connection_kill_wrapper); wdg_compound_add_callback(wdg_conndata, ' ', curses_connection_data_help); wdg_draw_object(wdg_conndata); wdg_set_focus(wdg_conndata); /* print the old data */ connbuf_print(&curr_conn->data, join_print); /* add the hook on the connection to receive data only from it */ conntrack_hook_conn_add(curr_conn, join_print_po); }
/* * called to redraw a window */ static int wdg_scroll_redraw(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_scroll, ww); size_t c = wdg_get_ncols(wo); size_t l = wdg_get_nlines(wo); size_t x = wdg_get_begin_x(wo); size_t y = wdg_get_begin_y(wo); WDG_DEBUG_MSG("wdg_scroll_redraw"); /* the window already exist */ if (ww->win) { /* erase the border */ wbkgd(ww->win, COLOR_PAIR(wo->screen_color)); werase(ww->win); touchwin(ww->win); wnoutrefresh(ww->win); /* resize the window and draw the new border */ mvwin(ww->win, y, x); wresize(ww->win, l, c); wdg_scroll_border(wo); /* set the window color */ wbkgd(ww->sub, COLOR_PAIR(wo->window_color)); touchwin(ww->sub); /* the pad is resized only orizzontally. * the vertical dimension can be larger than the screen */ wdg_scroll_set_lines(wo, ww->y_max); /* refresh it */ WDG_PAD_REFRESH(ww, c, l, x, y); /* the first time we have to allocate the window */ } else { /* a default value waiting for wdg_scroll_set_lines() */ ww->y_max = l * 5; /* create the outher window */ if ((ww->win = newwin(l, c, y, x)) == NULL) return -WDG_EFATAL; /* draw the borders */ wdg_scroll_border(wo); /* initialize the pointer */ wdg_set_scroll(wo, ww->y_max - l + 1); /* create the inner (actual) window */ if ((ww->sub = newpad(ww->y_max, c - 2)) == NULL) return -WDG_EFATAL; /* set the window color */ wbkgd(ww->sub, COLOR_PAIR(wo->window_color)); touchwin(ww->sub); /* move to the bottom of the pad */ wmove(ww->sub, ww->y_scroll + 1, 0); /* permit scroll in the pad */ scrollok(ww->sub, TRUE); } /* refresh the window */ touchwin(ww->sub); wnoutrefresh(ww->win); WDG_PAD_REFRESH(ww, c, l, x, y); wo->flags |= WDG_OBJ_VISIBLE; return WDG_ESUCCESS; }
/* * display the initial menu to setup global options * at startup. */ static void curses_setup(void) { wdg_t *menu; struct wdg_menu file[] = { {"File", 'F', "", NULL}, {"Open...", CTRL('O'), "C-o", curses_file_open}, {"Dump to file...", CTRL('D'), "C-d", curses_file_write}, {"-", 0, "", NULL}, {"Exit", CTRL('X'), "C-x", curses_exit}, {NULL, 0, NULL, NULL}, }; struct wdg_menu live[] = { {"Sniff", 'S', "", NULL}, {"Unified sniffing...", 'U', "U", curses_unified_sniff}, {"Bridged sniffing...", 'B', "B", curses_bridged_sniff}, {"-", 0, "", NULL}, {"Set pcap filter...", 'p', "p", curses_pcap_filter}, {NULL, 0, NULL, NULL}, }; struct wdg_menu options[] = { {"Options", 'O', "", NULL}, {"Unoffensive", 0, tag_unoff, toggle_unoffensive}, {"Promisc mode", 0, tag_promisc, toggle_nopromisc}, {"Set netmask", 'n', "n" , curses_set_netmask}, {NULL, 0, NULL, NULL}, }; DEBUG_MSG("curses_setup"); wdg_create_object(&menu, WDG_MENU, WDG_OBJ_WANT_FOCUS | WDG_OBJ_ROOT_OBJECT); wdg_set_title(menu, GBL_VERSION, WDG_ALIGN_RIGHT); wdg_set_color(menu, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(menu, WDG_COLOR_WINDOW, EC_COLOR_MENU); wdg_set_color(menu, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_color(menu, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_menu_add(menu, file); wdg_menu_add(menu, live); wdg_menu_add(menu, options); wdg_menu_add(menu, menu_help); wdg_draw_object(menu); DEBUG_MSG("curses_setup: menu created"); /* create the bottom windows for user messages */ wdg_create_object(&sysmsg_win, WDG_SCROLL, WDG_OBJ_WANT_FOCUS); wdg_set_title(sysmsg_win, "User messages:", WDG_ALIGN_LEFT); wdg_set_size(sysmsg_win, 0, SYSMSG_WIN_SIZE, 0, 0); wdg_set_color(sysmsg_win, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(sysmsg_win, WDG_COLOR_WINDOW, EC_COLOR); wdg_set_color(sysmsg_win, WDG_COLOR_BORDER, EC_COLOR_BORDER); wdg_set_color(sysmsg_win, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_color(sysmsg_win, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_scroll_set_lines(sysmsg_win, 500); wdg_draw_object(sysmsg_win); /* give the focus to the menu */ wdg_set_focus(menu); DEBUG_MSG("curses_setup: sysmsg created"); /* initialize the options */ if (GBL_OPTIONS->unoffensive) tag_unoff[0] = '*'; else tag_unoff[0] = ' '; if (GBL_PCAP->promisc) tag_promisc[0] = '*'; else tag_promisc[0] = ' '; /* give the control to the interface */ wdg_events_handler('u'); wdg_destroy_object(&menu); DEBUG_MSG("curses_setup: end"); }