ip.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /* @(#) $Header: /home/pdw/vcvs/repos/iftop/ip.h,v 1.2 2003/06/06 22:42:35 pdw Exp $ (LBL) */
  2. /*
  3. * Copyright (c) 1982, 1986, 1993
  4. * The Regents of the University of California. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. All advertising materials mentioning features or use of this software
  15. * must display the following acknowledgement:
  16. * This product includes software developed by the University of
  17. * California, Berkeley and its contributors.
  18. * 4. Neither the name of the University nor the names of its contributors
  19. * may be used to endorse or promote products derived from this software
  20. * without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  23. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  26. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  28. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  29. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  31. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * @(#)ip.h 8.2 (Berkeley) 6/1/94
  35. */
  36. /*
  37. * Definitions for internet protocol version 4.
  38. * Per RFC 791, September 1981.
  39. */
  40. #define IPVERSION 4
  41. /*
  42. * Structure of an internet header, naked of options.
  43. *
  44. * We declare ip_len and ip_off to be short, rather than u_short
  45. * pragmatically since otherwise unsigned comparisons can result
  46. * against negative integers quite easily, and fail in subtle ways.
  47. */
  48. struct ip {
  49. u_int8_t ip_vhl; /* header length, version */
  50. #define IP_V(ip) (((ip)->ip_vhl & 0xf0) >> 4)
  51. #define IP_HL(ip) ((ip)->ip_vhl & 0x0f)
  52. u_int8_t ip_tos; /* type of service */
  53. u_int16_t ip_len; /* total length */
  54. u_int16_t ip_id; /* identification */
  55. u_int16_t ip_off; /* fragment offset field */
  56. #define IP_DF 0x4000 /* dont fragment flag */
  57. #define IP_MF 0x2000 /* more fragments flag */
  58. #define IP_OFFMASK 0x1fff /* mask for fragmenting bits */
  59. u_int8_t ip_ttl; /* time to live */
  60. u_int8_t ip_p; /* protocol */
  61. u_int16_t ip_sum; /* checksum */
  62. struct in_addr ip_src,ip_dst; /* source and dest address */
  63. };
  64. #define IP_MAXPACKET 65535 /* maximum packet size */
  65. /*
  66. * Definitions for IP type of service (ip_tos)
  67. */
  68. #define IPTOS_LOWDELAY 0x10
  69. #define IPTOS_THROUGHPUT 0x08
  70. #define IPTOS_RELIABILITY 0x04
  71. /*
  72. * Definitions for IP precedence (also in ip_tos) (hopefully unused)
  73. */
  74. #define IPTOS_PREC_NETCONTROL 0xe0
  75. #define IPTOS_PREC_INTERNETCONTROL 0xc0
  76. #define IPTOS_PREC_CRITIC_ECP 0xa0
  77. #define IPTOS_PREC_FLASHOVERRIDE 0x80
  78. #define IPTOS_PREC_FLASH 0x60
  79. #define IPTOS_PREC_IMMEDIATE 0x40
  80. #define IPTOS_PREC_PRIORITY 0x20
  81. #define IPTOS_PREC_ROUTINE 0x00
  82. /*
  83. * Definitions for options.
  84. */
  85. #define IPOPT_COPIED(o) ((o)&0x80)
  86. #define IPOPT_CLASS(o) ((o)&0x60)
  87. #define IPOPT_NUMBER(o) ((o)&0x1f)
  88. #define IPOPT_CONTROL 0x00
  89. #define IPOPT_RESERVED1 0x20
  90. #define IPOPT_DEBMEAS 0x40
  91. #define IPOPT_RESERVED2 0x60
  92. #define IPOPT_EOL 0 /* end of option list */
  93. #define IPOPT_NOP 1 /* no operation */
  94. #define IPOPT_RR 7 /* record packet route */
  95. #define IPOPT_TS 68 /* timestamp */
  96. #define IPOPT_SECURITY 130 /* provide s,c,h,tcc */
  97. #define IPOPT_LSRR 131 /* loose source route */
  98. #define IPOPT_SATID 136 /* satnet id */
  99. #define IPOPT_SSRR 137 /* strict source route */
  100. /*
  101. * Offsets to fields in options other than EOL and NOP.
  102. */
  103. #define IPOPT_OPTVAL 0 /* option ID */
  104. #define IPOPT_OLEN 1 /* option length */
  105. #define IPOPT_OFFSET 2 /* offset within option */
  106. #define IPOPT_MINOFF 4 /* min value of above */
  107. /*
  108. * Time stamp option structure.
  109. */
  110. struct ip_timestamp {
  111. u_int8_t ipt_code; /* IPOPT_TS */
  112. u_int8_t ipt_len; /* size of structure (variable) */
  113. u_int8_t ipt_ptr; /* index of current entry */
  114. u_int8_t ipt_oflwflg; /* flags, overflow counter */
  115. #define IPTS_OFLW(ip) (((ipt)->ipt_oflwflg & 0xf0) >> 4)
  116. #define IPTS_FLG(ip) ((ipt)->ipt_oflwflg & 0x0f)
  117. union ipt_timestamp {
  118. u_int32_t ipt_time[1];
  119. struct ipt_ta {
  120. struct in_addr ipt_addr;
  121. u_int32_t ipt_time;
  122. } ipt_ta[1];
  123. } ipt_timestamp;
  124. };
  125. /* flag bits for ipt_flg */
  126. #define IPOPT_TS_TSONLY 0 /* timestamps only */
  127. #define IPOPT_TS_TSANDADDR 1 /* timestamps and addresses */
  128. #define IPOPT_TS_PRESPEC 3 /* specified modules only */
  129. /* bits for security (not byte swapped) */
  130. #define IPOPT_SECUR_UNCLASS 0x0000
  131. #define IPOPT_SECUR_CONFID 0xf135
  132. #define IPOPT_SECUR_EFTO 0x789a
  133. #define IPOPT_SECUR_MMMM 0xbc4d
  134. #define IPOPT_SECUR_RESTR 0xaf13
  135. #define IPOPT_SECUR_SECRET 0xd788
  136. #define IPOPT_SECUR_TOPSECRET 0x6bc5
  137. /*
  138. * Internet implementation parameters.
  139. */
  140. #define MAXTTL 255 /* maximum time to live (seconds) */
  141. #define IPDEFTTL 64 /* default ttl, from RFC 1340 */
  142. #define IPFRAGTTL 60 /* time to live for frags, slowhz */
  143. #define IPTTLDEC 1 /* subtracted when forwarding */
  144. #define IP_MSS 576 /* default maximum segment size */