Simon Cooksey / mbed-os
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers icmp.h Source File

icmp.h

Go to the documentation of this file.
00001 /**
00002  * @file
00003  * ICMP API
00004  */
00005 
00006 /*
00007  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
00008  * All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without modification,
00011  * are permitted provided that the following conditions are met:
00012  *
00013  * 1. Redistributions of source code must retain the above copyright notice,
00014  *    this list of conditions and the following disclaimer.
00015  * 2. Redistributions in binary form must reproduce the above copyright notice,
00016  *    this list of conditions and the following disclaimer in the documentation
00017  *    and/or other materials provided with the distribution.
00018  * 3. The name of the author may not be used to endorse or promote products
00019  *    derived from this software without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
00022  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00023  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
00024  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00025  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
00026  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
00029  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
00030  * OF SUCH DAMAGE.
00031  *
00032  * This file is part of the lwIP TCP/IP stack.
00033  *
00034  * Author: Adam Dunkels <adam@sics.se>
00035  *
00036  */
00037 #ifndef LWIP_HDR_ICMP_H
00038 #define LWIP_HDR_ICMP_H
00039 
00040 #include "lwip/opt.h"
00041 #include "lwip/pbuf.h"
00042 #include "lwip/ip_addr.h"
00043 #include "lwip/netif.h"
00044 
00045 #if LWIP_IPV6 && LWIP_ICMP6
00046 #include "lwip/icmp6.h"
00047 #endif
00048 
00049 #ifdef __cplusplus
00050 extern "C" {
00051 #endif
00052 
00053 #define ICMP_ER   0    /* echo reply */
00054 #define ICMP_DUR  3    /* destination unreachable */
00055 #define ICMP_SQ   4    /* source quench */
00056 #define ICMP_RD   5    /* redirect */
00057 #define ICMP_ECHO 8    /* echo */
00058 #define ICMP_TE  11    /* time exceeded */
00059 #define ICMP_PP  12    /* parameter problem */
00060 #define ICMP_TS  13    /* timestamp */
00061 #define ICMP_TSR 14    /* timestamp reply */
00062 #define ICMP_IRQ 15    /* information request */
00063 #define ICMP_IR  16    /* information reply */
00064 #define ICMP_AM  17    /* address mask request */
00065 #define ICMP_AMR 18    /* address mask reply */
00066 
00067 /** ICMP destination unreachable codes */
00068 enum icmp_dur_type {
00069   /** net unreachable */
00070   ICMP_DUR_NET   = 0,
00071   /** host unreachable */
00072   ICMP_DUR_HOST  = 1,
00073   /** protocol unreachable */
00074   ICMP_DUR_PROTO = 2,
00075   /** port unreachable */
00076   ICMP_DUR_PORT  = 3,
00077   /** fragmentation needed and DF set */
00078   ICMP_DUR_FRAG  = 4,
00079   /** source route failed */
00080   ICMP_DUR_SR    = 5
00081 };
00082 
00083 /** ICMP time exceeded codes */
00084 enum icmp_te_type {
00085   /* time to live exceeded in transit */
00086   ICMP_TE_TTL  = 0,
00087   /** fragment reassembly time exceeded */
00088   ICMP_TE_FRAG = 1
00089 };
00090 
00091 #ifdef PACK_STRUCT_USE_INCLUDES
00092 #  include "arch/bpstruct.h"
00093 #endif
00094 /** This is the standard ICMP header only that the u32_t data
00095  *  is split to two u16_t like ICMP echo needs it.
00096  *  This header is also used for other ICMP types that do not
00097  *  use the data part.
00098  */
00099 PACK_STRUCT_BEGIN
00100 struct icmp_echo_hdr {
00101   PACK_STRUCT_FLD_8(u8_t type);
00102   PACK_STRUCT_FLD_8(u8_t code);
00103   PACK_STRUCT_FIELD(u16_t chksum);
00104   PACK_STRUCT_FIELD(u16_t id);
00105   PACK_STRUCT_FIELD(u16_t seqno);
00106 } PACK_STRUCT_STRUCT;
00107 PACK_STRUCT_END
00108 #ifdef PACK_STRUCT_USE_INCLUDES
00109 #  include "arch/epstruct.h"
00110 #endif
00111 
00112 #define ICMPH_TYPE(hdr) ((hdr)->type)
00113 #define ICMPH_CODE(hdr) ((hdr)->code)
00114 
00115 /** Combines type and code to an u16_t */
00116 #define ICMPH_TYPE_SET(hdr, t) ((hdr)->type = (t))
00117 #define ICMPH_CODE_SET(hdr, c) ((hdr)->code = (c))
00118 
00119 
00120 #if LWIP_IPV4 && LWIP_ICMP /* don't build if not configured for use in lwipopts.h */
00121 
00122 void icmp_input(struct pbuf *p, struct netif *inp);
00123 void icmp_dest_unreach(struct pbuf *p, enum icmp_dur_type t);
00124 void icmp_time_exceeded(struct pbuf *p, enum icmp_te_type t);
00125 
00126 #endif /* LWIP_IPV4 && LWIP_ICMP */
00127 
00128 #if LWIP_IPV4 && LWIP_IPV6
00129 #if LWIP_ICMP && LWIP_ICMP6
00130 #define icmp_port_unreach(isipv6, pbuf) ((isipv6) ? \
00131                                          icmp6_dest_unreach(pbuf, ICMP6_DUR_PORT) : \
00132                                          icmp_dest_unreach(pbuf, ICMP_DUR_PORT))
00133 #elif LWIP_ICMP
00134 #define icmp_port_unreach(isipv6, pbuf) do{ if(!(isipv6)) { icmp_dest_unreach(pbuf, ICMP_DUR_PORT);}}while(0)
00135 #elif LWIP_ICMP6
00136 #define icmp_port_unreach(isipv6, pbuf) do{ if(isipv6) { icmp6_dest_unreach(pbuf, ICMP6_DUR_PORT);}}while(0)
00137 #else
00138 #define icmp_port_unreach(isipv6, pbuf)
00139 #endif
00140 #elif LWIP_IPV6 && LWIP_ICMP6
00141 #define icmp_port_unreach(isipv6, pbuf) icmp6_dest_unreach(pbuf, ICMP6_DUR_PORT)
00142 #elif LWIP_IPV4 && LWIP_ICMP
00143 #define icmp_port_unreach(isipv6, pbuf) icmp_dest_unreach(pbuf, ICMP_DUR_PORT)
00144 #else /* (LWIP_IPV6 && LWIP_ICMP6) || (LWIP_IPV4 && LWIP_ICMP) */
00145 #define icmp_port_unreach(isipv6, pbuf)
00146 #endif /* (LWIP_IPV6 && LWIP_ICMP6) || (LWIP_IPV4 && LWIP_ICMP) LWIP_IPV4*/
00147 
00148 #ifdef __cplusplus
00149 }
00150 #endif
00151 
00152 #endif /* LWIP_HDR_ICMP_H */