ip.h 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. /* Copyright (C) 1991,92,93,95,96,97,98,99,2000,2009 Free Software
  2. Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  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 Explicit Congestion Notification (ECN)
  142. *
  143. * Taken from RFC-3168, Section 5.
  144. */
  145. #define IPTOS_ECN_MASK 0x03
  146. #define IPTOS_ECN(x) ((x) & IPTOS_ECN_MASK)
  147. #define IPTOS_ECN_NOT_ECT 0x00
  148. #define IPTOS_ECN_ECT1 0x01
  149. #define IPTOS_ECN_ECT0 0x02
  150. #define IPTOS_ECN_CE 0x03
  151. /*
  152. * Definitions for IP differentiated services code points (DSCP)
  153. *
  154. * Taken from RFC-2597, Section 6 and RFC-2598, Section 2.3.
  155. */
  156. #define IPTOS_DSCP_MASK 0xfc
  157. #define IPTOS_DSCP(x) ((x) & IPTOS_DSCP_MASK)
  158. #define IPTOS_DSCP_AF11 0x28
  159. #define IPTOS_DSCP_AF12 0x30
  160. #define IPTOS_DSCP_AF13 0x38
  161. #define IPTOS_DSCP_AF21 0x48
  162. #define IPTOS_DSCP_AF22 0x50
  163. #define IPTOS_DSCP_AF23 0x58
  164. #define IPTOS_DSCP_AF31 0x68
  165. #define IPTOS_DSCP_AF32 0x70
  166. #define IPTOS_DSCP_AF33 0x78
  167. #define IPTOS_DSCP_AF41 0x88
  168. #define IPTOS_DSCP_AF42 0x90
  169. #define IPTOS_DSCP_AF43 0x98
  170. #define IPTOS_DSCP_EF 0xb8
  171. /*
  172. * Definitions for IP type of service (ip_tos)
  173. */
  174. #define IPTOS_TOS_MASK 0x1E
  175. #define IPTOS_TOS(tos) ((tos) & IPTOS_TOS_MASK)
  176. #define IPTOS_LOWDELAY 0x10
  177. #define IPTOS_THROUGHPUT 0x08
  178. #define IPTOS_RELIABILITY 0x04
  179. #define IPTOS_LOWCOST 0x02
  180. #define IPTOS_MINCOST IPTOS_LOWCOST
  181. /*
  182. * Definitions for IP precedence (also in ip_tos) (hopefully unused)
  183. */
  184. #define IPTOS_PREC_MASK 0xe0
  185. #define IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK)
  186. #define IPTOS_PREC_NETCONTROL 0xe0
  187. #define IPTOS_PREC_INTERNETCONTROL 0xc0
  188. #define IPTOS_PREC_CRITIC_ECP 0xa0
  189. #define IPTOS_PREC_FLASHOVERRIDE 0x80
  190. #define IPTOS_PREC_FLASH 0x60
  191. #define IPTOS_PREC_IMMEDIATE 0x40
  192. #define IPTOS_PREC_PRIORITY 0x20
  193. #define IPTOS_PREC_ROUTINE 0x00
  194. /*
  195. * Definitions for options.
  196. */
  197. #define IPOPT_COPY 0x80
  198. #define IPOPT_CLASS_MASK 0x60
  199. #define IPOPT_NUMBER_MASK 0x1f
  200. #define IPOPT_COPIED(o) ((o) & IPOPT_COPY)
  201. #define IPOPT_CLASS(o) ((o) & IPOPT_CLASS_MASK)
  202. #define IPOPT_NUMBER(o) ((o) & IPOPT_NUMBER_MASK)
  203. #define IPOPT_CONTROL 0x00
  204. #define IPOPT_RESERVED1 0x20
  205. #define IPOPT_DEBMEAS 0x40
  206. #define IPOPT_MEASUREMENT IPOPT_DEBMEAS
  207. #define IPOPT_RESERVED2 0x60
  208. #define IPOPT_EOL 0 /* end of option list */
  209. #define IPOPT_END IPOPT_EOL
  210. #define IPOPT_NOP 1 /* no operation */
  211. #define IPOPT_NOOP IPOPT_NOP
  212. #define IPOPT_RR 7 /* record packet route */
  213. #define IPOPT_TS 68 /* timestamp */
  214. #define IPOPT_TIMESTAMP IPOPT_TS
  215. #define IPOPT_SECURITY 130 /* provide s,c,h,tcc */
  216. #define IPOPT_SEC IPOPT_SECURITY
  217. #define IPOPT_LSRR 131 /* loose source route */
  218. #define IPOPT_SATID 136 /* satnet id */
  219. #define IPOPT_SID IPOPT_SATID
  220. #define IPOPT_SSRR 137 /* strict source route */
  221. #define IPOPT_RA 148 /* router alert */
  222. /*
  223. * Offsets to fields in options other than EOL and NOP.
  224. */
  225. #define IPOPT_OPTVAL 0 /* option ID */
  226. #define IPOPT_OLEN 1 /* option length */
  227. #define IPOPT_OFFSET 2 /* offset within option */
  228. #define IPOPT_MINOFF 4 /* min value of above */
  229. #define MAX_IPOPTLEN 40
  230. /* flag bits for ipt_flg */
  231. #define IPOPT_TS_TSONLY 0 /* timestamps only */
  232. #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
  233. #define IPOPT_TS_PRESPEC 3 /* specified modules only */
  234. /* bits for security (not byte swapped) */
  235. #define IPOPT_SECUR_UNCLASS 0x0000
  236. #define IPOPT_SECUR_CONFID 0xf135
  237. #define IPOPT_SECUR_EFTO 0x789a
  238. #define IPOPT_SECUR_MMMM 0xbc4d
  239. #define IPOPT_SECUR_RESTR 0xaf13
  240. #define IPOPT_SECUR_SECRET 0xd788
  241. #define IPOPT_SECUR_TOPSECRET 0x6bc5
  242. /*
  243. * Internet implementation parameters.
  244. */
  245. #define MAXTTL 255 /* maximum time to live (seconds) */
  246. #define IPDEFTTL 64 /* default ttl, from RFC 1340 */
  247. #define IPFRAGTTL 60 /* time to live for frags, slowhz */
  248. #define IPTTLDEC 1 /* subtracted when forwarding */
  249. #define IP_MSS 576 /* default maximum segment size */
  250. __END_DECLS
  251. #endif /* netinet/ip.h */