I have a problem getting this to work. Server only recieves half of the data being sent. Whats wrong

Dependencies:   mbed

Committer:
tax
Date:
Tue Mar 29 13:20:15 2011 +0000
Revision:
0:66300c77c6e9

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tax 0:66300c77c6e9 1 /**
tax 0:66300c77c6e9 2 * @file
tax 0:66300c77c6e9 3 * ICMP - Internet Control Message Protocol
tax 0:66300c77c6e9 4 *
tax 0:66300c77c6e9 5 */
tax 0:66300c77c6e9 6
tax 0:66300c77c6e9 7 /*
tax 0:66300c77c6e9 8 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
tax 0:66300c77c6e9 9 * All rights reserved.
tax 0:66300c77c6e9 10 *
tax 0:66300c77c6e9 11 * Redistribution and use in source and binary forms, with or without modification,
tax 0:66300c77c6e9 12 * are permitted provided that the following conditions are met:
tax 0:66300c77c6e9 13 *
tax 0:66300c77c6e9 14 * 1. Redistributions of source code must retain the above copyright notice,
tax 0:66300c77c6e9 15 * this list of conditions and the following disclaimer.
tax 0:66300c77c6e9 16 * 2. Redistributions in binary form must reproduce the above copyright notice,
tax 0:66300c77c6e9 17 * this list of conditions and the following disclaimer in the documentation
tax 0:66300c77c6e9 18 * and/or other materials provided with the distribution.
tax 0:66300c77c6e9 19 * 3. The name of the author may not be used to endorse or promote products
tax 0:66300c77c6e9 20 * derived from this software without specific prior written permission.
tax 0:66300c77c6e9 21 *
tax 0:66300c77c6e9 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
tax 0:66300c77c6e9 23 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
tax 0:66300c77c6e9 24 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
tax 0:66300c77c6e9 25 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
tax 0:66300c77c6e9 26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
tax 0:66300c77c6e9 27 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
tax 0:66300c77c6e9 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
tax 0:66300c77c6e9 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
tax 0:66300c77c6e9 30 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
tax 0:66300c77c6e9 31 * OF SUCH DAMAGE.
tax 0:66300c77c6e9 32 *
tax 0:66300c77c6e9 33 * This file is part of the lwIP TCP/IP stack.
tax 0:66300c77c6e9 34 *
tax 0:66300c77c6e9 35 * Author: Adam Dunkels <adam@sics.se>
tax 0:66300c77c6e9 36 *
tax 0:66300c77c6e9 37 */
tax 0:66300c77c6e9 38
tax 0:66300c77c6e9 39 /* Some ICMP messages should be passed to the transport protocols. This
tax 0:66300c77c6e9 40 is not implemented. */
tax 0:66300c77c6e9 41
tax 0:66300c77c6e9 42 #include "lwip/opt.h"
tax 0:66300c77c6e9 43
tax 0:66300c77c6e9 44 #if LWIP_ICMP /* don't build if not configured for use in lwipopts.h */
tax 0:66300c77c6e9 45
tax 0:66300c77c6e9 46 #include "lwip/icmp.h"
tax 0:66300c77c6e9 47 #include "lwip/inet_chksum.h"
tax 0:66300c77c6e9 48 #include "lwip/ip.h"
tax 0:66300c77c6e9 49 #include "lwip/def.h"
tax 0:66300c77c6e9 50 #include "lwip/stats.h"
tax 0:66300c77c6e9 51 #include "lwip/snmp.h"
tax 0:66300c77c6e9 52
tax 0:66300c77c6e9 53 #include <string.h>
tax 0:66300c77c6e9 54
tax 0:66300c77c6e9 55 /** Small optimization: set to 0 if incoming PBUF_POOL pbuf always can be
tax 0:66300c77c6e9 56 * used to modify and send a response packet (and to 1 if this is not the case,
tax 0:66300c77c6e9 57 * e.g. when link header is stripped of when receiving) */
tax 0:66300c77c6e9 58 #ifndef LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN
tax 0:66300c77c6e9 59 #define LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN 1
tax 0:66300c77c6e9 60 #endif /* LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN */
tax 0:66300c77c6e9 61
tax 0:66300c77c6e9 62 /* The amount of data from the original packet to return in a dest-unreachable */
tax 0:66300c77c6e9 63 #define ICMP_DEST_UNREACH_DATASIZE 8
tax 0:66300c77c6e9 64
tax 0:66300c77c6e9 65 static void icmp_send_response(struct pbuf *p, u8_t type, u8_t code);
tax 0:66300c77c6e9 66
tax 0:66300c77c6e9 67 /**
tax 0:66300c77c6e9 68 * Processes ICMP input packets, called from ip_input().
tax 0:66300c77c6e9 69 *
tax 0:66300c77c6e9 70 * Currently only processes icmp echo requests and sends
tax 0:66300c77c6e9 71 * out the echo response.
tax 0:66300c77c6e9 72 *
tax 0:66300c77c6e9 73 * @param p the icmp echo request packet, p->payload pointing to the ip header
tax 0:66300c77c6e9 74 * @param inp the netif on which this packet was received
tax 0:66300c77c6e9 75 */
tax 0:66300c77c6e9 76 void
tax 0:66300c77c6e9 77 icmp_input(struct pbuf *p, struct netif *inp)
tax 0:66300c77c6e9 78 {
tax 0:66300c77c6e9 79 u8_t type;
tax 0:66300c77c6e9 80 #ifdef LWIP_DEBUG
tax 0:66300c77c6e9 81 u8_t code;
tax 0:66300c77c6e9 82 #endif /* LWIP_DEBUG */
tax 0:66300c77c6e9 83 struct icmp_echo_hdr *iecho;
tax 0:66300c77c6e9 84 struct ip_hdr *iphdr;
tax 0:66300c77c6e9 85 s16_t hlen;
tax 0:66300c77c6e9 86
tax 0:66300c77c6e9 87 ICMP_STATS_INC(icmp.recv);
tax 0:66300c77c6e9 88 snmp_inc_icmpinmsgs();
tax 0:66300c77c6e9 89
tax 0:66300c77c6e9 90
tax 0:66300c77c6e9 91 iphdr = (struct ip_hdr *)p->payload;
tax 0:66300c77c6e9 92 hlen = IPH_HL(iphdr) * 4;
tax 0:66300c77c6e9 93 if (pbuf_header(p, -hlen) || (p->tot_len < sizeof(u16_t)*2)) {
tax 0:66300c77c6e9 94 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: short ICMP (%"U16_F" bytes) received\n", p->tot_len));
tax 0:66300c77c6e9 95 goto lenerr;
tax 0:66300c77c6e9 96 }
tax 0:66300c77c6e9 97
tax 0:66300c77c6e9 98 type = *((u8_t *)p->payload);
tax 0:66300c77c6e9 99 #ifdef LWIP_DEBUG
tax 0:66300c77c6e9 100 code = *(((u8_t *)p->payload)+1);
tax 0:66300c77c6e9 101 #endif /* LWIP_DEBUG */
tax 0:66300c77c6e9 102 switch (type) {
tax 0:66300c77c6e9 103 case ICMP_ER:
tax 0:66300c77c6e9 104 /* This is OK, echo reply might have been parsed by a raw PCB
tax 0:66300c77c6e9 105 (as obviously, an echo request has been sent, too). */
tax 0:66300c77c6e9 106 break;
tax 0:66300c77c6e9 107 case ICMP_ECHO:
tax 0:66300c77c6e9 108 #if !LWIP_MULTICAST_PING || !LWIP_BROADCAST_PING
tax 0:66300c77c6e9 109 {
tax 0:66300c77c6e9 110 int accepted = 1;
tax 0:66300c77c6e9 111 #if !LWIP_MULTICAST_PING
tax 0:66300c77c6e9 112 /* multicast destination address? */
tax 0:66300c77c6e9 113 if (ip_addr_ismulticast(&current_iphdr_dest)) {
tax 0:66300c77c6e9 114 accepted = 0;
tax 0:66300c77c6e9 115 }
tax 0:66300c77c6e9 116 #endif /* LWIP_MULTICAST_PING */
tax 0:66300c77c6e9 117 #if !LWIP_BROADCAST_PING
tax 0:66300c77c6e9 118 /* broadcast destination address? */
tax 0:66300c77c6e9 119 if (ip_addr_isbroadcast(&current_iphdr_dest, inp)) {
tax 0:66300c77c6e9 120 accepted = 0;
tax 0:66300c77c6e9 121 }
tax 0:66300c77c6e9 122 #endif /* LWIP_BROADCAST_PING */
tax 0:66300c77c6e9 123 /* broadcast or multicast destination address not acceptd? */
tax 0:66300c77c6e9 124 if (!accepted) {
tax 0:66300c77c6e9 125 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: Not echoing to multicast or broadcast pings\n"));
tax 0:66300c77c6e9 126 ICMP_STATS_INC(icmp.err);
tax 0:66300c77c6e9 127 pbuf_free(p);
tax 0:66300c77c6e9 128 return;
tax 0:66300c77c6e9 129 }
tax 0:66300c77c6e9 130 }
tax 0:66300c77c6e9 131 #endif /* !LWIP_MULTICAST_PING || !LWIP_BROADCAST_PING */
tax 0:66300c77c6e9 132 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: ping\n"));
tax 0:66300c77c6e9 133 if (p->tot_len < sizeof(struct icmp_echo_hdr)) {
tax 0:66300c77c6e9 134 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: bad ICMP echo received\n"));
tax 0:66300c77c6e9 135 goto lenerr;
tax 0:66300c77c6e9 136 }
tax 0:66300c77c6e9 137 if (inet_chksum_pbuf(p) != 0) {
tax 0:66300c77c6e9 138 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: checksum failed for received ICMP echo\n"));
tax 0:66300c77c6e9 139 pbuf_free(p);
tax 0:66300c77c6e9 140 ICMP_STATS_INC(icmp.chkerr);
tax 0:66300c77c6e9 141 snmp_inc_icmpinerrors();
tax 0:66300c77c6e9 142 return;
tax 0:66300c77c6e9 143 }
tax 0:66300c77c6e9 144 #if LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN
tax 0:66300c77c6e9 145 if (pbuf_header(p, (PBUF_IP_HLEN + PBUF_LINK_HLEN))) {
tax 0:66300c77c6e9 146 /* p is not big enough to contain link headers
tax 0:66300c77c6e9 147 * allocate a new one and copy p into it
tax 0:66300c77c6e9 148 */
tax 0:66300c77c6e9 149 struct pbuf *r;
tax 0:66300c77c6e9 150 /* switch p->payload to ip header */
tax 0:66300c77c6e9 151 if (pbuf_header(p, hlen)) {
tax 0:66300c77c6e9 152 LWIP_ASSERT("icmp_input: moving p->payload to ip header failed\n", 0);
tax 0:66300c77c6e9 153 goto memerr;
tax 0:66300c77c6e9 154 }
tax 0:66300c77c6e9 155 /* allocate new packet buffer with space for link headers */
tax 0:66300c77c6e9 156 r = pbuf_alloc(PBUF_LINK, p->tot_len, PBUF_RAM);
tax 0:66300c77c6e9 157 if (r == NULL) {
tax 0:66300c77c6e9 158 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: allocating new pbuf failed\n"));
tax 0:66300c77c6e9 159 goto memerr;
tax 0:66300c77c6e9 160 }
tax 0:66300c77c6e9 161 LWIP_ASSERT("check that first pbuf can hold struct the ICMP header",
tax 0:66300c77c6e9 162 (r->len >= hlen + sizeof(struct icmp_echo_hdr)));
tax 0:66300c77c6e9 163 /* copy the whole packet including ip header */
tax 0:66300c77c6e9 164 if (pbuf_copy(r, p) != ERR_OK) {
tax 0:66300c77c6e9 165 LWIP_ASSERT("icmp_input: copying to new pbuf failed\n", 0);
tax 0:66300c77c6e9 166 goto memerr;
tax 0:66300c77c6e9 167 }
tax 0:66300c77c6e9 168 iphdr = (struct ip_hdr *)r->payload;
tax 0:66300c77c6e9 169 /* switch r->payload back to icmp header */
tax 0:66300c77c6e9 170 if (pbuf_header(r, -hlen)) {
tax 0:66300c77c6e9 171 LWIP_ASSERT("icmp_input: restoring original p->payload failed\n", 0);
tax 0:66300c77c6e9 172 goto memerr;
tax 0:66300c77c6e9 173 }
tax 0:66300c77c6e9 174 /* free the original p */
tax 0:66300c77c6e9 175 pbuf_free(p);
tax 0:66300c77c6e9 176 /* we now have an identical copy of p that has room for link headers */
tax 0:66300c77c6e9 177 p = r;
tax 0:66300c77c6e9 178 } else {
tax 0:66300c77c6e9 179 /* restore p->payload to point to icmp header */
tax 0:66300c77c6e9 180 if (pbuf_header(p, -(s16_t)(PBUF_IP_HLEN + PBUF_LINK_HLEN))) {
tax 0:66300c77c6e9 181 LWIP_ASSERT("icmp_input: restoring original p->payload failed\n", 0);
tax 0:66300c77c6e9 182 goto memerr;
tax 0:66300c77c6e9 183 }
tax 0:66300c77c6e9 184 }
tax 0:66300c77c6e9 185 #endif /* LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN */
tax 0:66300c77c6e9 186 /* At this point, all checks are OK. */
tax 0:66300c77c6e9 187 /* We generate an answer by switching the dest and src ip addresses,
tax 0:66300c77c6e9 188 * setting the icmp type to ECHO_RESPONSE and updating the checksum. */
tax 0:66300c77c6e9 189 iecho = (struct icmp_echo_hdr *)p->payload;
tax 0:66300c77c6e9 190 ip_addr_copy(iphdr->src, *ip_current_dest_addr());
tax 0:66300c77c6e9 191 ip_addr_copy(iphdr->dest, *ip_current_src_addr());
tax 0:66300c77c6e9 192 ICMPH_TYPE_SET(iecho, ICMP_ER);
tax 0:66300c77c6e9 193 /* adjust the checksum */
tax 0:66300c77c6e9 194 if (iecho->chksum >= PP_HTONS(0xffff - (ICMP_ECHO << 8))) {
tax 0:66300c77c6e9 195 iecho->chksum += PP_HTONS(ICMP_ECHO << 8) + 1;
tax 0:66300c77c6e9 196 } else {
tax 0:66300c77c6e9 197 iecho->chksum += PP_HTONS(ICMP_ECHO << 8);
tax 0:66300c77c6e9 198 }
tax 0:66300c77c6e9 199
tax 0:66300c77c6e9 200 /* Set the correct TTL and recalculate the header checksum. */
tax 0:66300c77c6e9 201 IPH_TTL_SET(iphdr, ICMP_TTL);
tax 0:66300c77c6e9 202 IPH_CHKSUM_SET(iphdr, 0);
tax 0:66300c77c6e9 203 #if CHECKSUM_GEN_IP
tax 0:66300c77c6e9 204 IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, IP_HLEN));
tax 0:66300c77c6e9 205 #endif /* CHECKSUM_GEN_IP */
tax 0:66300c77c6e9 206
tax 0:66300c77c6e9 207 ICMP_STATS_INC(icmp.xmit);
tax 0:66300c77c6e9 208 /* increase number of messages attempted to send */
tax 0:66300c77c6e9 209 snmp_inc_icmpoutmsgs();
tax 0:66300c77c6e9 210 /* increase number of echo replies attempted to send */
tax 0:66300c77c6e9 211 snmp_inc_icmpoutechoreps();
tax 0:66300c77c6e9 212
tax 0:66300c77c6e9 213 if(pbuf_header(p, hlen)) {
tax 0:66300c77c6e9 214 LWIP_ASSERT("Can't move over header in packet", 0);
tax 0:66300c77c6e9 215 } else {
tax 0:66300c77c6e9 216 err_t ret;
tax 0:66300c77c6e9 217 /* send an ICMP packet, src addr is the dest addr of the curren packet */
tax 0:66300c77c6e9 218 ret = ip_output_if(p, ip_current_dest_addr(), IP_HDRINCL,
tax 0:66300c77c6e9 219 ICMP_TTL, 0, IP_PROTO_ICMP, inp);
tax 0:66300c77c6e9 220 if (ret != ERR_OK) {
tax 0:66300c77c6e9 221 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: ip_output_if returned an error: %c.\n", ret));
tax 0:66300c77c6e9 222 }
tax 0:66300c77c6e9 223 }
tax 0:66300c77c6e9 224 break;
tax 0:66300c77c6e9 225 default:
tax 0:66300c77c6e9 226 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: ICMP type %"S16_F" code %"S16_F" not supported.\n",
tax 0:66300c77c6e9 227 (s16_t)type, (s16_t)code));
tax 0:66300c77c6e9 228 ICMP_STATS_INC(icmp.proterr);
tax 0:66300c77c6e9 229 ICMP_STATS_INC(icmp.drop);
tax 0:66300c77c6e9 230 }
tax 0:66300c77c6e9 231 pbuf_free(p);
tax 0:66300c77c6e9 232 return;
tax 0:66300c77c6e9 233 lenerr:
tax 0:66300c77c6e9 234 pbuf_free(p);
tax 0:66300c77c6e9 235 ICMP_STATS_INC(icmp.lenerr);
tax 0:66300c77c6e9 236 snmp_inc_icmpinerrors();
tax 0:66300c77c6e9 237 return;
tax 0:66300c77c6e9 238 #if LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN
tax 0:66300c77c6e9 239 memerr:
tax 0:66300c77c6e9 240 pbuf_free(p);
tax 0:66300c77c6e9 241 ICMP_STATS_INC(icmp.err);
tax 0:66300c77c6e9 242 snmp_inc_icmpinerrors();
tax 0:66300c77c6e9 243 return;
tax 0:66300c77c6e9 244 #endif /* LWIP_ICMP_ECHO_CHECK_INPUT_PBUF_LEN */
tax 0:66300c77c6e9 245 }
tax 0:66300c77c6e9 246
tax 0:66300c77c6e9 247 /**
tax 0:66300c77c6e9 248 * Send an icmp 'destination unreachable' packet, called from ip_input() if
tax 0:66300c77c6e9 249 * the transport layer protocol is unknown and from udp_input() if the local
tax 0:66300c77c6e9 250 * port is not bound.
tax 0:66300c77c6e9 251 *
tax 0:66300c77c6e9 252 * @param p the input packet for which the 'unreachable' should be sent,
tax 0:66300c77c6e9 253 * p->payload pointing to the IP header
tax 0:66300c77c6e9 254 * @param t type of the 'unreachable' packet
tax 0:66300c77c6e9 255 */
tax 0:66300c77c6e9 256 void
tax 0:66300c77c6e9 257 icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t)
tax 0:66300c77c6e9 258 {
tax 0:66300c77c6e9 259 icmp_send_response(p, ICMP_DUR, t);
tax 0:66300c77c6e9 260 }
tax 0:66300c77c6e9 261
tax 0:66300c77c6e9 262 #if IP_FORWARD || IP_REASSEMBLY
tax 0:66300c77c6e9 263 /**
tax 0:66300c77c6e9 264 * Send a 'time exceeded' packet, called from ip_forward() if TTL is 0.
tax 0:66300c77c6e9 265 *
tax 0:66300c77c6e9 266 * @param p the input packet for which the 'time exceeded' should be sent,
tax 0:66300c77c6e9 267 * p->payload pointing to the IP header
tax 0:66300c77c6e9 268 * @param t type of the 'time exceeded' packet
tax 0:66300c77c6e9 269 */
tax 0:66300c77c6e9 270 void
tax 0:66300c77c6e9 271 icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t)
tax 0:66300c77c6e9 272 {
tax 0:66300c77c6e9 273 icmp_send_response(p, ICMP_TE, t);
tax 0:66300c77c6e9 274 }
tax 0:66300c77c6e9 275
tax 0:66300c77c6e9 276 #endif /* IP_FORWARD || IP_REASSEMBLY */
tax 0:66300c77c6e9 277
tax 0:66300c77c6e9 278 /**
tax 0:66300c77c6e9 279 * Send an icmp packet in response to an incoming packet.
tax 0:66300c77c6e9 280 *
tax 0:66300c77c6e9 281 * @param p the input packet for which the 'unreachable' should be sent,
tax 0:66300c77c6e9 282 * p->payload pointing to the IP header
tax 0:66300c77c6e9 283 * @param type Type of the ICMP header
tax 0:66300c77c6e9 284 * @param code Code of the ICMP header
tax 0:66300c77c6e9 285 */
tax 0:66300c77c6e9 286 static void
tax 0:66300c77c6e9 287 icmp_send_response(struct pbuf *p, u8_t type, u8_t code)
tax 0:66300c77c6e9 288 {
tax 0:66300c77c6e9 289 struct pbuf *q;
tax 0:66300c77c6e9 290 struct ip_hdr *iphdr;
tax 0:66300c77c6e9 291 /* we can use the echo header here */
tax 0:66300c77c6e9 292 struct icmp_echo_hdr *icmphdr;
tax 0:66300c77c6e9 293 ip_addr_t iphdr_src;
tax 0:66300c77c6e9 294
tax 0:66300c77c6e9 295 /* ICMP header + IP header + 8 bytes of data */
tax 0:66300c77c6e9 296 q = pbuf_alloc(PBUF_IP, sizeof(struct icmp_echo_hdr) + IP_HLEN + ICMP_DEST_UNREACH_DATASIZE,
tax 0:66300c77c6e9 297 PBUF_RAM);
tax 0:66300c77c6e9 298 if (q == NULL) {
tax 0:66300c77c6e9 299 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_time_exceeded: failed to allocate pbuf for ICMP packet.\n"));
tax 0:66300c77c6e9 300 return;
tax 0:66300c77c6e9 301 }
tax 0:66300c77c6e9 302 LWIP_ASSERT("check that first pbuf can hold icmp message",
tax 0:66300c77c6e9 303 (q->len >= (sizeof(struct icmp_echo_hdr) + IP_HLEN + ICMP_DEST_UNREACH_DATASIZE)));
tax 0:66300c77c6e9 304
tax 0:66300c77c6e9 305 iphdr = (struct ip_hdr *)p->payload;
tax 0:66300c77c6e9 306 LWIP_DEBUGF(ICMP_DEBUG, ("icmp_time_exceeded from "));
tax 0:66300c77c6e9 307 ip_addr_debug_print(ICMP_DEBUG, &(iphdr->src));
tax 0:66300c77c6e9 308 LWIP_DEBUGF(ICMP_DEBUG, (" to "));
tax 0:66300c77c6e9 309 ip_addr_debug_print(ICMP_DEBUG, &(iphdr->dest));
tax 0:66300c77c6e9 310 LWIP_DEBUGF(ICMP_DEBUG, ("\n"));
tax 0:66300c77c6e9 311
tax 0:66300c77c6e9 312 icmphdr = (struct icmp_echo_hdr *)q->payload;
tax 0:66300c77c6e9 313 icmphdr->type = type;
tax 0:66300c77c6e9 314 icmphdr->code = code;
tax 0:66300c77c6e9 315 icmphdr->id = 0;
tax 0:66300c77c6e9 316 icmphdr->seqno = 0;
tax 0:66300c77c6e9 317
tax 0:66300c77c6e9 318 /* copy fields from original packet */
tax 0:66300c77c6e9 319 SMEMCPY((u8_t *)q->payload + sizeof(struct icmp_echo_hdr), (u8_t *)p->payload,
tax 0:66300c77c6e9 320 IP_HLEN + ICMP_DEST_UNREACH_DATASIZE);
tax 0:66300c77c6e9 321
tax 0:66300c77c6e9 322 /* calculate checksum */
tax 0:66300c77c6e9 323 icmphdr->chksum = 0;
tax 0:66300c77c6e9 324 icmphdr->chksum = inet_chksum(icmphdr, q->len);
tax 0:66300c77c6e9 325 ICMP_STATS_INC(icmp.xmit);
tax 0:66300c77c6e9 326 /* increase number of messages attempted to send */
tax 0:66300c77c6e9 327 snmp_inc_icmpoutmsgs();
tax 0:66300c77c6e9 328 /* increase number of destination unreachable messages attempted to send */
tax 0:66300c77c6e9 329 snmp_inc_icmpouttimeexcds();
tax 0:66300c77c6e9 330 ip_addr_copy(iphdr_src, iphdr->src);
tax 0:66300c77c6e9 331 ip_output(q, NULL, &iphdr_src, ICMP_TTL, 0, IP_PROTO_ICMP);
tax 0:66300c77c6e9 332 pbuf_free(q);
tax 0:66300c77c6e9 333 }
tax 0:66300c77c6e9 334
tax 0:66300c77c6e9 335 #endif /* LWIP_ICMP */