ip.h 8.7 KB

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