This repository has been archived by the owner on Jun 1, 2024. It is now read-only.
forked from n0xa/m5stick-nemo
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy patharp.h
85 lines (68 loc) · 2.24 KB
/
arp.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include "lwip/opt.h"
#include "esp_eth.h"
#include "lwip/etharp.h"
#include "lwip/stats.h"
#include "lwip/snmp.h"
#include "lwip/dhcp.h"
#include "lwip/autoip.h"
#include "nvs_flash.h"
#include "lwip/pbuf.h"
#include "lwip/netif.h"
#include "lwip/ip_addr.h"
#include "lwip/ethip6.h"
#include "lwip/ip.h"
#include "lwip/ip4_addr.h"
#include "lwip/prot/udp.h"
#define ARP_TABLE_SIZE 30 // TODO: this probably is causing inconsistance
int etharp_get_entry(size_t i, ip4_addr_t **ipaddr, struct netif **netif, struct eth_addr **eth_ret);
void print_arp_table() {
struct netif *existing_netif = netif_default;
if (existing_netif != NULL) {
ip4_addr_t *printed_addresses[ARP_TABLE_SIZE];
memset(printed_addresses, 0, sizeof(printed_addresses));
for (int i = 0; i < ARP_TABLE_SIZE; i++) {
ip4_addr_t *ipaddr;
struct netif *netif_entry;
struct eth_addr *eth_ret;
int result = etharp_get_entry(i, &ipaddr, &netif_entry, ð_ret);
delay(1000);
if (result == 0 && ipaddr != NULL) {
// Check if the IP address has already been printed
int is_duplicate = 0;
for (int j = 0; j < ARP_TABLE_SIZE; j++) {
if (printed_addresses[j] != NULL && ip4_addr_cmp(ipaddr, printed_addresses[j])) {
is_duplicate = 1;
break;
}
}
if (!is_duplicate) {
Serial.print("IP: ");
Serial.print(ip4addr_ntoa(ipaddr));
DISP.println(ip4addr_ntoa(ipaddr));
Serial.print("\tMAC: ");
char mac_str[18];
snprintf(mac_str, sizeof(mac_str), "%02X:%02X:%02X:%02X:%02X:%02X",
eth_ret->addr[0], eth_ret->addr[1], eth_ret->addr[2],
eth_ret->addr[3], eth_ret->addr[4], eth_ret->addr[5]);
Serial.print(mac_str);
Serial.println();
for (int j = 0; j < ARP_TABLE_SIZE; j++) {
if (printed_addresses[j] == NULL) {
printed_addresses[j] = ipaddr;
break;
}
}
}
}
}
} else {
Serial.println("No network interface available.");
}
}
void local_scan_setup(String local_ip) {
Serial.printf("starting ARP scan");
print_arp_table();
}
void local_scan_loop() {
//print_arp_table();
}