From b80c407c50aec83671a224674df820a33a9488c4 Mon Sep 17 00:00:00 2001 From: sunmingbao Date: Wed, 20 Nov 2013 21:04:04 +0800 Subject: [PATCH] v2.3.1 --- inc/common.h | 9 +-- release_notes.txt | 11 ++-- res/sample.rc | 2 +- src/common.c | 26 ++++++++ src/right_window.c | 139 +++++++++++++++++++++++++----------------- src/stream_edit_dlg.c | 88 +++++++++++++++++++------- xb_ether_tester.nsi | 2 +- 7 files changed, 184 insertions(+), 93 deletions(-) diff --git a/inc/common.h b/inc/common.h index 921670f..ac3859b 100644 --- a/inc/common.h +++ b/inc/common.h @@ -296,19 +296,20 @@ typedef struct unsigned char ar_pln; /* length of protocol address */ unsigned short ar_op; /* ARP opcode (command) */ -#if 0 +#if 1 /* * Ethernet looks like this : This bit is variable sized however... */ - unsigned char ar_sha[ETH_ALEN]; /* sender hardware address */ + unsigned char ar_sha[6]; /* sender hardware address */ unsigned char ar_sip[4]; /* sender IP address */ - unsigned char ar_tha[ETH_ALEN]; /* target hardware address */ + unsigned char ar_tha[6]; /* target hardware address */ unsigned char ar_tip[4]; /* target IP address */ #endif -} t_arp_hdr; +} __attribute__ ((aligned (1))) t_arp_hdr; void get_protocol_name(int protocol, char *name); +void get_eth_type_name(int type, char *info); int SelRvs(HWND hList); int SelAll(HWND hList); diff --git a/release_notes.txt b/release_notes.txt index 2a9a05c..5101d79 100644 --- a/release_notes.txt +++ b/release_notes.txt @@ -1,14 +1,11 @@ - 小兵以太网测试仪 v2.3.0 + 小兵以太网测试仪 v2.3.1 -发布日期:2013-11-15 +发布日期:2013-11-20 【功能完善】 - o 工具栏界面显示进行了完善。 - o 支持了IP报文全部协议名称的显示。 - o 对源码及相关文件进行了梳理,以便将软件开源。 + o 优化了报文列表的显示内容。 + o 优化了部分界面显示。 -【其他说明】 - o 从本版本开始,本软件走向了开源。 \ No newline at end of file diff --git a/res/sample.rc b/res/sample.rc index 2d78f58..2267950 100644 --- a/res/sample.rc +++ b/res/sample.rc @@ -133,7 +133,7 @@ ABOUTBOX DIALOG DISCARDABLE 32, 32, 250, 200 STYLE DS_MODALFRAME | WS_POPUP FONT 8, "MS Sans Serif" BEGIN - ICON "my_frame_icon",IDC_STATIC,10,10,32,32 + ICON "my_frame_icon",IDC_STATIC,10,10,32,32, SS_REALSIZEIMAGE PUSHBUTTON "源码", ID_AB_SOURCE,5, 50, 35, 14 PUSHBUTTON "官网", ID_AB_SITE, 5, 70, 35, 14 PUSHBUTTON "升级", ID_AB_UPDATE,5, 90, 35, 14 diff --git a/src/common.c b/src/common.c index 3106dad..c3e44a3 100644 --- a/src/common.c +++ b/src/common.c @@ -1046,5 +1046,31 @@ void get_protocol_name(int protocol, char *name) } } +void get_eth_type_name(int type, char *info) +{ + switch (type) + { + + case ETH_P_IP: + strcpy(info, "ip"); + return; + + case ETH_P_ARP: + strcpy(info, "arp"); + return; + + case ETH_P_RARP: + strcpy(info, "rarp"); + return; + + case ETH_P_IPV6: + strcpy(info, "ipv6"); + return; + + } + + sprintf(info, "0x%04x", type); + +} #endif diff --git a/src/right_window.c b/src/right_window.c index 0f94f73..7cefa13 100644 --- a/src/right_window.c +++ b/src/right_window.c @@ -12,7 +12,7 @@ #include "global_info.h" #include "res.h" -const char version[4]={'2','3','0','0'}; +const char version[4]={'2','3','1','0'}; TCHAR szRightWinClassName[] = TEXT ("right_win") ; HWND hwnd_right; @@ -111,9 +111,9 @@ TCHAR *col_names[] = NULL, TEXT("索引"), TEXT("名称"), - TEXT("目的mac"), - TEXT("源mac"), - TEXT("类型"), + TEXT("源地址"), + TEXT("目的地址"), + TEXT("协议"), TEXT("长度"), TEXT("信息"), }; @@ -122,51 +122,36 @@ BOOL InitListViewColumns(HWND hWndListView) { TCHAR szText[256]; // Temporary buffer. LVCOLUMN lvc; - int iCol; + int iCol, col_num = ARRAY_SIZE(col_names); int order[] = { 1, 0, 2, 3, 4, 5, 6, 7, 8}; - // Initialize the LVCOLUMN structure. - // The mask specifies that the format, width, text, - // and subitem members of the structure are valid. +int lv_width = GetSystemMetrics(SM_CXSCREEN) - 240; +int col_width[] = {40, 20, cxChar*7, cxChar*10, cxChar*20, cxChar*20 + , cxChar*9, cxChar*7, cxChar*30}; + +SendMessage(hWndListView, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FIXED_FONT), 0); lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; // Add the columns. - for (iCol = 0; iCol < ARRAY_SIZE(col_names); iCol++) + for (iCol = 0; iCol < col_num; iCol++) { + lvc.fmt = LVCFMT_LEFT; lvc.iSubItem = iCol; lvc.pszText = col_names[iCol]; - if ( iCol == 0 ) + if ( iCol == 0 || iCol == 1) { lvc.fmt = LVCFMT_RIGHT; // Left-aligned column. - lvc.cx = 40; } - else if ( iCol == 1 ) - { - lvc.fmt = LVCFMT_RIGHT; // Left-aligned column. - lvc.cx = 20; - } - else if ( iCol == 2 ) + if ( iCol != (col_num-1)) { - lvc.fmt = LVCFMT_LEFT; // Left-aligned column. - lvc.cx = 80; + lvc.cx = col_width[iCol]; + lv_width -= lvc.cx; } - else if ( iCol == 3 ) + else { - lvc.fmt = LVCFMT_LEFT; // Left-aligned column. - lvc.cx = 150; - } + lvc.cx = lv_width-25; - else if ( iCol == 6 || iCol == 7) - { - lvc.fmt = LVCFMT_LEFT; // Right-aligned column. - lvc.cx = 100; } - else - { - lvc.fmt = LVCFMT_LEFT; // Right-aligned column. - lvc.cx = 230; - } - // Insert the columns into the list view. if (ListView_InsertColumn(hWndListView, iCol, &lvc) == -1) @@ -238,7 +223,8 @@ BOOL InsertItemFromStream(HWND hWndListView, t_stream* pt_stream) LVITEM lvI; int index=ListView_GetItemCount(hWndListView); int iCol; - TCHAR info[64]; + TCHAR info[128]; + t_ether_packet *pt_eth_hdr = pt_stream->data; // Initialize LVITEM members that are different for each item. { @@ -279,30 +265,50 @@ BOOL InsertItemFromStream(HWND hWndListView, t_stream* pt_stream) sprintf(info, "%d", index+1); ListView_SetItemText(hWndListView, index, 2, info); #endif + ListView_SetItemText(hWndListView, index, 3, pt_stream->name); + if (ntohs(pt_eth_hdr->type)!=ETH_P_IP) + { sprintf(info, "%02hhx %02hhx %02hhx %02hhx %02hhx %02hhx" - , pt_stream->eth_packet.dst[0] - , pt_stream->eth_packet.dst[1] - , pt_stream->eth_packet.dst[2] - , pt_stream->eth_packet.dst[3] - , pt_stream->eth_packet.dst[4] - , pt_stream->eth_packet.dst[5]); - ListView_SetItemText(hWndListView, index, 4, info); - - sprintf(info, "%02hhx %02hhx %02hhx %02hhx %02hhx %02hhx" - , pt_stream->eth_packet.src[0] - , pt_stream->eth_packet.src[1] - , pt_stream->eth_packet.src[2] - , pt_stream->eth_packet.src[3] - , pt_stream->eth_packet.src[4] - , pt_stream->eth_packet.src[5]); - ListView_SetItemText(hWndListView, index, 5, info); - - - sprintf(info, "%04hx", htons(pt_stream->eth_packet.type)); + , pt_stream->eth_packet.src[0] + , pt_stream->eth_packet.src[1] + , pt_stream->eth_packet.src[2] + , pt_stream->eth_packet.src[3] + , pt_stream->eth_packet.src[4] + , pt_stream->eth_packet.src[5]); + ListView_SetItemText(hWndListView, index, 4, info); + + + sprintf(info, "%02hhx %02hhx %02hhx %02hhx %02hhx %02hhx" + , pt_stream->eth_packet.dst[0] + , pt_stream->eth_packet.dst[1] + , pt_stream->eth_packet.dst[2] + , pt_stream->eth_packet.dst[3] + , pt_stream->eth_packet.dst[4] + , pt_stream->eth_packet.dst[5]); + ListView_SetItemText(hWndListView, index, 5, info); + + get_eth_type_name(ntohs(pt_stream->eth_packet.type), info); ListView_SetItemText(hWndListView, index, 6, info); + } + else + { + t_ip_hdr *iph=(void *)(pt_eth_hdr->payload); + ip_n2str(info, &(iph->saddr)); + ListView_SetItemText(hWndListView, index, 4, info); + + ip_n2str(info, &(iph->daddr)); + ListView_SetItemText(hWndListView, index, 5, info); + + get_protocol_name(iph->protocol, info); + + ListView_SetItemText(hWndListView, index, 6, info); + + + } + sprintf(info, "%d", pt_stream->len); ListView_SetItemText(hWndListView, index, 7, info); @@ -360,21 +366,40 @@ void update_grid_from_edit(int edit_iItem, int edit_iSubItem) { TCHAR buf[32]; t_stream* pt_stream=g_apt_streams[edit_iItem]; + t_ether_packet *pt_eth_hdr = pt_stream->data; + t_ip_hdr *iph=(void *)(pt_eth_hdr->payload); + GetWindowText(hwnd_dynamic_edit, buf, sizeof(buf)); ShowWindow (hwnd_dynamic_edit, 0); ListView_SetItemText(hwnd_lv, edit_iItem, edit_iSubItem, buf); if (edit_iSubItem==3) { strcpy(pt_stream->name, buf); + return; } - else if (edit_iSubItem==4) + + if (ntohs(pt_eth_hdr->type)!=ETH_P_IP) + { + if (edit_iSubItem==4) + { + mac_str2n(pt_stream->eth_packet.src, buf); + } + else if (edit_iSubItem==5) + { + mac_str2n(pt_stream->eth_packet.dst, buf); + } + return; + } + + if (edit_iSubItem==4) { - mac_str2n(pt_stream->eth_packet.dst, buf); + ip_str2n(&(iph->saddr), buf); } else if (edit_iSubItem==5) { - mac_str2n(pt_stream->eth_packet.src, buf); + ip_str2n(&(iph->daddr), buf); } + check_sum_proc(pt_stream); } @@ -470,7 +495,7 @@ void lv_row_color_init() lv_row_color[0]=GetSysColor (COLOR_WINDOW); lv_row_color[1]=colorShade(GetSysColor (COLOR_WINDOW), 95.0); lv_row_color[2]=RGB(0xA9, 0x13, 0x30); - lv_row_color[3]=RGB(0xEE, 0xEE, 0x00); + lv_row_color[3]=RGB(0xE6, 0x94, 0x1A); } diff --git a/src/stream_edit_dlg.c b/src/stream_edit_dlg.c index 7360145..a7a20f6 100644 --- a/src/stream_edit_dlg.c +++ b/src/stream_edit_dlg.c @@ -646,15 +646,25 @@ void get_pkt_desc_info(char *info, void* p_eth_hdr, uint32_t err_flags) t_arp_hdr *arp_hdr = (void *)(pt_eth_hdr->payload); t_icmp_hdr *icmp_hdr = ip_data(iph); t_tcp_hdr *tcp_hdr = ip_data(iph); + char info_2[64]; switch (ntohs(pt_eth_hdr->type)) { case ETH_P_ARP: - strcpy(info, "arp"); if (ntohs(arp_hdr->ar_op)==1) - strcat(info, " request"); + { + ip_n2str(info_2, arp_hdr->ar_tip); + sprintf(info, "who has %s? tell ", info_2); + ip_n2str(info_2, arp_hdr->ar_sip); + strcat(info, info_2); + } else if (ntohs(arp_hdr->ar_op)==2) - strcat(info, " reply"); + { + ip_n2str(info_2, arp_hdr->ar_sip); + sprintf(info, "%s is at ", info_2); + mac_n2str(info_2, arp_hdr->ar_sha); + strcat(info, info_2); + } goto append_err_info; @@ -670,15 +680,13 @@ void get_pkt_desc_info(char *info, void* p_eth_hdr, uint32_t err_flags) if (ntohs(pt_eth_hdr->type)!=ETH_P_IP) { - sprintf(info, "eth type:%hu", ntohs(pt_eth_hdr->type)); + sprintf(info, "eth type:0x%04x", ntohs(pt_eth_hdr->type)); goto append_err_info; } - sprintf(info, "%s ", protocol_name_map[iph->protocol]); - if (ip_pkt_is_frag(iph)) { - strcat(info, "frag "); + sprintf(info, "frag "); goto append_err_info; } @@ -691,7 +699,7 @@ void get_pkt_desc_info(char *info, void* p_eth_hdr, uint32_t err_flags) else if (icmp_hdr->type==0 && icmp_hdr->code==0) strcpy(info, "ping reply"); else - sprintf(info, "ICMP:type %hhu code %hhu", icmp_hdr->type, icmp_hdr->code); + sprintf(info, "type %hhu code %hhu", icmp_hdr->type, icmp_hdr->code); goto append_err_info; @@ -700,7 +708,7 @@ void get_pkt_desc_info(char *info, void* p_eth_hdr, uint32_t err_flags) goto append_err_info; case IPPROTO_TCP: - sprintf(info, "TCP port %hu->%hu[%s%s%s%s%s%s%s%s]" + sprintf(info, "port %hu->%hu[%s%s%s%s%s%s%s%s]" , ntohs(tcp_hdr->source), ntohs(tcp_hdr->dest) ,tcp_hdr->cwr?"cwr ":"" ,tcp_hdr->ece?"ece ":"" @@ -714,7 +722,7 @@ void get_pkt_desc_info(char *info, void* p_eth_hdr, uint32_t err_flags) goto append_err_info; case IPPROTO_UDP: - sprintf(info, "UDP port %hu->%hu", ntohs(tcp_hdr->source), ntohs(tcp_hdr->dest)); + sprintf(info, "port %hu->%hu", ntohs(tcp_hdr->source), ntohs(tcp_hdr->dest)); goto append_err_info; } @@ -1135,7 +1143,7 @@ void update_from_rule_data(HWND htv, HTREEITEM htvi) } -void check_sum_proc(t_stream *pt_stream, t_rule *pt_rule) +void check_sum_proc(t_stream *pt_stream) { t_ip_hdr *iph=(void *)(pt_stream->eth_packet.payload); if (ntohs(pt_stream->eth_packet.type)!=ETH_P_IP) return; @@ -1300,7 +1308,7 @@ void rule_fileds_init(t_stream *pt_stream) { pt_rule = &(pt_stream->at_rules[pt_stream->rule_idx[i]]); init_rule_field(pt_stream, pt_rule); - check_sum_proc(pt_stream, pt_rule); + check_sum_proc(pt_stream); } } @@ -1313,7 +1321,7 @@ void rule_fileds_update(t_stream *pt_stream) pt_rule = &(pt_stream->at_rules[pt_stream->rule_idx[i]]); update_rule_field(pt_stream, pt_rule); - check_sum_proc(pt_stream, pt_rule); + check_sum_proc(pt_stream); } } @@ -1775,9 +1783,9 @@ TCHAR *pkt_view_lv_col_names[] = { TEXT("索引"), TEXT("时间"), - TEXT("目的mac"), - TEXT("源mac"), - TEXT("类型"), + TEXT("源地址"), + TEXT("目的地址"), + TEXT("协议"), TEXT("长度"), TEXT("信息"), }; @@ -1786,16 +1794,28 @@ BOOL InitLvColumns(HWND hWndListView, int *col_width) { TCHAR szText[256]; // Temporary buffer. LVCOLUMN lvc; - int iCol; + int iCol, col_num = ARRAY_SIZE(pkt_view_lv_col_names); + +int lv_width = win_width(hWndListView); + lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM; // Add the columns. - for (iCol = 0; iCol < ARRAY_SIZE(pkt_view_lv_col_names); iCol++) + for (iCol = 0; iCol < col_num; iCol++) { lvc.iSubItem = iCol; lvc.pszText = pkt_view_lv_col_names[iCol]; lvc.fmt = LVCFMT_LEFT; // Left-aligned column. - lvc.cx = col_width[iCol]; + + if (iCol!= (col_num-1)) + { + lvc.cx = col_width[iCol]; + lv_width -= lvc.cx; + } + else + { + lvc.cx = lv_width-35; + } // Insert the columns into the list view. if (ListView_InsertColumn(hWndListView, iCol, &lvc) == -1) @@ -1814,11 +1834,12 @@ BOOL InsertItemFromPkt(HWND hWndListView, t_dump_pkt *pt_pkt, struct timeval *ba LVITEM lvI; int index=ListView_GetItemCount(hWndListView); int iCol; - TCHAR info[32]; + TCHAR info[128]; struct tm ltime; char timestr[32]; time_t local_tv_sec; struct timeval tmp=pt_pkt->header.ts; + t_ether_packet *pt_eth_hdr = pt_pkt->pkt_data; // Initialize LVITEM members that are different for each item. { @@ -1856,6 +1877,8 @@ BOOL InsertItemFromPkt(HWND hWndListView, t_dump_pkt *pt_pkt, struct timeval *ba #endif ListView_SetItemText(hWndListView, index, 1, info); + if (ntohs(pt_eth_hdr->type)!=ETH_P_IP) + { sprintf(info, "%02hhx %02hhx %02hhx %02hhx %02hhx %02hhx" , pt_pkt->pkt_data[0] , pt_pkt->pkt_data[1] @@ -1874,10 +1897,29 @@ BOOL InsertItemFromPkt(HWND hWndListView, t_dump_pkt *pt_pkt, struct timeval *ba , pt_pkt->pkt_data[11]); ListView_SetItemText(hWndListView, index, 3, info); - - sprintf(info, "%04hx", htons(*(unsigned short *)(pt_pkt->pkt_data+12))); + get_eth_type_name(ntohs(pt_eth_hdr->type), info); ListView_SetItemText(hWndListView, index, 4, info); + + } + else + { + t_ip_hdr *iph=(void *)(pt_eth_hdr->payload); + ip_n2str(info, &(iph->saddr)); + ListView_SetItemText(hWndListView, index, 2, info); + + ip_n2str(info, &(iph->saddr)); + ListView_SetItemText(hWndListView, index, 3, info); + + get_protocol_name(iph->protocol, info); + + ListView_SetItemText(hWndListView, index, 4, info); + + + } + + + sprintf(info, "%d", pt_pkt->header.caplen); ListView_SetItemText(hWndListView, index, 5, info); @@ -2042,7 +2084,7 @@ void init_ui_pkt_view(HWND hDlg) HWND hwnd_tree=GetDlgItem(hDlg,ID_VIEW_STREAM_TREE_VIEW); HWND hwnd_hexedit=GetDlgItem(hDlg,ID_VIEW_STREAM_HEX_EDIT); int lv_width=cxChar*120, lv_height=cxChar*28; - int col_width[] = {cxChar*10, cxChar*15, cxChar*20, cxChar*20, cxChar*8, cxChar*8, cxChar*34}; + int col_width[] = {cxChar*10, cxChar*15, cxChar*20, cxChar*20, cxChar*9, cxChar*7, cxChar*34}; SendMessage(hwnd_tree, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FIXED_FONT), 0); SendMessage(hlv, WM_SETFONT, (WPARAM)GetStockObject(SYSTEM_FIXED_FONT), 0); diff --git a/xb_ether_tester.nsi b/xb_ether_tester.nsi index 11de6ca..00dcbc8 100644 --- a/xb_ether_tester.nsi +++ b/xb_ether_tester.nsi @@ -12,7 +12,7 @@ ; HM NIS Edit Wizard helper defines !define PRODUCT_NAME "小兵以太网测试仪" -!define PRODUCT_VERSION "2.3.0" +!define PRODUCT_VERSION "2.3.1" !define PRODUCT_PUBLISHER "孙明保" !define PRODUCT_DIR_REGKEY "Software\Microsoft\Windows\CurrentVersion\App Paths\xb_ether_tester.exe" !define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"