Back to index

glibc  2.9
ip_icmp.h
Go to the documentation of this file.
00001 /* Copyright (C) 1991, 92, 93, 95, 96, 97, 99 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #ifndef __NETINET_IP_ICMP_H
00020 #define __NETINET_IP_ICMP_H    1
00021 
00022 #include <sys/cdefs.h>
00023 #include <sys/types.h>
00024 
00025 __BEGIN_DECLS
00026 
00027 struct icmphdr
00028 {
00029   u_int8_t type;            /* message type */
00030   u_int8_t code;            /* type sub-code */
00031   u_int16_t checksum;
00032   union
00033   {
00034     struct
00035     {
00036       u_int16_t      id;
00037       u_int16_t      sequence;
00038     } echo;                 /* echo datagram */
00039     u_int32_t gateway;      /* gateway address */
00040     struct
00041     {
00042       u_int16_t      __unused;
00043       u_int16_t      mtu;
00044     } frag;                 /* path mtu discovery */
00045   } un;
00046 };
00047 
00048 #define ICMP_ECHOREPLY             0      /* Echo Reply               */
00049 #define ICMP_DEST_UNREACH   3      /* Destination Unreachable  */
00050 #define ICMP_SOURCE_QUENCH  4      /* Source Quench            */
00051 #define ICMP_REDIRECT              5      /* Redirect (change route)  */
00052 #define ICMP_ECHO           8      /* Echo Request                    */
00053 #define ICMP_TIME_EXCEEDED  11     /* Time Exceeded            */
00054 #define ICMP_PARAMETERPROB  12     /* Parameter Problem        */
00055 #define ICMP_TIMESTAMP             13     /* Timestamp Request        */
00056 #define ICMP_TIMESTAMPREPLY 14     /* Timestamp Reply          */
00057 #define ICMP_INFO_REQUEST   15     /* Information Request             */
00058 #define ICMP_INFO_REPLY            16     /* Information Reply        */
00059 #define ICMP_ADDRESS        17     /* Address Mask Request            */
00060 #define ICMP_ADDRESSREPLY   18     /* Address Mask Reply              */
00061 #define NR_ICMP_TYPES              18
00062 
00063 
00064 /* Codes for UNREACH. */
00065 #define ICMP_NET_UNREACH    0      /* Network Unreachable             */
00066 #define ICMP_HOST_UNREACH   1      /* Host Unreachable         */
00067 #define ICMP_PROT_UNREACH   2      /* Protocol Unreachable            */
00068 #define ICMP_PORT_UNREACH   3      /* Port Unreachable         */
00069 #define ICMP_FRAG_NEEDED    4      /* Fragmentation Needed/DF set     */
00070 #define ICMP_SR_FAILED             5      /* Source Route failed             */
00071 #define ICMP_NET_UNKNOWN    6
00072 #define ICMP_HOST_UNKNOWN   7
00073 #define ICMP_HOST_ISOLATED  8
00074 #define ICMP_NET_ANO        9
00075 #define ICMP_HOST_ANO              10
00076 #define ICMP_NET_UNR_TOS    11
00077 #define ICMP_HOST_UNR_TOS   12
00078 #define ICMP_PKT_FILTERED   13     /* Packet filtered */
00079 #define ICMP_PREC_VIOLATION 14     /* Precedence violation */
00080 #define ICMP_PREC_CUTOFF    15     /* Precedence cut off */
00081 #define NR_ICMP_UNREACH            15     /* instead of hardcoding immediate value */
00082 
00083 /* Codes for REDIRECT. */
00084 #define ICMP_REDIR_NET             0      /* Redirect Net                    */
00085 #define ICMP_REDIR_HOST            1      /* Redirect Host            */
00086 #define ICMP_REDIR_NETTOS   2      /* Redirect Net for TOS            */
00087 #define ICMP_REDIR_HOSTTOS  3      /* Redirect Host for TOS    */
00088 
00089 /* Codes for TIME_EXCEEDED. */
00090 #define ICMP_EXC_TTL        0      /* TTL count exceeded              */
00091 #define ICMP_EXC_FRAGTIME   1      /* Fragment Reass time exceeded    */
00092 
00093 
00094 #ifdef __USE_BSD
00095 /*
00096  * Copyright (c) 1982, 1986, 1993
00097  *     The Regents of the University of California.  All rights reserved.
00098  *
00099  * Redistribution and use in source and binary forms, with or without
00100  * modification, are permitted provided that the following conditions
00101  * are met:
00102  * 1. Redistributions of source code must retain the above copyright
00103  *    notice, this list of conditions and the following disclaimer.
00104  * 2. Redistributions in binary form must reproduce the above copyright
00105  *    notice, this list of conditions and the following disclaimer in the
00106  *    documentation and/or other materials provided with the distribution.
00107  * 4. Neither the name of the University nor the names of its contributors
00108  *    may be used to endorse or promote products derived from this software
00109  *    without specific prior written permission.
00110  *
00111  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00112  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00113  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00114  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00115  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00116  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00117  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00118  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00119  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00120  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00121  * SUCH DAMAGE.
00122  *
00123  *     @(#)ip_icmp.h 8.1 (Berkeley) 6/10/93
00124  */
00125 
00126 #include <netinet/in.h>
00127 #include <netinet/ip.h>
00128 
00129 /*
00130  * Internal of an ICMP Router Advertisement
00131  */
00132 struct icmp_ra_addr
00133 {
00134   u_int32_t ira_addr;
00135   u_int32_t ira_preference;
00136 };
00137 
00138 struct icmp
00139 {
00140   u_int8_t  icmp_type;      /* type of message, see below */
00141   u_int8_t  icmp_code;      /* type sub code */
00142   u_int16_t icmp_cksum;     /* ones complement checksum of struct */
00143   union
00144   {
00145     u_char ih_pptr;         /* ICMP_PARAMPROB */
00146     struct in_addr ih_gwaddr;      /* gateway address */
00147     struct ih_idseq         /* echo datagram */
00148     {
00149       u_int16_t icd_id;
00150       u_int16_t icd_seq;
00151     } ih_idseq;
00152     u_int32_t ih_void;
00153 
00154     /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
00155     struct ih_pmtu
00156     {
00157       u_int16_t ipm_void;
00158       u_int16_t ipm_nextmtu;
00159     } ih_pmtu;
00160 
00161     struct ih_rtradv
00162     {
00163       u_int8_t irt_num_addrs;
00164       u_int8_t irt_wpa;
00165       u_int16_t irt_lifetime;
00166     } ih_rtradv;
00167   } icmp_hun;
00168 #define       icmp_pptr     icmp_hun.ih_pptr
00169 #define       icmp_gwaddr   icmp_hun.ih_gwaddr
00170 #define       icmp_id              icmp_hun.ih_idseq.icd_id
00171 #define       icmp_seq      icmp_hun.ih_idseq.icd_seq
00172 #define       icmp_void     icmp_hun.ih_void
00173 #define       icmp_pmvoid   icmp_hun.ih_pmtu.ipm_void
00174 #define       icmp_nextmtu  icmp_hun.ih_pmtu.ipm_nextmtu
00175 #define       icmp_num_addrs       icmp_hun.ih_rtradv.irt_num_addrs
00176 #define       icmp_wpa      icmp_hun.ih_rtradv.irt_wpa
00177 #define       icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime
00178   union
00179   {
00180     struct
00181     {
00182       u_int32_t its_otime;
00183       u_int32_t its_rtime;
00184       u_int32_t its_ttime;
00185     } id_ts;
00186     struct
00187     {
00188       struct ip idi_ip;
00189       /* options and then 64 bits of data */
00190     } id_ip;
00191     struct icmp_ra_addr id_radv;
00192     u_int32_t   id_mask;
00193     u_int8_t    id_data[1];
00194   } icmp_dun;
00195 #define       icmp_otime    icmp_dun.id_ts.its_otime
00196 #define       icmp_rtime    icmp_dun.id_ts.its_rtime
00197 #define       icmp_ttime    icmp_dun.id_ts.its_ttime
00198 #define       icmp_ip              icmp_dun.id_ip.idi_ip
00199 #define       icmp_radv     icmp_dun.id_radv
00200 #define       icmp_mask     icmp_dun.id_mask
00201 #define       icmp_data     icmp_dun.id_data
00202 };
00203 
00204 /*
00205  * Lower bounds on packet lengths for various types.
00206  * For the error advice packets must first insure that the
00207  * packet is large enough to contain the returned ip header.
00208  * Only then can we do the check to see if 64 bits of packet
00209  * data have been returned, since we need to check the returned
00210  * ip header length.
00211  */
00212 #define       ICMP_MINLEN   8                           /* abs minimum */
00213 #define       ICMP_TSLEN    (8 + 3 * sizeof (n_time))   /* timestamp */
00214 #define       ICMP_MASKLEN  12                          /* address mask */
00215 #define       ICMP_ADVLENMIN       (8 + sizeof (struct ip) + 8)       /* min */
00216 #ifndef _IP_VHL
00217 #define       ICMP_ADVLEN(p)       (8 + ((p)->icmp_ip.ip_hl << 2) + 8)
00218        /* N.B.: must separately check that ip_hl >= 5 */
00219 #else
00220 #define       ICMP_ADVLEN(p)       (8 + (IP_VHL_HL((p)->icmp_ip.ip_vhl) << 2) + 8)
00221        /* N.B.: must separately check that header length >= 5 */
00222 #endif
00223 
00224 /* Definition of type and code fields. */
00225 /* defined above: ICMP_ECHOREPLY, ICMP_REDIRECT, ICMP_ECHO */
00226 #define       ICMP_UNREACH         3             /* dest unreachable, codes: */
00227 #define       ICMP_SOURCEQUENCH    4             /* packet lost, slow down */
00228 #define       ICMP_ROUTERADVERT    9             /* router advertisement */
00229 #define       ICMP_ROUTERSOLICIT   10            /* router solicitation */
00230 #define       ICMP_TIMXCEED        11            /* time exceeded, code: */
00231 #define       ICMP_PARAMPROB              12            /* ip header bad */
00232 #define       ICMP_TSTAMP          13            /* timestamp request */
00233 #define       ICMP_TSTAMPREPLY     14            /* timestamp reply */
00234 #define       ICMP_IREQ            15            /* information request */
00235 #define       ICMP_IREQREPLY              16            /* information reply */
00236 #define       ICMP_MASKREQ         17            /* address mask request */
00237 #define       ICMP_MASKREPLY              18            /* address mask reply */
00238 
00239 #define       ICMP_MAXTYPE         18
00240 
00241 /* UNREACH codes */
00242 #define       ICMP_UNREACH_NET             0     /* bad net */
00243 #define       ICMP_UNREACH_HOST            1     /* bad host */
00244 #define       ICMP_UNREACH_PROTOCOL               2     /* bad protocol */
00245 #define       ICMP_UNREACH_PORT            3     /* bad port */
00246 #define       ICMP_UNREACH_NEEDFRAG               4     /* IP_DF caused drop */
00247 #define       ICMP_UNREACH_SRCFAIL         5     /* src route failed */
00248 #define       ICMP_UNREACH_NET_UNKNOWN        6  /* unknown net */
00249 #define       ICMP_UNREACH_HOST_UNKNOWN       7  /* unknown host */
00250 #define       ICMP_UNREACH_ISOLATED               8     /* src host isolated */
00251 #define       ICMP_UNREACH_NET_PROHIB             9     /* net denied */
00252 #define       ICMP_UNREACH_HOST_PROHIB        10 /* host denied */
00253 #define       ICMP_UNREACH_TOSNET          11    /* bad tos for net */
00254 #define       ICMP_UNREACH_TOSHOST         12    /* bad tos for host */
00255 #define       ICMP_UNREACH_FILTER_PROHIB      13 /* admin prohib */
00256 #define       ICMP_UNREACH_HOST_PRECEDENCE    14 /* host prec vio. */
00257 #define       ICMP_UNREACH_PRECEDENCE_CUTOFF  15 /* prec cutoff */
00258 
00259 /* REDIRECT codes */
00260 #define       ICMP_REDIRECT_NET    0             /* for network */
00261 #define       ICMP_REDIRECT_HOST   1             /* for host */
00262 #define       ICMP_REDIRECT_TOSNET 2             /* for tos and net */
00263 #define       ICMP_REDIRECT_TOSHOST       3             /* for tos and host */
00264 
00265 /* TIMEXCEED codes */
00266 #define       ICMP_TIMXCEED_INTRANS       0             /* ttl==0 in transit */
00267 #define       ICMP_TIMXCEED_REASS  1             /* ttl==0 in reass */
00268 
00269 /* PARAMPROB code */
00270 #define       ICMP_PARAMPROB_OPTABSENT 1         /* req. opt. absent */
00271 
00272 #define       ICMP_INFOTYPE(type) \
00273        ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \
00274        (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \
00275        (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \
00276        (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \
00277        (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
00278 
00279 #endif /* __USE_BSD */
00280 
00281 __END_DECLS
00282 
00283 #endif /* netinet/ip_icmp.h */