home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue6 / SDL.ZIP / !gcc / include / unixlib / netinet / h / ip_icmp < prev    next >
Encoding:
Text File  |  2006-09-17  |  10.4 KB  |  300 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /usr/local/cvsroot/gccsdk/unixlib/source/clib/netinet/ip_icmp.h,v $
  4.  * $Date: 2002/12/22 18:22:28 $
  5.  * $Revision: 1.4 $
  6.  * $State: Exp $
  7.  * $Author: admin $
  8.  *
  9.  ***************************************************************************/
  10.  
  11. /*
  12.  * File taken from glibc 2.2.5.
  13.  * Following changes were made:
  14.  *  <none>
  15.  */
  16.  
  17. /* Copyright (C) 1991, 92, 93, 95, 96, 97, 99 Free Software Foundation, Inc.
  18.    This file is part of the GNU C Library.
  19.  
  20.    The GNU C Library is free software; you can redistribute it and/or
  21.    modify it under the terms of the GNU Lesser General Public
  22.    License as published by the Free Software Foundation; either
  23.    version 2.1 of the License, or (at your option) any later version.
  24.  
  25.    The GNU C Library is distributed in the hope that it will be useful,
  26.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  27.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  28.    Lesser General Public License for more details.
  29.  
  30.    You should have received a copy of the GNU Lesser General Public
  31.    License along with the GNU C Library; if not, write to the Free
  32.    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  33.    02111-1307 USA.  */
  34.  
  35. #ifndef __NETINET_IP_ICMP_H
  36. #define __NETINET_IP_ICMP_H    1
  37.  
  38. #include <features.h>
  39. #include <sys/types.h>
  40.  
  41. __BEGIN_DECLS
  42.  
  43. struct icmphdr
  44. {
  45.   u_int8_t type;        /* message type */
  46.   u_int8_t code;        /* type sub-code */
  47.   u_int16_t checksum;
  48.   union
  49.   {
  50.     struct
  51.     {
  52.       u_int16_t    id;
  53.       u_int16_t    sequence;
  54.     } echo;            /* echo datagram */
  55.     u_int32_t    gateway;    /* gateway address */
  56.     struct
  57.     {
  58.       u_int16_t    __unused;
  59.       u_int16_t    mtu;
  60.     } frag;            /* path mtu discovery */
  61.   } un;
  62. };
  63.  
  64. #define ICMP_ECHOREPLY        0    /* Echo Reply            */
  65. #define ICMP_DEST_UNREACH    3    /* Destination Unreachable    */
  66. #define ICMP_SOURCE_QUENCH    4    /* Source Quench        */
  67. #define ICMP_REDIRECT        5    /* Redirect (change route)    */
  68. #define ICMP_ECHO        8    /* Echo Request            */
  69. #define ICMP_TIME_EXCEEDED    11    /* Time Exceeded        */
  70. #define ICMP_PARAMETERPROB    12    /* Parameter Problem        */
  71. #define ICMP_TIMESTAMP        13    /* Timestamp Request        */
  72. #define ICMP_TIMESTAMPREPLY    14    /* Timestamp Reply        */
  73. #define ICMP_INFO_REQUEST    15    /* Information Request        */
  74. #define ICMP_INFO_REPLY        16    /* Information Reply        */
  75. #define ICMP_ADDRESS        17    /* Address Mask Request        */
  76. #define ICMP_ADDRESSREPLY    18    /* Address Mask Reply        */
  77. #define NR_ICMP_TYPES        18
  78.  
  79.  
  80. /* Codes for UNREACH. */
  81. #define ICMP_NET_UNREACH    0    /* Network Unreachable        */
  82. #define ICMP_HOST_UNREACH    1    /* Host Unreachable        */
  83. #define ICMP_PROT_UNREACH    2    /* Protocol Unreachable        */
  84. #define ICMP_PORT_UNREACH    3    /* Port Unreachable        */
  85. #define ICMP_FRAG_NEEDED    4    /* Fragmentation Needed/DF set    */
  86. #define ICMP_SR_FAILED        5    /* Source Route failed        */
  87. #define ICMP_NET_UNKNOWN    6
  88. #define ICMP_HOST_UNKNOWN    7
  89. #define ICMP_HOST_ISOLATED    8
  90. #define ICMP_NET_ANO        9
  91. #define ICMP_HOST_ANO        10
  92. #define ICMP_NET_UNR_TOS    11
  93. #define ICMP_HOST_UNR_TOS    12
  94. #define ICMP_PKT_FILTERED    13    /* Packet filtered */
  95. #define ICMP_PREC_VIOLATION    14    /* Precedence violation */
  96. #define ICMP_PREC_CUTOFF    15    /* Precedence cut off */
  97. #define NR_ICMP_UNREACH        15    /* instead of hardcoding immediate value */
  98.  
  99. /* Codes for REDIRECT. */
  100. #define ICMP_REDIR_NET        0    /* Redirect Net            */
  101. #define ICMP_REDIR_HOST        1    /* Redirect Host        */
  102. #define ICMP_REDIR_NETTOS    2    /* Redirect Net for TOS        */
  103. #define ICMP_REDIR_HOSTTOS    3    /* Redirect Host for TOS    */
  104.  
  105. /* Codes for TIME_EXCEEDED. */
  106. #define ICMP_EXC_TTL        0    /* TTL count exceeded        */
  107. #define ICMP_EXC_FRAGTIME    1    /* Fragment Reass time exceeded    */
  108.  
  109.  
  110. #ifdef __USE_BSD
  111. /*
  112.  * Copyright (c) 1982, 1986, 1993
  113.  *    The Regents of the University of California.  All rights reserved.
  114.  *
  115.  * Redistribution and use in source and binary forms, with or without
  116.  * modification, are permitted provided that the following conditions
  117.  * are met:
  118.  * 1. Redistributions of source code must retain the above copyright
  119.  *    notice, this list of conditions and the following disclaimer.
  120.  * 2. Redistributions in binary form must reproduce the above copyright
  121.  *    notice, this list of conditions and the following disclaimer in the
  122.  *    documentation and/or other materials provided with the distribution.
  123.  * 4. Neither the name of the University nor the names of its contributors
  124.  *    may be used to endorse or promote products derived from this software
  125.  *    without specific prior written permission.
  126.  *
  127.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  128.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  129.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  130.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  131.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  132.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  133.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  134.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  135.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  136.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  137.  * SUCH DAMAGE.
  138.  *
  139.  *    @(#)ip_icmp.h    8.1 (Berkeley) 6/10/93
  140.  */
  141.  
  142. #include <netinet/in.h>
  143. #include <netinet/ip.h>
  144.  
  145. /*
  146.  * Internal of an ICMP Router Advertisement
  147.  */
  148. struct icmp_ra_addr
  149. {
  150.   u_int32_t ira_addr;
  151.   u_int32_t ira_preference;
  152. };
  153.  
  154. struct icmp
  155. {
  156.   u_int8_t  icmp_type;    /* type of message, see below */
  157.   u_int8_t  icmp_code;    /* type sub code */
  158.   u_int16_t icmp_cksum;    /* ones complement checksum of struct */
  159.   union
  160.   {
  161.     u_char ih_pptr;        /* ICMP_PARAMPROB */
  162.     struct in_addr ih_gwaddr;    /* gateway address */
  163.     struct ih_idseq        /* echo datagram */
  164.     {
  165.       u_int16_t icd_id;
  166.       u_int16_t icd_seq;
  167.     } ih_idseq;
  168.     u_int32_t ih_void;
  169.  
  170.     /* ICMP_UNREACH_NEEDFRAG -- Path MTU Discovery (RFC1191) */
  171.     struct ih_pmtu
  172.     {
  173.       u_int16_t ipm_void;
  174.       u_int16_t ipm_nextmtu;
  175.     } ih_pmtu;
  176.  
  177.     struct ih_rtradv
  178.     {
  179.       u_int8_t irt_num_addrs;
  180.       u_int8_t irt_wpa;
  181.       u_int16_t irt_lifetime;
  182.     } ih_rtradv;
  183.   } icmp_hun;
  184. #define    icmp_pptr    icmp_hun.ih_pptr
  185. #define    icmp_gwaddr    icmp_hun.ih_gwaddr
  186. #define    icmp_id        icmp_hun.ih_idseq.icd_id
  187. #define    icmp_seq    icmp_hun.ih_idseq.icd_seq
  188. #define    icmp_void    icmp_hun.ih_void
  189. #define    icmp_pmvoid    icmp_hun.ih_pmtu.ipm_void
  190. #define    icmp_nextmtu    icmp_hun.ih_pmtu.ipm_nextmtu
  191. #define    icmp_num_addrs    icmp_hun.ih_rtradv.irt_num_addrs
  192. #define    icmp_wpa    icmp_hun.ih_rtradv.irt_wpa
  193. #define    icmp_lifetime    icmp_hun.ih_rtradv.irt_lifetime
  194.   union
  195.   {
  196.     struct
  197.     {
  198.       u_int32_t its_otime;
  199.       u_int32_t its_rtime;
  200.       u_int32_t its_ttime;
  201.     } id_ts;
  202.     struct
  203.     {
  204.       struct ip idi_ip;
  205.       /* options and then 64 bits of data */
  206.     } id_ip;
  207.     struct icmp_ra_addr id_radv;
  208.     u_int32_t   id_mask;
  209.     u_int8_t    id_data[1];
  210.   } icmp_dun;
  211. #define    icmp_otime    icmp_dun.id_ts.its_otime
  212. #define    icmp_rtime    icmp_dun.id_ts.its_rtime
  213. #define    icmp_ttime    icmp_dun.id_ts.its_ttime
  214. #define    icmp_ip        icmp_dun.id_ip.idi_ip
  215. #define    icmp_radv    icmp_dun.id_radv
  216. #define    icmp_mask    icmp_dun.id_mask
  217. #define    icmp_data    icmp_dun.id_data
  218. };
  219.  
  220. /*
  221.  * Lower bounds on packet lengths for various types.
  222.  * For the error advice packets must first insure that the
  223.  * packet is large enough to contain the returned ip header.
  224.  * Only then can we do the check to see if 64 bits of packet
  225.  * data have been returned, since we need to check the returned
  226.  * ip header length.
  227.  */
  228. #define    ICMP_MINLEN    8                /* abs minimum */
  229. #define    ICMP_TSLEN    (8 + 3 * sizeof (n_time))    /* timestamp */
  230. #define    ICMP_MASKLEN    12                /* address mask */
  231. #define    ICMP_ADVLENMIN    (8 + sizeof (struct ip) + 8)    /* min */
  232. #ifndef _IP_VHL
  233. #define    ICMP_ADVLEN(p)    (8 + ((p)->icmp_ip.ip_hl << 2) + 8)
  234.     /* N.B.: must separately check that ip_hl >= 5 */
  235. #else
  236. #define    ICMP_ADVLEN(p)    (8 + (IP_VHL_HL((p)->icmp_ip.ip_vhl) << 2) + 8)
  237.     /* N.B.: must separately check that header length >= 5 */
  238. #endif
  239.  
  240. /* Definition of type and code fields. */
  241. /* defined above: ICMP_ECHOREPLY, ICMP_REDIRECT, ICMP_ECHO */
  242. #define    ICMP_UNREACH        3        /* dest unreachable, codes: */
  243. #define    ICMP_SOURCEQUENCH    4        /* packet lost, slow down */
  244. #define    ICMP_ROUTERADVERT    9        /* router advertisement */
  245. #define    ICMP_ROUTERSOLICIT    10        /* router solicitation */
  246. #define    ICMP_TIMXCEED        11        /* time exceeded, code: */
  247. #define    ICMP_PARAMPROB        12        /* ip header bad */
  248. #define    ICMP_TSTAMP        13        /* timestamp request */
  249. #define    ICMP_TSTAMPREPLY    14        /* timestamp reply */
  250. #define    ICMP_IREQ        15        /* information request */
  251. #define    ICMP_IREQREPLY        16        /* information reply */
  252. #define    ICMP_MASKREQ        17        /* address mask request */
  253. #define    ICMP_MASKREPLY        18        /* address mask reply */
  254.  
  255. #define    ICMP_MAXTYPE        18
  256.  
  257. /* UNREACH codes */
  258. #define    ICMP_UNREACH_NET            0    /* bad net */
  259. #define    ICMP_UNREACH_HOST            1    /* bad host */
  260. #define    ICMP_UNREACH_PROTOCOL            2    /* bad protocol */
  261. #define    ICMP_UNREACH_PORT            3    /* bad port */
  262. #define    ICMP_UNREACH_NEEDFRAG            4    /* IP_DF caused drop */
  263. #define    ICMP_UNREACH_SRCFAIL            5    /* src route failed */
  264. #define    ICMP_UNREACH_NET_UNKNOWN        6    /* unknown net */
  265. #define    ICMP_UNREACH_HOST_UNKNOWN       7    /* unknown host */
  266. #define    ICMP_UNREACH_ISOLATED            8    /* src host isolated */
  267. #define    ICMP_UNREACH_NET_PROHIB            9    /* net denied */
  268. #define    ICMP_UNREACH_HOST_PROHIB        10    /* host denied */
  269. #define    ICMP_UNREACH_TOSNET            11    /* bad tos for net */
  270. #define    ICMP_UNREACH_TOSHOST            12    /* bad tos for host */
  271. #define    ICMP_UNREACH_FILTER_PROHIB      13    /* admin prohib */
  272. #define    ICMP_UNREACH_HOST_PRECEDENCE    14    /* host prec vio. */
  273. #define    ICMP_UNREACH_PRECEDENCE_CUTOFF  15    /* prec cutoff */
  274.  
  275. /* REDIRECT codes */
  276. #define    ICMP_REDIRECT_NET    0        /* for network */
  277. #define    ICMP_REDIRECT_HOST    1        /* for host */
  278. #define    ICMP_REDIRECT_TOSNET    2        /* for tos and net */
  279. #define    ICMP_REDIRECT_TOSHOST    3        /* for tos and host */
  280.  
  281. /* TIMEXCEED codes */
  282. #define    ICMP_TIMXCEED_INTRANS    0        /* ttl==0 in transit */
  283. #define    ICMP_TIMXCEED_REASS    1        /* ttl==0 in reass */
  284.  
  285. /* PARAMPROB code */
  286. #define    ICMP_PARAMPROB_OPTABSENT 1        /* req. opt. absent */
  287.  
  288. #define    ICMP_INFOTYPE(type) \
  289.     ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \
  290.     (type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \
  291.     (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \
  292.     (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \
  293.     (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY)
  294.  
  295. #endif /* __USE_BSD */
  296.  
  297. __END_DECLS
  298.  
  299. #endif /* netinet/ip_icmp.h */
  300.