Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 lines
3.2 KiB

  1. /*++
  2. Copyright (c) 1989-2001 Microsoft Corporation
  3. Module Name:
  4. ip6util.h
  5. Abstract:
  6. IP6 utilities
  7. Author:
  8. Jiandong Ruan
  9. Revision History:
  10. --*/
  11. #ifndef __IP6UTIL_H__
  12. #define __IP6UTIL_H__
  13. #ifndef htons
  14. #define htons(x) RtlUshortByteSwap(x)
  15. #endif
  16. #ifndef ntohs
  17. #define ntohs htons
  18. #endif
  19. #ifndef htonl
  20. #define htonl(x) RtlUlongByteSwap(x)
  21. #endif
  22. #ifndef ntohl
  23. #define ntohl htonl
  24. #endif
  25. typedef struct {
  26. union {
  27. USHORT sin6_addr[8];
  28. BYTE sin6_addr_bytes[16];
  29. };
  30. ULONG sin6_scope_id;
  31. } SMB_IP6_ADDRESS, *PSMB_IP6_ADDRESS;
  32. typedef struct {
  33. union {
  34. ULONG sin4_addr;
  35. BYTE sin4_addr_bytes[4];
  36. };
  37. } SMB_IP4_ADDRESS, *PSMB_IP4_ADDRESS;
  38. typedef struct {
  39. enum {
  40. SMB_AF_INET,
  41. SMB_AF_INET6,
  42. SMB_AF_INVALID_INET6,
  43. } sin_family;
  44. union {
  45. SMB_IP4_ADDRESS ip4;
  46. SMB_IP6_ADDRESS ip6;
  47. };
  48. } SMB_IP_ADDRESS, *PSMB_IP_ADDRESS;
  49. void __inline
  50. ip6addr_getany(
  51. PSMB_IP6_ADDRESS addr
  52. )
  53. {
  54. RtlZeroMemory(addr->sin6_addr, sizeof(addr->sin6_addr));
  55. }
  56. void __inline
  57. ip6addr_getloopback(
  58. PSMB_IP6_ADDRESS addr
  59. )
  60. {
  61. RtlZeroMemory(addr->sin6_addr, sizeof(addr->sin6_addr));
  62. addr->sin6_addr[7] = 1;
  63. addr->sin6_scope_id = 0;
  64. }
  65. void __inline
  66. hton_ip6addr(
  67. PSMB_IP6_ADDRESS addr
  68. )
  69. {
  70. int i;
  71. BYTE a, b;
  72. for (i = 0; i < 8; i++) {
  73. addr->sin6_addr[i] = RtlUshortByteSwap(addr->sin6_addr[i]);
  74. }
  75. }
  76. #define ntoh_ip6addr hton_ip6addr
  77. BOOL
  78. inet_addr6W(
  79. WCHAR *str,
  80. PSMB_IP6_ADDRESS addr
  81. );
  82. BOOL
  83. inet_ntoa6W(
  84. WCHAR *str,
  85. DWORD Size,
  86. PSMB_IP6_ADDRESS addr
  87. );
  88. BOOL
  89. inet_ntoa6(
  90. CHAR *str,
  91. DWORD Size,
  92. PSMB_IP6_ADDRESS addr
  93. );
  94. void
  95. Inet_ntoa_nb(
  96. ULONG Address,
  97. PCHAR Buffer
  98. );
  99. unsigned long PASCAL
  100. inet_addrW(
  101. IN WCHAR *cp
  102. );
  103. #ifndef INADDR_ANY
  104. # define INADDR_ANY 0
  105. #endif
  106. #ifndef INADDR_NONE
  107. # define INADDR_NONE 0
  108. #endif
  109. #ifndef INADDR_LOOPBACK
  110. # define INADDR_LOOPBACK (0x7f000001)
  111. #endif
  112. int __inline
  113. SMB_IS_LINKLOCAL(const BYTE bytes[16])
  114. {
  115. return ((bytes[0] == 0xfe) && ((bytes[1] & 0xc0) == 0x80));
  116. }
  117. int __inline
  118. SMB_IS_SITELOCAL(const BYTE bytes[16])
  119. {
  120. return ((bytes[0] == 0xfe) && ((bytes[1] & 0xc0) == 0xc0));
  121. }
  122. int __inline
  123. SMB_IS_LOOPBACK(const BYTE bytes[16])
  124. {
  125. return ((bytes[0] == 0) &&
  126. (bytes[1] == 0) &&
  127. (bytes[2] == 0) &&
  128. (bytes[3] == 0) &&
  129. (bytes[4] == 0) &&
  130. (bytes[5] == 0) &&
  131. (bytes[6] == 0) &&
  132. (bytes[7] == 0) &&
  133. (bytes[8] == 0) &&
  134. (bytes[9] == 0) &&
  135. (bytes[10] == 0) &&
  136. (bytes[11] == 0) &&
  137. (bytes[12] == 0) &&
  138. (bytes[13] == 0) &&
  139. (bytes[14] == 0) &&
  140. (bytes[15] == 1));
  141. }
  142. int __inline
  143. SMB_IS_ADDRESS_ALLOWED(const BYTE bytes[16])
  144. {
  145. if (SMB_IS_LINKLOCAL(bytes) || SMB_IS_SITELOCAL(bytes) || SMB_IS_LOOPBACK(bytes)) {
  146. return TRUE;
  147. }
  148. return FALSE;
  149. }
  150. #endif