|
|
@ -4,6 +4,7 @@ |
|
|
|
#include <QCoreApplication> |
|
|
|
#include <QRegularExpression> |
|
|
|
#include <interface.h> |
|
|
|
#include <neighbor.h> |
|
|
|
#include <QStringList> |
|
|
|
#include <QHash> |
|
|
|
|
|
|
@ -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<QString, QString> 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); |
|
|
|
|
|
|
|