| 1 |
/* |
| 2 |
Copyright (C) 2001-2026 Free Software Foundation, Inc. |
| 3 |
|
| 4 |
This file is part of GNU Inetutils. |
| 5 |
|
| 6 |
GNU Inetutils is free software: you can redistribute it and/or modify |
| 7 |
it under the terms of the GNU General Public License as published by |
| 8 |
the Free Software Foundation, either version 3 of the License, or (at |
| 9 |
your option) any later version. |
| 10 |
|
| 11 |
GNU Inetutils is distributed in the hope that it will be useful, but |
| 12 |
WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 |
General Public License for more details. |
| 15 |
|
| 16 |
You should have received a copy of the GNU General Public License |
| 17 |
along with this program. If not, see `http://www.gnu.org/licenses/'. */ |
| 18 |
|
| 19 |
/* |
| 20 |
* Structure of an icmp header. |
| 21 |
*/ |
| 22 |
typedef struct icmp_header icmphdr_t; |
| 23 |
|
| 24 |
struct icmp_header |
| 25 |
{ |
| 26 |
unsigned char icmp_type; /* type of message, see below */ |
| 27 |
unsigned char icmp_code; /* type sub code */ |
| 28 |
unsigned short icmp_cksum; /* ones complement cksum of struct */ |
| 29 |
union |
| 30 |
{ |
| 31 |
unsigned char ih_pptr; /* ICMP_PARAMPROB */ |
| 32 |
struct in_addr ih_gwaddr; /* ICMP_REDIRECT */ |
| 33 |
struct ih_idseq |
| 34 |
{ |
| 35 |
unsigned short icd_id; |
| 36 |
unsigned short icd_seq; |
| 37 |
} ih_idseq; |
| 38 |
int ih_void; |
| 39 |
|
| 40 |
/* ICMP_UNREACH_NEEDFRAG -- Path MTU discovery as per rfc 1191 */ |
| 41 |
struct ih_pmtu |
| 42 |
{ |
| 43 |
unsigned short ipm_void; |
| 44 |
unsigned short ipm_nextmtu; |
| 45 |
} ih_pmtu; |
| 46 |
|
| 47 |
/* ICMP_ROUTERADV -- RFC 1256 */ |
| 48 |
struct ih_rtradv |
| 49 |
{ |
| 50 |
unsigned char irt_num_addrs; /* Number of addresses following the msg */ |
| 51 |
unsigned char irt_wpa; /* Address Entry Size (32-bit words) */ |
| 52 |
unsigned short irt_lifetime; /* Lifetime */ |
| 53 |
} ih_rtradv; |
| 54 |
|
| 55 |
} icmp_hun; |
| 56 |
#define icmp_pptr icmp_hun.ih_pptr |
| 57 |
#define icmp_gwaddr icmp_hun.ih_gwaddr |
| 58 |
#define icmp_id icmp_hun.ih_idseq.icd_id |
| 59 |
#define icmp_seq icmp_hun.ih_idseq.icd_seq |
| 60 |
#define icmp_void icmp_hun.ih_void |
| 61 |
#define icmp_pmvoid icmp_hun.ih_pmtu.ipm_void |
| 62 |
#define icmp_nextmtu icmp_hun.ih_pmtu.ipm_nextmtu |
| 63 |
#define icmp_num_addrs icmp_hun.ih_rtradv.irt_num_addrs |
| 64 |
#define icmp_wpa icmp_hun.ih_rtradv.irt_wpa |
| 65 |
#define icmp_lifetime icmp_hun.ih_rtradv.irt_lifetime |
| 66 |
|
| 67 |
union |
| 68 |
{ |
| 69 |
struct id_ts /* ICMP_TIMESTAMP, ICMP_TIMESTAMPREPLY */ |
| 70 |
{ |
| 71 |
n_time its_otime; /* Originate timestamp */ |
| 72 |
n_time its_rtime; /* Receive timestamp */ |
| 73 |
n_time its_ttime; /* Transmit timestamp */ |
| 74 |
} id_ts; |
| 75 |
struct id_ip /* Original IP header */ |
| 76 |
{ |
| 77 |
struct ip idi_ip; |
| 78 |
/* options and then 64 bits of data */ |
| 79 |
} id_ip; |
| 80 |
unsigned long id_mask; /* ICMP_ADDRESS, ICMP_ADDRESSREPLY */ |
| 81 |
char id_data[1]; |
| 82 |
} icmp_dun; |
| 83 |
#define icmp_otime icmp_dun.id_ts.its_otime |
| 84 |
#define icmp_rtime icmp_dun.id_ts.its_rtime |
| 85 |
#define icmp_ttime icmp_dun.id_ts.its_ttime |
| 86 |
#define icmp_ip icmp_dun.id_ip.idi_ip |
| 87 |
#define icmp_mask icmp_dun.id_mask |
| 88 |
#define icmp_data icmp_dun.id_data |
| 89 |
}; |
| 90 |
|
| 91 |
#define ICMP_ECHOREPLY 0 /* Echo Reply */ |
| 92 |
#define ICMP_DEST_UNREACH 3 /* Destination Unreachable */ |
| 93 |
/* Codes for ICMP_DEST_UNREACH. */ |
| 94 |
#define ICMP_NET_UNREACH 0 /* Network Unreachable */ |
| 95 |
#define ICMP_HOST_UNREACH 1 /* Host Unreachable */ |
| 96 |
#define ICMP_PROT_UNREACH 2 /* Protocol Unreachable */ |
| 97 |
#define ICMP_PORT_UNREACH 3 /* Port Unreachable */ |
| 98 |
#define ICMP_FRAG_NEEDED 4 /* Fragmentation Needed/DF set */ |
| 99 |
#define ICMP_SR_FAILED 5 /* Source Route failed */ |
| 100 |
#define ICMP_NET_UNKNOWN 6 |
| 101 |
#define ICMP_HOST_UNKNOWN 7 |
| 102 |
#define ICMP_HOST_ISOLATED 8 |
| 103 |
#define ICMP_NET_ANO 9 |
| 104 |
#define ICMP_HOST_ANO 10 |
| 105 |
#define ICMP_NET_UNR_TOS 11 |
| 106 |
#define ICMP_HOST_UNR_TOS 12 |
| 107 |
#define ICMP_PKT_FILTERED 13 /* Packet filtered */ |
| 108 |
#define ICMP_PREC_VIOLATION 14 /* Precedence violation */ |
| 109 |
#define ICMP_PREC_CUTOFF 15 /* Precedence cut off */ |
| 110 |
#define NR_ICMP_UNREACH 15 /* total subcodes */ |
| 111 |
|
| 112 |
#define ICMP_SOURCE_QUENCH 4 /* Source Quench */ |
| 113 |
#define ICMP_REDIRECT 5 /* Redirect (change route) */ |
| 114 |
/* Codes for ICMP_REDIRECT. */ |
| 115 |
#define ICMP_REDIR_NET 0 /* Redirect Net */ |
| 116 |
#define ICMP_REDIR_HOST 1 /* Redirect Host */ |
| 117 |
#define ICMP_REDIR_NETTOS 2 /* Redirect Net for TOS */ |
| 118 |
#define ICMP_REDIR_HOSTTOS 3 /* Redirect Host for TOS */ |
| 119 |
|
| 120 |
#define ICMP_ECHO 8 /* Echo Request */ |
| 121 |
#define ICMP_ROUTERADV 9 /* Router Advertisement -- RFC 1256 */ |
| 122 |
#define ICMP_ROUTERDISCOVERY 10 /* Router Discovery -- RFC 1256 */ |
| 123 |
#define ICMP_TIME_EXCEEDED 11 /* Time Exceeded */ |
| 124 |
/* Codes for TIME_EXCEEDED. */ |
| 125 |
#define ICMP_EXC_TTL 0 /* TTL count exceeded */ |
| 126 |
#define ICMP_EXC_FRAGTIME 1 /* Fragment Reass time exceeded */ |
| 127 |
|
| 128 |
#define ICMP_PARAMETERPROB 12 /* Parameter Problem */ |
| 129 |
#define ICMP_TIMESTAMP 13 /* Timestamp Request */ |
| 130 |
#define ICMP_TIMESTAMPREPLY 14 /* Timestamp Reply */ |
| 131 |
#define ICMP_INFO_REQUEST 15 /* Information Request */ |
| 132 |
#define ICMP_INFO_REPLY 16 /* Information Reply */ |
| 133 |
#define ICMP_ADDRESS 17 /* Address Mask Request */ |
| 134 |
#define ICMP_ADDRESSREPLY 18 /* Address Mask Reply */ |
| 135 |
#define NR_ICMP_TYPES 18 |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
#define MAXIPLEN 60 |
| 140 |
#define MAXICMPLEN 76 |
| 141 |
#define ICMP_MINLEN 8 /* abs minimum */ |
| 142 |
#define ICMP_TSLEN (8 + 3 * sizeof (n_time)) /* timestamp */ |
| 143 |
#define ICMP_MASKLEN 12 /* address mask */ |
| 144 |
#define ICMP_ADVLENMIN (8 + sizeof (struct ip) + 8) /* min */ |
| 145 |
#define ICMP_ADVLEN(p) (8 + ((p)->icmp_ip.ip_hl << 2) + 8) |
| 146 |
/* N.B.: must separately check that ip_hl >= 5 */ |
| 147 |
|
| 148 |
unsigned short icmp_cksum (unsigned char *addr, int len); |
| 149 |
int icmp_generic_encode (unsigned char *buffer, size_t bufsize, int type, |
| 150 |
int ident, int seqno); |
| 151 |
int icmp_generic_decode (unsigned char *buffer, size_t bufsize, |
| 152 |
struct ip **ipp, icmphdr_t ** icmpp); |
| 153 |
|
| 154 |
int icmp_echo_encode (unsigned char *buffer, size_t bufsize, int ident, |
| 155 |
int seqno); |
| 156 |
int icmp_echo_decode (unsigned char *buffer, size_t bufsize, struct ip **ip, |
| 157 |
icmphdr_t ** icmp); |
| 158 |
int icmp_timestamp_encode (unsigned char *buffer, size_t bufsize, int ident, |
| 159 |
int seqno); |
| 160 |
int icmp_address_encode (unsigned char *buffer, size_t bufsize, int ident, |
| 161 |
int seqno); |