1 // SPDX-License-Identifier: GPL-2.0+ 2 /* Copyright (C) 2025 Linaro Ltd. */ 3 4 #include <lwip/icmp.h> 5 #include <lwip/ip4_addr.h> 6 #include <lwip/pbuf.h> 7 #include <lwip/prot/ip4.h> 8 code_to_str(int code)9static const char *code_to_str(int code) 10 { 11 switch (code) { 12 case ICMP_DUR_NET: 13 return "network unreachable"; 14 case ICMP_DUR_HOST: 15 return "host unreachable"; 16 case ICMP_DUR_PROTO: 17 return "protocol unreachable"; 18 case ICMP_DUR_PORT: 19 return "port unreachable"; 20 case ICMP_DUR_FRAG: 21 return "fragmentation needed and DF set"; 22 case ICMP_DUR_SR: 23 return "source route failed"; 24 default: 25 break; 26 } 27 return "unknown cause"; 28 } 29 net_lwip_icmp_dest_unreach(int code,struct pbuf * p)30void net_lwip_icmp_dest_unreach(int code, struct pbuf *p) 31 { 32 struct ip_hdr *iphdr = (struct ip_hdr *)p->payload; 33 ip4_addr_t src; 34 35 ip4_addr_copy(src, iphdr->src); 36 printf("ICMP destination unreachable (%s) from %s\n", 37 code_to_str(code), ip4addr_ntoa(&src)); 38 } 39