CODE REVIEW - record the amount of wifi devices broadcasting
Posted: Thu Nov 02, 2017 10:31 pm
Im trying to record the amount of wifi devices broadcasting by sniffing WiFi frames in promiscuous.
I pull the mac id from the frame and put it in an array. Before i put in the array I iterate through the array to check if its there already.
For some reason I end up with a few duplicates.
I am at my wits end. Any suggestions?
I pull the mac id from the frame and put it in an array. Before i put in the array I iterate through the array to check if its there already.
For some reason I end up with a few duplicates.
I am at my wits end. Any suggestions?
Code: Select all
void promisc_cb(uint8_t* buf, uint16_t len) {
wifi_promiscuous_enable(false);
sniffer = (struct sniffer_buf2*) buf;
String mac = "";
if ((bitRead(3, sniffer->buf[0]) == 0) && (bitRead(2, sniffer->buf[0])) == 0) {
//grab mac of sender
for (int i = 10; i < 16; i++)
{
mac = mac + String(sniffer->buf[i], HEX);
if (i < 15) {
mac = mac + ":";
}
}
if (!exists(mac, amountMacs)) {
amountMacs++;
macs[amountMacs] = mac;
printData(amountMacs);
}
}
}
void printData(int amount) {
for (int i = 0; i < amount; i++) {
Serial.print(String(i) + " " + macs[i] + " ** ");
}
Serial.println();
}
boolean exists(String mac, int amount) {
if (amount == 0) {
return false;
}
for (int i = 0; i < amount; i++) {
if (mac == macs[i]) {
return true;
}
}
return false;
}