in.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #ifndef _NETINET_IN_H_
  2. /*
  3. * Copyright (C) 2001-2005 by egnite Software GmbH. All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. *
  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. Neither the name of the copyright holders nor the names of
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  21. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  22. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  23. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  24. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  25. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  26. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  27. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  28. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. *
  31. * For additional information see http://www.ethernut.de/
  32. *
  33. * -
  34. * Portions Copyright (C) 2000 David J. Hudson <dave@humbug.demon.co.uk>
  35. *
  36. * This file is distributed in the hope that it will be useful, but WITHOUT
  37. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  38. * FITNESS FOR A PARTICULAR PURPOSE.
  39. *
  40. * You can redistribute this file and/or modify it under the terms of the GNU
  41. * General Public License (GPL) as published by the Free Software Foundation;
  42. * either version 2 of the License, or (at your discretion) any later version.
  43. * See the accompanying file "copying-gpl.txt" for more details.
  44. *
  45. * As a special exception to the GPL, permission is granted for additional
  46. * uses of the text contained in this file. See the accompanying file
  47. * "copying-liquorice.txt" for details.
  48. * -
  49. * Portions Copyright (c) 1983, 1993 by
  50. * The Regents of the University of California. All rights reserved.
  51. *
  52. * Redistribution and use in source and binary forms, with or without
  53. * modification, are permitted provided that the following conditions
  54. * are met:
  55. * 1. Redistributions of source code must retain the above copyright
  56. * notice, this list of conditions and the following disclaimer.
  57. * 2. Redistributions in binary form must reproduce the above copyright
  58. * notice, this list of conditions and the following disclaimer in the
  59. * documentation and/or other materials provided with the distribution.
  60. * 3. Neither the name of the University nor the names of its contributors
  61. * may be used to endorse or promote products derived from this software
  62. * without specific prior written permission.
  63. *
  64. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  65. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  66. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  67. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  68. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  69. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  70. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  71. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  72. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  73. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  74. * SUCH DAMAGE.
  75. */
  76. /*
  77. * $Log$
  78. * Revision 1.6 2009/03/05 22:16:57 freckle
  79. * use __NUT_EMULATION instead of __APPLE__, __linux__, or __CYGWIN__
  80. *
  81. * Revision 1.5 2008/08/11 07:00:23 haraldkipp
  82. * BSD types replaced by stdint types (feature request #1282721).
  83. *
  84. * Revision 1.4 2007/05/02 11:18:32 haraldkipp
  85. * IGMP support added. Incomplete.
  86. *
  87. * Revision 1.3 2005/07/26 15:49:59 haraldkipp
  88. * Cygwin support added.
  89. *
  90. * Revision 1.2 2005/04/04 19:33:55 freckle
  91. * added creation of include/netdb_orig.h, include/sys/socket_orig.h and
  92. * include/netinet/in_orig.h to allow unix emulation to use tcp/ip sockets
  93. *
  94. * Revision 1.1.1.1 2003/05/09 14:41:14 haraldkipp
  95. * Initial using 3.2.1
  96. *
  97. * Revision 1.5 2003/02/04 18:00:45 harald
  98. * Version 3 released
  99. *
  100. * Revision 1.4 2002/06/26 17:29:21 harald
  101. * First pre-release with 2.4 stack
  102. *
  103. */
  104. #include <sys/types.h>
  105. /* use native version on unix emulation */
  106. #ifdef __NUT_EMULATION__
  107. #include <netinet/in_orig.h>
  108. /* assure _NETINET_IN_H_ is set */
  109. #undef _NETINET_IN_H_
  110. #define _NETINET_IN_H_
  111. #else /* unix emulation */
  112. #define _NETINET_IN_H_
  113. /*!
  114. * \file netinet/in.h
  115. * \brief Internet definitions.
  116. *
  117. * Constants and structures defined by the internet system.
  118. */
  119. /*
  120. * Protocols
  121. */
  122. #define IPPROTO_IP 0 /*!< \brief Dummy for IP. */
  123. #define IPPROTO_ICMP 1 /*!< \brief Control message protocol. */
  124. #define IPPROTO_IGMP 2 /*!< \brief Group management protocol. */
  125. #define IPPROTO_TCP 6 /*!< \brief Transmission control protocol. */
  126. #define IPPROTO_UDP 17 /*!< \brief User datagram protocol. */
  127. #define IPPROTO_RAW 255 /*!< \brief Raw IP packet. */
  128. #define IPPROTO_MAX 256 /*!< \brief Maximum protocol identifier. */
  129. #define IPPORT_RESERVED 1024 /*!< \brief Last reserved port number. */
  130. #define IPPORT_USERRESERVED 5000 /*!< \brief User reserved port number. */
  131. /*!
  132. * \brief Any IP address.
  133. */
  134. #define INADDR_ANY (uint32_t)0x00000000
  135. /*!
  136. * \brief Broadcast IP address.
  137. */
  138. #define INADDR_BROADCAST (uint32_t)0xffffffff
  139. /*
  140. * Definitions of bits in internet address integers.
  141. */
  142. #ifdef __BIG_ENDIAN__
  143. #define IN_CLASSA(i) (((uint32_t)(i) & 0x80000000) == 0)
  144. #define IN_CLASSA_NET 0xff000000
  145. #define IN_CLASSB(i) (((uint32_t)(i) & 0xc0000000) == 0x80000000)
  146. #define IN_CLASSB_NET 0xffff0000
  147. #define IN_CLASSC(i) (((uint32_t)(i) & 0xe0000000) == 0xc0000000)
  148. #define IN_CLASSC_NET 0xffffff00
  149. #define IN_CLASSD(i) (((uint32_t)(i) & 0xf0000000) == 0xe0000000)
  150. #define IN_CLASSD_NET 0xf0000000
  151. #else /* __BIG_ENDIAN__ */
  152. #define IN_CLASSA(i) (((uint32_t)(i) & 0x00000080) == 0)
  153. #define IN_CLASSA_NET 0x000000ff
  154. #define IN_CLASSB(i) (((uint32_t)(i) & 0x000000c0) == 0x00000080)
  155. #define IN_CLASSB_NET 0x0000ffff
  156. #define IN_CLASSC(i) (((uint32_t)(i) & 0x000000e0) == 0x000000c0)
  157. #define IN_CLASSC_NET 0x00ffffff
  158. #define IN_CLASSD(i) (((uint32_t)(i) & 0x000000f0) == 0x000000e0)
  159. #define IN_CLASSD_NET 0x0000000f
  160. #endif /* __BIG_ENDIAN__ */
  161. #define IN_MULTICAST(i) IN_CLASSD(i)
  162. #ifdef __BIG_ENDIAN__
  163. #define INADDR_UNSPEC_GROUP (uint32_t)0xe0000000 /* 224.0.0.0 */
  164. #define INADDR_ALLHOSTS_GROUP (uint32_t)0xe0000001 /* 224.0.0.1 */
  165. #define INADDR_ALLRTRS_GROUP (uint32_t)0xe0000002 /* 224.0.0.2 */
  166. #define INADDR_ALLRPTS_GROUP (uint32_t)0xe0000016 /* 224.0.0.22, IGMPv3 */
  167. #define INADDR_CARP_GROUP (uint32_t)0xe0000012 /* 224.0.0.18 */
  168. #define INADDR_PFSYNC_GROUP (uint32_t)0xe00000f0 /* 224.0.0.240 */
  169. #define INADDR_ALLMDNS_GROUP (uint32_t)0xe00000fb /* 224.0.0.251 */
  170. #define INADDR_MAX_LOCAL_GROUP (uint32_t)0xe00000ff /* 224.0.0.255 */
  171. #else /* __BIG_ENDIAN__ */
  172. #define INADDR_UNSPEC_GROUP (uint32_t)0x000000e0 /* 224.0.0.0 */
  173. #define INADDR_ALLHOSTS_GROUP (uint32_t)0x010000e0 /* 224.0.0.1 */
  174. #define INADDR_ALLRTRS_GROUP (uint32_t)0x020000e0 /* 224.0.0.2 */
  175. #define INADDR_ALLRPTS_GROUP (uint32_t)0x160000e0 /* 224.0.0.22, IGMPv3 */
  176. #define INADDR_CARP_GROUP (uint32_t)0x120000e0 /* 224.0.0.18 */
  177. #define INADDR_PFSYNC_GROUP (uint32_t)0xf00000e0 /* 224.0.0.240 */
  178. #define INADDR_ALLMDNS_GROUP (uint32_t)0xfb0000e0 /* 224.0.0.251 */
  179. #define INADDR_MAX_LOCAL_GROUP (uint32_t)0xff0000e0 /* 224.0.0.255 */
  180. #endif /* __BIG_ENDIAN__ */
  181. #ifdef __BIG_ENDIAN__
  182. #define INADDR_LOOPBACK (uint32_t)0x7f000001
  183. #else /* __BIG_ENDIAN__ */
  184. #define INADDR_LOOPBACK (uint32_t)0x0100007f
  185. #endif /* __BIG_ENDIAN__ */
  186. /*!
  187. * \brief Official loopback net address.
  188. */
  189. #define IN_LOOPBACKNET 127
  190. #endif /* unix emulation */
  191. #endif