46 |
void |
void |
47 |
icmp_input(struct pbuf *p, struct netif *inp) |
icmp_input(struct pbuf *p, struct netif *inp) |
48 |
{ |
{ |
49 |
unsigned char type; |
u8_t type; |
50 |
unsigned char code; |
u8_t code; |
51 |
struct icmp_echo_hdr *iecho; |
struct icmp_echo_hdr *iecho; |
52 |
struct ip_hdr *iphdr; |
struct ip_hdr *iphdr; |
53 |
struct ip_addr tmpaddr; |
struct ip_addr tmpaddr; |
60 |
iphdr = p->payload; |
iphdr = p->payload; |
61 |
hlen = IPH_HL(iphdr) * 4; |
hlen = IPH_HL(iphdr) * 4; |
62 |
if (pbuf_header(p, -((s16_t)hlen)) || (p->tot_len < sizeof(u16_t)*2)) { |
if (pbuf_header(p, -((s16_t)hlen)) || (p->tot_len < sizeof(u16_t)*2)) { |
63 |
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: short ICMP (%u bytes) received\n", p->tot_len)); |
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: short ICMP (%"U16_F" bytes) received\n", p->tot_len)); |
64 |
pbuf_free(p); |
pbuf_free(p); |
65 |
ICMP_STATS_INC(icmp.lenerr); |
ICMP_STATS_INC(icmp.lenerr); |
66 |
snmp_inc_icmpinerrors(); |
snmp_inc_icmpinerrors(); |
116 |
IPH_TTL(iphdr), 0, IP_PROTO_ICMP, inp); |
IPH_TTL(iphdr), 0, IP_PROTO_ICMP, inp); |
117 |
break; |
break; |
118 |
default: |
default: |
119 |
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: ICMP type %d code %d not supported.\n", (int)type, (int)code)); |
LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: ICMP type %"S16_F" code %"S16_F" not supported.\n", (s16_t)type, (s16_t)code)); |
120 |
ICMP_STATS_INC(icmp.proterr); |
ICMP_STATS_INC(icmp.proterr); |
121 |
ICMP_STATS_INC(icmp.drop); |
ICMP_STATS_INC(icmp.drop); |
122 |
} |
} |
139 |
ICMPH_TYPE_SET(idur, ICMP_DUR); |
ICMPH_TYPE_SET(idur, ICMP_DUR); |
140 |
ICMPH_CODE_SET(idur, t); |
ICMPH_CODE_SET(idur, t); |
141 |
|
|
142 |
memcpy((char *)q->payload + 8, p->payload, IP_HLEN + 8); |
memcpy((u8_t *)q->payload + 8, p->payload, IP_HLEN + 8); |
143 |
|
|
144 |
/* calculate checksum */ |
/* calculate checksum */ |
145 |
idur->chksum = 0; |
idur->chksum = 0; |
177 |
ICMPH_CODE_SET(tehdr, t); |
ICMPH_CODE_SET(tehdr, t); |
178 |
|
|
179 |
/* copy fields from original packet */ |
/* copy fields from original packet */ |
180 |
memcpy((char *)q->payload + 8, (char *)p->payload, IP_HLEN + 8); |
memcpy((u8_t *)q->payload + 8, (u8_t *)p->payload, IP_HLEN + 8); |
181 |
|
|
182 |
/* calculate checksum */ |
/* calculate checksum */ |
183 |
tehdr->chksum = 0; |
tehdr->chksum = 0; |