inet.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice,
  9. * this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. * 3. The name of the author may not be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  17. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  19. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  20. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  21. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  24. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  25. * OF SUCH DAMAGE.
  26. *
  27. * This file is part of the lwIP TCP/IP stack.
  28. *
  29. * Author: Adam Dunkels <adam@sics.se>
  30. *
  31. */
  32. #ifndef __LWIP_INET_H__
  33. #define __LWIP_INET_H__
  34. #include "lwip/opt.h"
  35. #include "lwip/def.h"
  36. #include "lwip/ip_addr.h"
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /** For compatibility with BSD code */
  41. struct in_addr {
  42. u32_t s_addr;
  43. };
  44. /** 255.255.255.255 */
  45. #define INADDR_NONE IPADDR_NONE
  46. /** 127.0.0.1 */
  47. #define INADDR_LOOPBACK IPADDR_LOOPBACK
  48. /** 0.0.0.0 */
  49. #define INADDR_ANY IPADDR_ANY
  50. /** 255.255.255.255 */
  51. #define INADDR_BROADCAST IPADDR_BROADCAST
  52. /* Definitions of the bits in an Internet address integer.
  53. On subnets, host and network parts are found according to
  54. the subnet mask, not these masks. */
  55. #define IN_CLASSA(a) IP_CLASSA(a)
  56. #define IN_CLASSA_NET IP_CLASSA_NET
  57. #define IN_CLASSA_NSHIFT IP_CLASSA_NSHIFT
  58. #define IN_CLASSA_HOST IP_CLASSA_HOST
  59. #define IN_CLASSA_MAX IP_CLASSA_MAX
  60. #define IN_CLASSB(b) IP_CLASSB(b)
  61. #define IN_CLASSB_NET IP_CLASSB_NET
  62. #define IN_CLASSB_NSHIFT IP_CLASSB_NSHIFT
  63. #define IN_CLASSB_HOST IP_CLASSB_HOST
  64. #define IN_CLASSB_MAX IP_CLASSB_MAX
  65. #define IN_CLASSC(c) IP_CLASSC(c)
  66. #define IN_CLASSC_NET IP_CLASSC_NET
  67. #define IN_CLASSC_NSHIFT IP_CLASSC_NSHIFT
  68. #define IN_CLASSC_HOST IP_CLASSC_HOST
  69. #define IN_CLASSC_MAX IP_CLASSC_MAX
  70. #define IN_CLASSD(d) IP_CLASSD(d)
  71. #define IN_CLASSD_NET IP_CLASSD_NET /* These ones aren't really */
  72. #define IN_CLASSD_NSHIFT IP_CLASSD_NSHIFT /* net and host fields, but */
  73. #define IN_CLASSD_HOST IP_CLASSD_HOST /* routing needn't know. */
  74. #define IN_CLASSD_MAX IP_CLASSD_MAX
  75. #define IN_MULTICAST(a) IP_MULTICAST(a)
  76. #define IN_EXPERIMENTAL(a) IP_EXPERIMENTAL(a)
  77. #define IN_BADCLASS(a) IP_BADCLASS(a)
  78. #define IN_LOOPBACKNET IP_LOOPBACKNET
  79. #define inet_addr_from_ipaddr(target_inaddr, source_ipaddr) ((target_inaddr)->s_addr = ip4_addr_get_u32(source_ipaddr))
  80. #define inet_addr_to_ipaddr(target_ipaddr, source_inaddr) (ip4_addr_set_u32(target_ipaddr, (source_inaddr)->s_addr))
  81. /* ATTENTION: the next define only works because both s_addr and ip_addr_t are an u32_t effectively! */
  82. #define inet_addr_to_ipaddr_p(target_ipaddr_p, source_inaddr) ((target_ipaddr_p) = (ip_addr_t*)&((source_inaddr)->s_addr))
  83. /* directly map this to the lwip internal functions */
  84. #define inet_addr(cp) ipaddr_addr(cp)
  85. #define inet_aton(cp, addr) ipaddr_aton(cp, (ip_addr_t*)addr)
  86. #define inet_ntoa(addr) ipaddr_ntoa((ip_addr_t*)&(addr))
  87. #define inet_ntoa_r(addr, buf, buflen) ipaddr_ntoa_r((ip_addr_t*)&(addr), buf, buflen)
  88. #ifdef __cplusplus
  89. }
  90. #endif
  91. #endif /* __LWIP_INET_H__ */