OCT 1. 修改所有模块默认配置为 INFO

2. 增加测试工具 HEX 数据包值计算
This commit is contained in:
黄昕 2023-05-08 17:52:19 +08:00
parent 07de7b4c2f
commit 6d59ecacfa
4 changed files with 123 additions and 56 deletions

View File

@ -20,7 +20,10 @@ static GtkWidget *g_detailWnd = NULL;
static GtkWidget *g_statusBar = NULL;
static GtkTextBuffer *g_pTxtBuf[4];
static GtkWidget *g_ptvDHcp[4];
static GtkWidget *g_pSelVal[4];
static PBUF_INFO g_HexBuf[4];
static PDHCP_INFO g_preInfo = NULL;
static U32 g_curPage = 0;
static const char *g_mess_info[] = {"NONE", "DISCOVER", "OFFER", "REQUEST", "DECLINE",
"ACK", "NAK", "RELEASE", "INFORM"};
@ -348,7 +351,6 @@ static gboolean upgrade_statusbar_proc(gpointer user_data) {
void details_wnd_show(PDHCP_INFO pInfo) {
int i;
PBUF_INFO hexBuf[4];
GtkTextIter iter, iter1;
if (pInfo) {
@ -363,16 +365,16 @@ void details_wnd_show(PDHCP_INFO pInfo) {
}
}
hexBuf[0] = &pInfo->pDiscBuf;
hexBuf[1] = &pInfo->pOfferBuf;
hexBuf[2] = &pInfo->pReqBuf;
hexBuf[3] = &pInfo->pAckBuf;
g_HexBuf[0] = &pInfo->pDiscBuf;
g_HexBuf[1] = &pInfo->pOfferBuf;
g_HexBuf[2] = &pInfo->pReqBuf;
g_HexBuf[3] = &pInfo->pAckBuf;
// 填充HEX 窗口数据
for (i = 0; i < 4; i++) {
char buf[128] = {0};
U32 offset = 0;
if (hexBuf[i]->buf_size == 0) {
if (g_HexBuf[i]->buf_size == 0) {
continue;
}
@ -387,7 +389,7 @@ void details_wnd_show(PDHCP_INFO pInfo) {
sprintf(buf, " Offset(h) 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F ASCII Tables\n");
gtk_text_buffer_insert_with_tags_by_name(g_pTxtBuf[i], &iter, buf, -1, "hex_head", NULL);
int row = hexBuf[i]->buf_size / 16 + ((hexBuf[i]->buf_size % 16) > 0 ? 1 : 0);
int row = g_HexBuf[i]->buf_size / 16 + ((g_HexBuf[i]->buf_size % 16) > 0 ? 1 : 0);
for (int k = 0; k < row; k++) {
char bufOffset[24] = {0};
@ -397,7 +399,7 @@ void details_wnd_show(PDHCP_INFO pInfo) {
for (int m = 0; m < 16; m++) {
char bufStr[4] = {0};
sprintf(bufStr, "%02X ", hexBuf[i]->p[k * 16 + m]);
sprintf(bufStr, "%02X ", g_HexBuf[i]->p[k * 16 + m]);
strcat(buf, bufStr);
if (m == 7 || m == 15) {
strcat(buf, " ");
@ -405,9 +407,9 @@ void details_wnd_show(PDHCP_INFO pInfo) {
}
for (int m = 0; m < 16; m++) {
if (isprint(hexBuf[i]->p[k * 16 + m])) {
if (isprint(g_HexBuf[i]->p[k * 16 + m])) {
char bufStr[2] = {0};
bufStr[0] = (char)hexBuf[i]->p[k * 16 + m];
bufStr[0] = (char)g_HexBuf[i]->p[k * 16 + m];
strcat(buf, bufStr);
} else {
strcat(buf, ".");
@ -420,7 +422,7 @@ void details_wnd_show(PDHCP_INFO pInfo) {
// 填充 TreeView
add_dhcp_tree_colums(g_ptvDHcp[i]);
create_dhcp_tree_mode((PDHCP_PACKAGE)hexBuf[i]->p, hexBuf[i]->buf_size, g_ptvDHcp[i]);
create_dhcp_tree_mode((PDHCP_PACKAGE)g_HexBuf[i]->p, g_HexBuf[i]->buf_size, g_ptvDHcp[i]);
}
upgrade_statusbar_proc(pInfo);
@ -431,33 +433,97 @@ void details_wnd_show(PDHCP_INFO pInfo) {
}
static gboolean button_release_event(GtkWidget *self, GdkEventButton UNUSED(event), gpointer UNUSED(user_data)) {
GtkTextIter iter, start_sel, end_sel;
int row, col;
GtkTextIter iter;
GtkTreeIter it;
GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(g_pSelVal[g_curPage]));
GtkListStore *store = GTK_LIST_STORE(model);
GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(self));
gtk_text_buffer_get_iter_at_mark(buffer, &iter, gtk_text_buffer_get_insert(buffer));
int row = gtk_text_iter_get_line(&iter);
int col = gtk_text_iter_get_line_offset(&iter);
row = gtk_text_iter_get_line(&iter);
col = gtk_text_iter_get_line_offset(&iter);
if (col <= 57 && col >= 11) {
if ((col <= 35 && ((col - 11) % 3) == 0) || (col > 35 && (col - 12) % 3 == 0)) {
GtkTextMark *mark = gtk_text_buffer_get_insert(buffer);
gtk_text_buffer_get_iter_at_mark(buffer, &start_sel, mark);
gtk_text_buffer_get_iter_at_line_offset(buffer, &end_sel, row, 59);
//char *text = (char *)gtk_text_buffer_get_text(buffer, &iter, &end_sel, FALSE);
//printf("Select %s(%d, %d)\n", text, row, col);
}
if (gtk_tree_model_get_iter_first(model, &it)) {
gtk_list_store_clear(store);
}
if (col >= 11 && col < 59 && row > 0) {
int k;
int id;
U8 valBuf[8] = {0};
sds s = sdsempty();
const char *binTbl[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111",
"1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
const char *itemTitle[] = {"Binary", "unsigne char", "unsigne short", "unsigne int", "unsigne long long",
"char", "short", "int", "long long"};
if (col >= 35) {
k = col - 12;
} else {
k = col - 11;
}
id = (row - 1) * 16 + (k + 1) / 3;
//printf("Select at(%d, %d), %d, %d, %d of %d\n", row, col, k, (k + 1) / 3, id, g_curPage);
memcpy(valBuf, &g_HexBuf[g_curPage]->p[id], MIN(8, g_HexBuf[g_curPage]->buf_size - id));
printf("%d, %d, %s, %s\n", valBuf[0] >> 4, valBuf[0] & 0x0F, binTbl[(valBuf[0] >> 4) & 0xF],
binTbl[valBuf[0] & 0x0F]);
sprintf(s, "%s%s", binTbl[(valBuf[0] >> 4) & 0xF], binTbl[valBuf[0] & 0x0F]);
gtk_list_store_append(store, &it);
gtk_list_store_set(store, &it, 0, itemTitle[0], 1, s, -1);
sdsclear(s);
sprintf(s, "%u", valBuf[0]);
gtk_list_store_append(store, &it);
gtk_list_store_set(store, &it, 0, itemTitle[1], 1, s, -1);
sdsclear(s);
sprintf(s, "%u", *(unsigned short *)valBuf);
gtk_list_store_append(store, &it);
gtk_list_store_set(store, &it, 0, itemTitle[2], 1, s, -1);
sdsclear(s);
sprintf(s, "%u", *(unsigned int *)valBuf);
gtk_list_store_append(store, &it);
gtk_list_store_set(store, &it, 0, itemTitle[3], 1, s, -1);
sdsclear(s);
sprintf(s, "%llu", *(unsigned long long *)valBuf);
gtk_list_store_append(store, &it);
gtk_list_store_set(store, &it, 0, itemTitle[4], 1, s, -1);
sdsclear(s);
sprintf(s, "%d", valBuf[0]);
gtk_list_store_append(store, &it);
gtk_list_store_set(store, &it, 0, itemTitle[5], 1, s, -1);
sdsclear(s);
sprintf(s, "%d", *(short *)valBuf);
gtk_list_store_append(store, &it);
gtk_list_store_set(store, &it, 0, itemTitle[6], 1, s, -1);
sdsclear(s);
sprintf(s, "%d", *(int *)valBuf);
gtk_list_store_append(store, &it);
gtk_list_store_set(store, &it, 0, itemTitle[7], 1, s, -1);
sdsclear(s);
sprintf(s, "%lld", *(long long *)valBuf);
gtk_list_store_append(store, &it);
gtk_list_store_set(store, &it, 0, itemTitle[8], 1, s, -1);
sdsfree(s);
}
return FALSE;
}
void switch_page(GtkNotebook *UNUSED(self),
GtkWidget *UNUSED(page),
guint UNUSED(page_num),
gpointer UNUSED(user_data)) {
void switch_page(GtkNotebook *UNUSED(self), GtkWidget *UNUSED(page), guint(page_num), gpointer UNUSED(user_data)) {
if (g_preInfo) {
details_wnd_show(g_preInfo);
upgrade_statusbar_proc(g_preInfo);
}
g_curPage = page_num;
}
void details_wnd_create(GtkBuilder *builder) {
@ -478,6 +544,7 @@ void details_wnd_create(GtkBuilder *builder) {
// 页标签的位置,可以有四种位置:上、下、左或右。
gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP);
g_signal_connect(notebook, "switch-page", G_CALLBACK(switch_page), NULL);
gtk_widget_set_name(notebook, "nbDhcpInfo");
for (int i = 0; i < 4; i++) {
GtkTreeIter iter;
@ -521,13 +588,6 @@ void details_wnd_create(GtkBuilder *builder) {
gtk_tree_view_append_column(GTK_TREE_VIEW(tvHex), column);
GtkListStore *store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_STRING);
const char *itemTitle[] = {"Binary", "unsigne char", "unsigne short", "unsigne int", "unsigne char long long",
"char", "short", "int", "long long"};
for (int k = 0; k < ARRAY_SIZE(itemTitle); k++) {
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, 0, itemTitle[k], 1, "", -1);
}
gtk_tree_view_set_model(GTK_TREE_VIEW(tvHex), GTK_TREE_MODEL(store));
gtk_tree_view_set_grid_lines(GTK_TREE_VIEW(tvHex), GTK_TREE_VIEW_GRID_LINES_BOTH);
@ -552,6 +612,7 @@ void details_wnd_create(GtkBuilder *builder) {
g_signal_connect(G_OBJECT(scText), "button_release_event", G_CALLBACK(button_release_event), builder);
g_ptvDHcp[i] = tvDhcp;
g_pSelVal[i] = tvHex;
}
g_statusBar = gtk_statusbar_new();

View File

@ -46,6 +46,7 @@ const char *u32_to_str_ip_safe(unsigned int ip);
unsigned short udp_checksum(unsigned int saddr, unsigned int daddr, unsigned char *pUdp);
unsigned short ip_checksum(unsigned char *pIp);
int string_mac_to_bytes(const char *pStrMac, unsigned char macByte[6]);
unsigned long long ntohll(unsigned long long val);
#ifdef __cplusplus
}
#endif

View File

@ -25,30 +25,30 @@ typedef enum {
} ZLOG_LV;
#define DEF_ZLOG_MOD(ZLOG_MOD) \
ZLOG_MOD(ZLOG_MOD_MAIN, ZLOG_LEVEL_DEBUG, "MAIN") \
ZLOG_MOD(ZLOG_MOD_TASK, ZLOG_LEVEL_DEBUG, "TASK") \
ZLOG_MOD(ZLOG_MOD_INIT, ZLOG_LEVEL_DEBUG, "INIT") \
ZLOG_MOD(ZLOG_MOD_MISC, ZLOG_LEVEL_DEBUG, "MISC") \
ZLOG_MOD(ZLOG_MOD_WATCH, ZLOG_LEVEL_DEBUG, "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LOG_MOD_ENUM(ENUM, lv, x) ENUM,

View File

@ -267,6 +267,11 @@ const char *u32_to_str_ip_safe(unsigned int ip) {
return strdup(inet_ntoa(s));
}
unsigned long long ntohll(unsigned long long val)
{
return (((unsigned long long) ntohl(val)) << 32) + ntohl(val >> 32);
}
int get_all_network_info(PSYS_NIC_INFO pInfo) {
int i;
unsigned long nicCnt;