/[lwip]/lwip/src/core/ipv6/icmp6.c
ViewVC logotype

Diff of /lwip/src/core/ipv6/icmp6.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.10 by kieranm, Tue Jun 10 10:45:29 2003 UTC revision 1.11 by likewise, Wed Jun 11 22:34:51 2003 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2001-2003 Swedish Institute of Computer Science.   * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
3   * All rights reserved.   * All rights reserved.
4   *   *
5   * Redistribution and use in source and binary forms, with or without modification,   * Redistribution and use in source and binary forms, with or without modification,
6   * are permitted provided that the following conditions are met:   * are permitted provided that the following conditions are met:
7   *   *
8   * 1. Redistributions of source code must retain the above copyright notice,   * 1. Redistributions of source code must retain the above copyright notice,
# Line 11  Line 11 
11   *    this list of conditions and the following disclaimer in the documentation   *    this list of conditions and the following disclaimer in the documentation
12   *    and/or other materials provided with the distribution.   *    and/or other materials provided with the distribution.
13   * 3. The name of the author may not be used to endorse or promote products   * 3. The name of the author may not be used to endorse or promote products
14   *    derived from this software without specific prior written permission.   *    derived from this software without specific prior written permission.
15   *   *
16   * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED   * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18   * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT   * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
19   * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,   * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
21   * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS   * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY   * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
25   * OF SUCH DAMAGE.   * OF SUCH DAMAGE.
26   *   *
27   * This file is part of the lwIP TCP/IP stack.   * This file is part of the lwIP TCP/IP stack.
28   *   *
29   * Author: Adam Dunkels <adam@sics.se>   * Author: Adam Dunkels <adam@sics.se>
30   *   *
31   */   */
# Line 50  icmp_input(struct pbuf *p, struct netif Line 50  icmp_input(struct pbuf *p, struct netif
50    struct icmp_echo_hdr *iecho;    struct icmp_echo_hdr *iecho;
51    struct ip_hdr *iphdr;    struct ip_hdr *iphdr;
52    struct ip_addr tmpaddr;    struct ip_addr tmpaddr;
53    
54  #ifdef ICMP_STATS  #ifdef ICMP_STATS
55    ++lwip_stats.icmp.recv;    ++lwip_stats.icmp.recv;
56  #endif /* ICMP_STATS */  #endif /* ICMP_STATS */
# Line 71  icmp_input(struct pbuf *p, struct netif Line 71  icmp_input(struct pbuf *p, struct netif
71        ++lwip_stats.icmp.lenerr;        ++lwip_stats.icmp.lenerr;
72  #endif /* ICMP_STATS */  #endif /* ICMP_STATS */
73    
74        return;              return;
75      }      }
76      iecho = p->payload;      iecho = p->payload;
77      iphdr = (struct ip_hdr *)((char *)p->payload - IP_HLEN);      iphdr = (struct ip_hdr *)((char *)p->payload - IP_HLEN);
# Line 99  icmp_input(struct pbuf *p, struct netif Line 99  icmp_input(struct pbuf *p, struct netif
99      ++lwip_stats.icmp.xmit;      ++lwip_stats.icmp.xmit;
100  #endif /* ICMP_STATS */  #endif /* ICMP_STATS */
101    
102      /*    LWIP_DEBUGF("icmp: p->len %d p->tot_len %d\n", p->len, p->tot_len);*/      /*    LWIP_DEBUGF("icmp: p->len %u p->tot_len %u\n", p->len, p->tot_len);*/
103      ip_output_if (p, &(iphdr->src), IP_HDRINCL,      ip_output_if (p, &(iphdr->src), IP_HDRINCL,
104       iphdr->hoplim, IP_PROTO_ICMP, inp);       iphdr->hoplim, IP_PROTO_ICMP, inp);
105      break;      break;
106    default:    default:
107      LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: ICMP type %d not supported.\n", (int)type));      LWIP_DEBUGF(ICMP_DEBUG, ("icmp_input: ICMP type %d not supported.\n", (int)type));
108  #ifdef ICMP_STATS  #ifdef ICMP_STATS
# Line 120  icmp_dest_unreach(struct pbuf *p, enum i Line 120  icmp_dest_unreach(struct pbuf *p, enum i
120    struct pbuf *q;    struct pbuf *q;
121    struct ip_hdr *iphdr;    struct ip_hdr *iphdr;
122    struct icmp_dur_hdr *idur;    struct icmp_dur_hdr *idur;
123      
124    q = pbuf_alloc(PBUF_IP, 8 + IP_HLEN + 8, PBUF_RAM);    q = pbuf_alloc(PBUF_IP, 8 + IP_HLEN + 8, PBUF_RAM);
125    /* ICMP header + IP header + 8 bytes of data */    /* ICMP header + IP header + 8 bytes of data */
126    
127    iphdr = p->payload;    iphdr = p->payload;
128      
129    idur = q->payload;    idur = q->payload;
130    idur->type = (char)ICMP6_DUR;    idur->type = (char)ICMP6_DUR;
131    idur->icode = (char)t;    idur->icode = (char)t;
132    
133    memcpy((char *)q->payload + 8, p->payload, IP_HLEN + 8);    memcpy((char *)q->payload + 8, p->payload, IP_HLEN + 8);
134      
135    /* calculate checksum */    /* calculate checksum */
136    idur->chksum = 0;    idur->chksum = 0;
137    idur->chksum = inet_chksum(idur, q->len);    idur->chksum = inet_chksum(idur, q->len);
# Line 152  icmp_time_exceeded(struct pbuf *p, enum Line 152  icmp_time_exceeded(struct pbuf *p, enum
152    struct icmp_te_hdr *tehdr;    struct icmp_te_hdr *tehdr;
153    
154    LWIP_DEBUGF(ICMP_DEBUG, ("icmp_time_exceeded\n"));    LWIP_DEBUGF(ICMP_DEBUG, ("icmp_time_exceeded\n"));
155      
156    q = pbuf_alloc(PBUF_IP, 8 + IP_HLEN + 8, PBUF_RAM);    q = pbuf_alloc(PBUF_IP, 8 + IP_HLEN + 8, PBUF_RAM);
157    
158    iphdr = p->payload;    iphdr = p->payload;
159      
160    tehdr = q->payload;    tehdr = q->payload;
161    tehdr->type = (char)ICMP6_TE;    tehdr->type = (char)ICMP6_TE;
162    tehdr->icode = (char)t;    tehdr->icode = (char)t;
163    
164    /* copy fields from original packet */    /* copy fields from original packet */
165    memcpy((char *)q->payload + 8, (char *)p->payload, IP_HLEN + 8);    memcpy((char *)q->payload + 8, (char *)p->payload, IP_HLEN + 8);
166      
167    /* calculate checksum */    /* calculate checksum */
168    tehdr->chksum = 0;    tehdr->chksum = 0;
169    tehdr->chksum = inet_chksum(tehdr, q->len);    tehdr->chksum = inet_chksum(tehdr, q->len);
170  #ifdef ICMP_STATS  #ifdef ICMP_STATS
171    ++lwip_stats.icmp.xmit;    ++lwip_stats.icmp.xmit;
172  #endif /* ICMP_STATS */  #endif /* ICMP_STATS */
173    ip_output(q, NULL,    ip_output(q, NULL,
174        (struct ip_addr *)&(iphdr->src), ICMP_TTL, IP_PROTO_ICMP);        (struct ip_addr *)&(iphdr->src), ICMP_TTL, IP_PROTO_ICMP);
175    pbuf_free(q);    pbuf_free(q);
176  }  }

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26