11 #define UIP_LOG(m) uip_log(__FILE__,__LINE__,m)
14 #endif /* UIP_LOGGING == 1 */
16 #if UIP_STATISTICS == 1
17 struct uip_stats uip_stat
;
21 #endif /* UIP_STATISTICS == 1 */
23 void uip_icmpinput(struct uip_pbuf
*p
,struct uip_netif
*inp
)
27 struct uip_ip_addr tmpaddr
;
28 struct uip_ip_hdr
*iphdr
;
29 struct uip_icmp_echo_hdr
*iecho
;
32 hlen
= UIP_IPH_HL(iphdr
)*4;
33 if(uip_pbuf_header(p
,-((s16_t
)hlen
)) || p
->tot_len
<sizeof(u16_t
)*2) {
34 UIP_LOG("uip_icmpinput: short ICMP received.\n");
39 type
= *((u8_t
*)p
->payload
);
40 code
= *((u8_t
*)p
->payload
+1);
43 if(ip_addr_isbroadcast(&iphdr
->dst
,inp
) || ip_addr_ismulticast(&iphdr
->dst
)) {
44 UIP_LOG("uip_icmpinput: Not echoing to broadcast pings.\n");
49 if(p
->tot_len
<sizeof(struct uip_icmp_echo_hdr
)) {
50 UIP_LOG("uip_icmpinput: bad ICMP echo received.\n");
56 if(uip_ipchksum_pbuf(p
)!=0) {
57 UIP_LOG("uip_icmpinput: checksum failed for received ICMP echo.\n");
62 tmpaddr
.addr
= iphdr
->src
.addr
;
63 iphdr
->src
.addr
= iphdr
->dst
.addr
;
64 iphdr
->dst
.addr
= tmpaddr
.addr
;
65 UIP_ICMPH_TYPE_SET(iecho
,UIP_ICMP_ER
);
67 if(iecho
->chksum
>=htons(0xffff-(UIP_ICMP_ECHO
<<8))) iecho
->chksum
+= htons(UIP_ICMP_ECHO
<<8)+1;
68 else iecho
->chksum
+= htons(UIP_ICMP_ECHO
<<8);
70 uip_pbuf_header(p
,hlen
);
71 uip_ipoutput_if(p
,&iphdr
->src
,NULL
,UIP_IPH_TTL(iphdr
),0,UIP_PROTO_ICMP
,inp
);
74 UIP_LOG("uip_icmpinput: ICMP type/code not supported.\n");
80 void uip_icmp_destunreach(struct uip_pbuf
*p
,enum uip_icmp_dur_type t
)
83 struct uip_ip_hdr
*iphdr
;
84 struct uip_icmp_dur_hdr
*idur
;
86 q
= uip_pbuf_alloc(UIP_PBUF_IP
,sizeof(struct uip_icmp_dur_hdr
)+UIP_IP_HLEN
+8,UIP_PBUF_RAM
);
91 UIP_ICMPH_TYPE_SET(idur
,UIP_ICMP_DUR
);
92 UIP_ICMPH_CODE_SET(idur
,t
);
94 UIP_MEMCPY((u8_t
*)q
->payload
+sizeof(struct uip_icmp_dur_hdr
),p
->payload
,UIP_IP_HLEN
+8);
97 idur
->chksum
= uip_ipchksum(idur
,q
->len
);
99 uip_ipoutput(q
,NULL
,&iphdr
->src
,UIP_ICMP_TTL
,0,UIP_PROTO_ICMP
);