#include "lwip/opt.h"
#include "lwip/icmp.h"
#include "lwip/inet.h"
#include "lwip/ip.h"
#include "lwip/def.h"
#include "lwip/stats.h"
#include "lwip/snmp.h"
Include dependency graph for icmp.c:
Go to the source code of this file.
Defines | |
#define | htons HTONS |
#define | htonl HTONL |
Functions | |
void | icmp_input (struct pbuf *p, struct netif *inp) |
void | icmp_dest_unreach (struct pbuf *p, enum icmp_dur_type t) |
|
|
|
|
|
Definition at line 138 of file icmp.c.
00139 { 00140 struct pbuf *q; 00141 struct ip_hdr *iphdr; 00142 struct icmp_dur_hdr *idur; 00143 00144 q = pbuf_alloc(PBUF_IP, 8 + IP_HLEN + 8, PBUF_RAM); 00145 /* ICMP header + IP header + 8 bytes of data */ 00146 00147 iphdr = p->payload; 00148 00149 idur = q->payload; 00150 ICMPH_TYPE_SET(idur, ICMP_DUR); 00151 ICMPH_CODE_SET(idur, t); 00152 00153 memcpy((char *)q->payload + 8, p->payload, IP_HLEN + 8); 00154 00155 /* calculate checksum */ 00156 idur->chksum = 0; 00157 idur->chksum = inet_chksum(idur, q->len); 00158 #ifdef ICMP_STATS 00159 ++lwip_stats.icmp.xmit; 00160 #endif /* ICMP_STATS */ 00161 /* increase number of messages attempted to send */ 00162 snmp_inc_icmpoutmsgs(); 00163 /* increase number of destination unreachable messages attempted to send */ 00164 snmp_inc_icmpoutdestunreachs(); 00165 00166 ip_output(q, NULL, &(iphdr->src), 00167 ICMP_TTL, IP_PROTO_ICMP); 00168 pbuf_free(q); 00169 } |
|
Definition at line 52 of file icmp.c.
00053 { 00054 unsigned char type; 00055 struct icmp_echo_hdr *iecho; 00056 struct ip_hdr *iphdr; 00057 struct ip_addr tmpaddr; 00058 u16_t hlen; 00059 00060 #ifdef ICMP_STATS 00061 ++lwip_stats.icmp.recv; 00062 #endif /* ICMP_STATS */ 00063 snmp_inc_icmpinmsgs(); 00064 00065 00066 iphdr = p->payload; 00067 hlen = IPH_HL(iphdr) * 4; 00068 pbuf_header(p, -((s16_t)hlen)); 00069 00070 type = *((u8_t *)p->payload); 00071 00072 switch(type) { 00073 case ICMP_ECHO: 00074 if(ip_addr_isbroadcast(&iphdr->dest, &inp->netmask) || 00075 ip_addr_ismulticast(&iphdr->dest)) { 00076 DEBUGF(ICMP_DEBUG, ("Smurf.\n")); 00077 #ifdef ICMP_STATS 00078 ++lwip_stats.icmp.err; 00079 #endif /* ICMP_STATS */ 00080 pbuf_free(p); 00081 return; 00082 } 00083 DEBUGF(ICMP_DEBUG, ("icmp_input: ping\n")); 00084 DEBUGF(DEMO_DEBUG, ("Pong!\n")); 00085 if(p->tot_len < sizeof(struct icmp_echo_hdr)) { 00086 DEBUGF(ICMP_DEBUG, ("icmp_input: bad ICMP echo received\n")); 00087 pbuf_free(p); 00088 #ifdef ICMP_STATS 00089 ++lwip_stats.icmp.lenerr; 00090 #endif /* ICMP_STATS */ 00091 snmp_inc_icmpinerrors(); 00092 00093 return; 00094 } 00095 iecho = p->payload; 00096 if(inet_chksum_pbuf(p) != 0) { 00097 DEBUGF(ICMP_DEBUG, ("icmp_input: checksum failed for received ICMP echo\n")); 00098 pbuf_free(p); 00099 #ifdef ICMP_STATS 00100 ++lwip_stats.icmp.chkerr; 00101 #endif /* ICMP_STATS */ 00102 snmp_inc_icmpinerrors(); 00103 return; 00104 } 00105 tmpaddr.addr = iphdr->src.addr; 00106 iphdr->src.addr = iphdr->dest.addr; 00107 iphdr->dest.addr = tmpaddr.addr; 00108 ICMPH_TYPE_SET(iecho, ICMP_ER); 00109 /* adjust the checksum */ 00110 if(iecho->chksum >= htons(0xffff - (ICMP_ECHO << 8))) { 00111 iecho->chksum += htons(ICMP_ECHO << 8) + 1; 00112 } else { 00113 iecho->chksum += htons(ICMP_ECHO << 8); 00114 } 00115 #ifdef ICMP_STATS 00116 ++lwip_stats.icmp.xmit; 00117 #endif /* ICMP_STATS */ 00118 /* increase number of messages attempted to send */ 00119 snmp_inc_icmpoutmsgs(); 00120 /* increase number of echo replies attempted to send */ 00121 snmp_inc_icmpoutechoreps(); 00122 00123 pbuf_header(p, hlen); 00124 ip_output_if(p, &(iphdr->src), IP_HDRINCL, 00125 IPH_TTL(iphdr), IP_PROTO_ICMP, inp); 00126 break; 00127 default: 00128 DEBUGF(ICMP_DEBUG, ("icmp_input: ICMP type not supported.\n")); 00129 #ifdef ICMP_STATS 00130 ++lwip_stats.icmp.proterr; 00131 ++lwip_stats.icmp.drop; 00132 #endif /* ICMP_STATS */ 00133 } 00134 pbuf_free(p); 00135 } |