ip.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /* Copyright (C) 1991,92,93,95,96,97,98,99,2000 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. The GNU C Library is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU Lesser General Public
  5. License as published by the Free Software Foundation; either
  6. version 2.1 of the License, or (at your option) any later version.
  7. The GNU C Library is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. Lesser General Public License for more details.
  11. You should have received a copy of the GNU Lesser General Public
  12. License along with the GNU C Library; if not, write to the Free
  13. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  14. 02111-1307 USA. */
  15. #ifndef __NETINET_IP_H
  16. #define __NETINET_IP_H 1
  17. #include <features.h>
  18. #include <sys/types.h>
  19. #include <netinet/in.h>
  20. __BEGIN_DECLS
  21. struct timestamp
  22. {
  23. u_int8_t len;
  24. u_int8_t ptr;
  25. #if __BYTE_ORDER == __LITTLE_ENDIAN
  26. unsigned int flags:4;
  27. unsigned int overflow:4;
  28. #elif __BYTE_ORDER == __BIG_ENDIAN
  29. unsigned int overflow:4;
  30. unsigned int flags:4;
  31. #else
  32. # error "Please fix <bits/endian.h>"
  33. #endif
  34. u_int32_t data[9];
  35. };
  36. struct iphdr
  37. {
  38. #if __BYTE_ORDER == __LITTLE_ENDIAN
  39. unsigned int ihl:4;
  40. unsigned int version:4;
  41. #elif __BYTE_ORDER == __BIG_ENDIAN
  42. unsigned int version:4;
  43. unsigned int ihl:4;
  44. #else
  45. # error "Please fix <bits/endian.h>"
  46. #endif
  47. u_int8_t tos;
  48. u_int16_t tot_len;
  49. u_int16_t id;
  50. u_int16_t frag_off;
  51. u_int8_t ttl;
  52. u_int8_t protocol;
  53. u_int16_t check;
  54. u_int32_t saddr;
  55. u_int32_t daddr;
  56. /*The options start here. */
  57. };
  58. #ifdef __USE_BSD
  59. /*
  60. * Copyright (c) 1982, 1986, 1993
  61. * The Regents of the University of California. All rights reserved.
  62. *
  63. * Redistribution and use in source and binary forms, with or without
  64. * modification, are permitted provided that the following conditions
  65. * are met:
  66. * 1. Redistributions of source code must retain the above copyright
  67. * notice, this list of conditions and the following disclaimer.
  68. * 2. Redistributions in binary form must reproduce the above copyright
  69. * notice, this list of conditions and the following disclaimer in the
  70. * documentation and/or other materials provided with the distribution.
  71. * 4. Neither the name of the University nor the names of its contributors
  72. * may be used to endorse or promote products derived from this software
  73. * without specific prior written permission.
  74. *
  75. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  76. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  77. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  78. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  79. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  80. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  81. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  82. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  83. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  84. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  85. * SUCH DAMAGE.
  86. *
  87. * @(#)ip.h 8.1 (Berkeley) 6/10/93
  88. */
  89. /*
  90. * Definitions for internet protocol version 4.
  91. * Per RFC 791, September 1981.
  92. */
  93. /*
  94. * Structure of an internet header, naked of options.
  95. */
  96. struct ip
  97. {
  98. #if __BYTE_ORDER == __LITTLE_ENDIAN
  99. unsigned int ip_hl:4; /* header length */
  100. unsigned int ip_v:4; /* version */
  101. #endif
  102. #if __BYTE_ORDER == __BIG_ENDIAN
  103. unsigned int ip_v:4; /* version */
  104. unsigned int ip_hl:4; /* header length */
  105. #endif
  106. u_int8_t ip_tos; /* type of service */
  107. u_short ip_len; /* total length */
  108. u_short ip_id; /* identification */
  109. u_short ip_off; /* fragment offset field */
  110. #define IP_RF 0x8000 /* reserved fragment flag */
  111. #define IP_DF 0x4000 /* dont fragment flag */
  112. #define IP_MF 0x2000 /* more fragments flag */
  113. #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
  114. u_int8_t ip_ttl; /* time to live */
  115. u_int8_t ip_p; /* protocol */
  116. u_short ip_sum; /* checksum */
  117. struct in_addr ip_src, ip_dst; /* source and dest address */
  118. };
  119. /*
  120. * Time stamp option structure.
  121. */
  122. struct ip_timestamp
  123. {
  124. u_int8_t ipt_code; /* IPOPT_TS */
  125. u_int8_t ipt_len; /* size of structure (variable) */
  126. u_int8_t ipt_ptr; /* index of current entry */
  127. #if __BYTE_ORDER == __LITTLE_ENDIAN
  128. unsigned int ipt_flg:4; /* flags, see below */
  129. unsigned int ipt_oflw:4; /* overflow counter */
  130. #endif
  131. #if __BYTE_ORDER == __BIG_ENDIAN
  132. unsigned int ipt_oflw:4; /* overflow counter */
  133. unsigned int ipt_flg:4; /* flags, see below */
  134. #endif
  135. u_int32_t data[9];
  136. };
  137. #endif /* __USE_BSD */
  138. #define IPVERSION 4 /* IP version number */
  139. #define IP_MAXPACKET 65535 /* maximum packet size */
  140. /*
  141. * Definitions for IP type of service (ip_tos)
  142. */
  143. #define IPTOS_TOS_MASK 0x1E
  144. #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
  145. #define IPTOS_LOWDELAY 0x10
  146. #define IPTOS_THROUGHPUT 0x08
  147. #define IPTOS_RELIABILITY 0x04
  148. #define IPTOS_LOWCOST 0x02
  149. #define IPTOS_MINCOST IPTOS_LOWCOST
  150. /*
  151. * Definitions for IP precedence (also in ip_tos) (hopefully unused)
  152. */
  153. #define IPTOS_PREC_MASK 0xe0
  154. #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK)
  155. #define IPTOS_PREC_NETCONTROL 0xe0
  156. #define IPTOS_PREC_INTERNETCONTROL 0xc0
  157. #define IPTOS_PREC_CRITIC_ECP 0xa0
  158. #define IPTOS_PREC_FLASHOVERRIDE 0x80
  159. #define IPTOS_PREC_FLASH 0x60
  160. #define IPTOS_PREC_IMMEDIATE 0x40
  161. #define IPTOS_PREC_PRIORITY 0x20
  162. #define IPTOS_PREC_ROUTINE 0x00
  163. /*
  164. * Definitions for options.
  165. */
  166. #define IPOPT_COPY 0x80
  167. #define IPOPT_CLASS_MASK 0x60
  168. #define IPOPT_NUMBER_MASK 0x1f
  169. #define IPOPT_COPIED(o) ((o) & IPOPT_COPY)
  170. #define IPOPT_CLASS(o) ((o) & IPOPT_CLASS_MASK)
  171. #define IPOPT_NUMBER(o) ((o) & IPOPT_NUMBER_MASK)
  172. #define IPOPT_CONTROL 0x00
  173. #define IPOPT_RESERVED1 0x20
  174. #define IPOPT_DEBMEAS 0x40
  175. #define IPOPT_MEASUREMENT IPOPT_DEBMEAS
  176. #define IPOPT_RESERVED2 0x60
  177. #define IPOPT_EOL 0 /* end of option list */
  178. #define IPOPT_END IPOPT_EOL
  179. #define IPOPT_NOP 1 /* no operation */
  180. #define IPOPT_NOOP IPOPT_NOP
  181. #define IPOPT_RR 7 /* record packet route */
  182. #define IPOPT_TS 68 /* timestamp */
  183. #define IPOPT_TIMESTAMP IPOPT_TS
  184. #define IPOPT_SECURITY 130 /* provide s,c,h,tcc */
  185. #define IPOPT_SEC IPOPT_SECURITY
  186. #define IPOPT_LSRR 131 /* loose source route */
  187. #define IPOPT_SATID 136 /* satnet id */
  188. #define IPOPT_SID IPOPT_SATID
  189. #define IPOPT_SSRR 137 /* strict source route */
  190. #define IPOPT_RA 148 /* router alert */
  191. /*
  192. * Offsets to fields in options other than EOL and NOP.
  193. */
  194. #define IPOPT_OPTVAL 0 /* option ID */
  195. #define IPOPT_OLEN 1 /* option length */
  196. #define IPOPT_OFFSET 2 /* offset within option */
  197. #define IPOPT_MINOFF 4 /* min value of above */
  198. #define MAX_IPOPTLEN 40
  199. /* flag bits for ipt_flg */
  200. #define IPOPT_TS_TSONLY 0 /* timestamps only */
  201. #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
  202. #define IPOPT_TS_PRESPEC 3 /* specified modules only */
  203. /* bits for security (not byte swapped) */
  204. #define IPOPT_SECUR_UNCLASS 0x0000
  205. #define IPOPT_SECUR_CONFID 0xf135
  206. #define IPOPT_SECUR_EFTO 0x789a
  207. #define IPOPT_SECUR_MMMM 0xbc4d
  208. #define IPOPT_SECUR_RESTR 0xaf13
  209. #define IPOPT_SECUR_SECRET 0xd788
  210. #define IPOPT_SECUR_TOPSECRET 0x6bc5
  211. /*
  212. * Internet implementation parameters.
  213. */
  214. #define MAXTTL 255 /* maximum time to live (seconds) */
  215. #define IPDEFTTL 64 /* default ttl, from RFC 1340 */
  216. #define IPFRAGTTL 60 /* time to live for frags, slowhz */
  217. #define IPTTLDEC 1 /* subtracted when forwarding */
  218. #define IP_MSS 576 /* default maximum segment size */
  219. __END_DECLS
  220. #endif /* netinet/ip.h */