Advertisement
Guest User

icmp.h

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