Show the packets arriving at LwIP

This commit is contained in:
Florian Hoss 2022-07-25 16:28:55 +02:00
parent 0422eeeb9a
commit 8c36882772
2 changed files with 26 additions and 2 deletions

View file

@ -3,7 +3,10 @@
#include "lwip/netif.h" #include "lwip/netif.h"
#include "lwip/pbuf.h" #include "lwip/pbuf.h"
#include "lwip/ip4.h"
#include "esp_log.h" #include "esp_log.h"
#include "esp_err.h"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"

View file

@ -1,7 +1,28 @@
#include "lwip_hooks.h" #include "lwip_hooks.h"
const char *get_protocol(u16_t type)
{
switch (type)
{
case 1:
return "ICMP";
case 6:
return "TCP";
case 17:
return "UDP";
default:
return "-";
}
}
int lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif) int lwip_hook_ip4_input(struct pbuf *pbuf, struct netif *input_netif)
{ {
ESP_LOGI("Hook", "Testing..."); const struct ip_hdr *iphdr;
return 0; char ip_address[IP_HLEN];
iphdr = (struct ip_hdr *)pbuf->payload;
sprintf(ip_address, "%d.%d.%d.%d", ip4_addr1_16_val(iphdr->src), ip4_addr2_16_val(iphdr->src), ip4_addr3_16_val(iphdr->src), ip4_addr4_16_val(iphdr->src));
ESP_LOGI("HOOK", "%s: %s",
get_protocol((u16_t)IPH_PROTO(iphdr)), ip_address);
return ESP_OK;
} }