1 /* 2 * Copyright (c) 1982, 1986 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that the above copyright notice and this paragraph are 7 * duplicated in all such forms and that any documentation, 8 * advertising materials, and other materials related to such 9 * distribution and use acknowledge that the software was developed 10 * by the University of California, Berkeley. The name of the 11 * University may not be used to endorse or promote products derived 12 * from this software without specific prior written permission. 13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR 14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED 15 * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. 16 * 17 * @(#)ip_icmp.h 7.4 (Berkeley) 06/29/88 18 */ 19 20 /* 21 * Interface Control Message Protocol Definitions. 22 * Per RFC 792, September 1981. 23 */ 24 25 /* 26 * Structure of an icmp header. 27 */ 28 struct icmp { 29 u_char icmp_type; /* type of message, see below */ 30 u_char icmp_code; /* type sub code */ 31 u_short icmp_cksum; /* ones complement cksum of struct */ 32 union { 33 u_char ih_pptr; /* ICMP_PARAMPROB */ 34 struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ 35 struct ih_idseq { 36 n_short icd_id; 37 n_short icd_seq; 38 } ih_idseq; 39 int ih_void; 40 } icmp_hun; 41 #define icmp_pptr icmp_hun.ih_pptr 42 #define icmp_gwaddr icmp_hun.ih_gwaddr 43 #define icmp_id icmp_hun.ih_idseq.icd_id 44 #define icmp_seq icmp_hun.ih_idseq.icd_seq 45 #define icmp_void icmp_hun.ih_void 46 union { 47 struct id_ts { 48 n_time its_otime; 49 n_time its_rtime; 50 n_time its_ttime; 51 } id_ts; 52 struct id_ip { 53 struct ip idi_ip; 54 /* options and then 64 bits of data */ 55 } id_ip; 56 u_long id_mask; 57 char id_data[1]; 58 } icmp_dun; 59 #define icmp_otime icmp_dun.id_ts.its_otime 60 #define icmp_rtime icmp_dun.id_ts.its_rtime 61 #define icmp_ttime icmp_dun.id_ts.its_ttime 62 #define icmp_ip icmp_dun.id_ip.idi_ip 63 #define icmp_mask icmp_dun.id_mask 64 #define icmp_data icmp_dun.id_data 65 }; 66 67 /* 68 * Lower bounds on packet lengths for various types. 69 * For the error advice packets must first insure that the 70 * packet is large enought to contain the returned ip header. 71 * Only then can we do the check to see if 64 bits of packet 72 * data have been returned, since we need to check the returned 73 * ip header length. 74 */ 75 #define ICMP_MINLEN 8 /* abs minimum */ 76 #define ICMP_TSLEN (8 + 3 * sizeof (n_time)) /* timestamp */ 77 #define ICMP_MASKLEN 12 /* address mask */ 78 #define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) /* min */ 79 #define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8) 80 /* N.B.: must separately check that ip_hl >= 5 */ 81 82 /* 83 * Definition of type and code field values. 84 */ 85 #define ICMP_ECHOREPLY 0 /* echo reply */ 86 #define ICMP_UNREACH 3 /* dest unreachable, codes: */ 87 #define ICMP_UNREACH_NET 0 /* bad net */ 88 #define ICMP_UNREACH_HOST 1 /* bad host */ 89 #define ICMP_UNREACH_PROTOCOL 2 /* bad protocol */ 90 #define ICMP_UNREACH_PORT 3 /* bad port */ 91 #define ICMP_UNREACH_NEEDFRAG 4 /* IP_DF caused drop */ 92 #define ICMP_UNREACH_SRCFAIL 5 /* src route failed */ 93 #define ICMP_SOURCEQUENCH 4 /* packet lost, slow down */ 94 #define ICMP_REDIRECT 5 /* shorter route, codes: */ 95 #define ICMP_REDIRECT_NET 0 /* for network */ 96 #define ICMP_REDIRECT_HOST 1 /* for host */ 97 #define ICMP_REDIRECT_TOSNET 2 /* for tos and net */ 98 #define ICMP_REDIRECT_TOSHOST 3 /* for tos and host */ 99 #define ICMP_ECHO 8 /* echo service */ 100 #define ICMP_TIMXCEED 11 /* time exceeded, code: */ 101 #define ICMP_TIMXCEED_INTRANS 0 /* ttl==0 in transit */ 102 #define ICMP_TIMXCEED_REASS 1 /* ttl==0 in reass */ 103 #define ICMP_PARAMPROB 12 /* ip header bad */ 104 #define ICMP_TSTAMP 13 /* timestamp request */ 105 #define ICMP_TSTAMPREPLY 14 /* timestamp reply */ 106 #define ICMP_IREQ 15 /* information request */ 107 #define ICMP_IREQREPLY 16 /* information reply */ 108 #define ICMP_MASKREQ 17 /* address mask request */ 109 #define ICMP_MASKREPLY 18 /* address mask reply */ 110 111 #define ICMP_MAXTYPE 18 112 113 #define ICMP_INFOTYPE(type) \ 114 ((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \ 115 (type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \ 116 (type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \ 117 (type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY) 118