From 44466c949347074acefbf29eaeeaaa285c1f9626 Mon Sep 17 00:00:00 2001 From: Brad Parker Date: Wed, 4 Sep 2013 01:07:39 -0400 Subject: [PATCH] add ARP table info --- tui/main.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/tui/main.cpp b/tui/main.cpp index cc60261..c9e9ba3 100644 --- a/tui/main.cpp +++ b/tui/main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -58,6 +59,7 @@ check_return: delwin(msgbox); } +void arpMenu(WINDOW *window); void interfaceMenu(WINDOW *window); void interfaceSelect(WINDOW *window, QString interface); @@ -90,10 +92,78 @@ void mainmenu(WINDOW *window) { }else{ if(c == '1') { interfaceMenu(window); + }else if(c == '2') { + arpMenu(window); } } } +void arpMenu(WINDOW *window) { + wclear(window); + + cyan(window); + box(window, 0, 0); + + red(window); + mvwaddstr(window, 1, 2, "APR Table:"); + + green(window); + + QHash arpList = Neighbor::list(QString()); + + int y = 3; + int width = 0; + int widthMAC = 0; + int widthIP = 0; + QString format = "%-"; + + foreach(QString arp, arpList.keys()) { + QString mac = arpList.value(arp); + widthMAC = qMax(widthMAC, mac.length()); + widthIP = qMax(widthIP, arp.length()); + } + + width = widthMAC + widthIP; + format += QString::number(widthIP) + "s at %" + QString::number(widthMAC) + "s"; + + QByteArray formatArr = format.toLatin1(); + const char *formatStr = formatArr.constData(); + char *str = (char*)malloc(width + 5); + + foreach(QString arp, arpList.keys()) { + //arp = QString::number(count) + ". " + arp; + memset(str, 0, width + 5); + QByteArray arpArray = arp.toLatin1(); + QString arpMac = arpList.value(arp); + QByteArray arpMacArray = arpMac.toLatin1(); + const char *arpStr = arpArray.constData(); + const char *arpMacStr = arpMacArray.constData(); + + snprintf(str, width + 4, formatStr, arpStr, arpMacStr); + /*memcpy(str, arpStr, strlen(arpStr)); + memcpy(str + strlen(arpStr), " at ", 4); + memcpy(str + strlen(arpStr) + 4, arpMacStr, strlen(arpMacStr));*/ + + mvwaddstr(window, y, 2, str); + + ++y; + } + + free(str); + cyan(window); + mvwaddstr(window, y + 1, 2, "0. Back to main menu"); + wrefresh(window); + +arpChar: + char c = getch(); + + if(c != '0') { + goto arpChar; + }else{ + mainmenu(window); + } +} + void interfaceMenu(WINDOW *window) { wclear(window);