Source code of Windows XP (NT5)
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.

229 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. Abstract:
  5. File contains the following functions
  6. PortCmp
  7. Cmp
  8. InetCmp
  9. UdpCmp
  10. Udp6Cmp
  11. TcpCmp
  12. Tcp6Cmp
  13. IpNetCmp
  14. All these functions behave like strcmp. They return >0 if first argument is greater
  15. than the second, <0 if the second is greater than the first and 0 if they are equal
  16. These functions should be revised to make them more effecient
  17. Revision History:
  18. Amritansh Raghav 6/8/95 Created
  19. Amritansh Raghav 10/18/95 The functions now return >0,0,<0 instead of +1,0,-1
  20. --*/
  21. #include "allinc.h"
  22. LONG
  23. UdpCmp(
  24. DWORD dwAddr1,
  25. DWORD dwPort1,
  26. DWORD dwAddr2,
  27. DWORD dwPort2
  28. )
  29. {
  30. LONG lResult;
  31. // Addrs are in network byte order
  32. if (InetCmp(dwAddr1, dwAddr2, lResult))
  33. {
  34. return lResult;
  35. }
  36. else
  37. {
  38. // Ports are in host byte order
  39. return Cmp(dwPort1, dwPort2, lResult);
  40. }
  41. }
  42. LONG
  43. Udp6Cmp(
  44. BYTE rgbyLocalAddrEx1[20],
  45. DWORD dwLocalPort1,
  46. BYTE rgbyLocalAddrEx2[20],
  47. DWORD dwLocalPort2
  48. )
  49. {
  50. LONG lResult;
  51. // Addr+scopeid is in network byte order. They're together
  52. // in one buffer since that's how the INET-ADDRESS-MIB expresses them.
  53. lResult = memcmp(rgbyLocalAddrEx1, rgbyLocalAddrEx2, 20);
  54. if (lResult isnot 0)
  55. {
  56. return lResult;
  57. }
  58. else
  59. {
  60. // Ports are in host byte order
  61. return Cmp(dwLocalPort1, dwLocalPort2, lResult);
  62. }
  63. }
  64. LONG
  65. TcpCmp(
  66. DWORD dwLocalAddr1,
  67. DWORD dwLocalPort1,
  68. DWORD dwRemAddr1,
  69. DWORD dwRemPort1,
  70. DWORD dwLocalAddr2,
  71. DWORD dwLocalPort2,
  72. DWORD dwRemAddr2,
  73. DWORD dwRemPort2
  74. )
  75. {
  76. LONG lResult;
  77. // Addrs are in network byte order
  78. if (InetCmp(dwLocalAddr1, dwLocalAddr2, lResult) isnot 0)
  79. {
  80. return lResult;
  81. }
  82. else
  83. {
  84. // Ports are in host byte order
  85. if (Cmp(dwLocalPort1, dwLocalPort2, lResult) isnot 0)
  86. {
  87. return lResult;
  88. }
  89. else
  90. {
  91. // Addrs are in network byte order
  92. if (InetCmp(dwRemAddr1, dwRemAddr2, lResult) isnot 0)
  93. {
  94. return lResult;
  95. }
  96. else
  97. {
  98. // Ports are in host byte order
  99. return Cmp(dwRemPort1, dwRemPort2, lResult);
  100. }
  101. }
  102. }
  103. }
  104. LONG
  105. Tcp6Cmp(
  106. BYTE rgbyLocalAddrEx1[20],
  107. DWORD dwLocalPort1,
  108. BYTE rgbyRemAddrEx1[20],
  109. DWORD dwRemPort1,
  110. BYTE rgbyLocalAddrEx2[20],
  111. DWORD dwLocalPort2,
  112. BYTE rgbyRemAddrEx2[20],
  113. DWORD dwRemPort2
  114. )
  115. {
  116. LONG lResult;
  117. // Addr+scopeid is in network byte order. They're together
  118. // in one buffer since that's how the INET-ADDRESS-MIB expresses them.
  119. lResult = memcmp(rgbyLocalAddrEx1, rgbyLocalAddrEx2, 20);
  120. if (lResult isnot 0)
  121. {
  122. return lResult;
  123. }
  124. else
  125. {
  126. // Ports are in host byte order
  127. if (Cmp(dwLocalPort1, dwLocalPort2, lResult) isnot 0)
  128. {
  129. return lResult;
  130. }
  131. else
  132. {
  133. // Addr+scopeid is in network byte order
  134. lResult = memcmp(rgbyRemAddrEx1, rgbyRemAddrEx2, 20);
  135. if (lResult isnot 0)
  136. {
  137. return lResult;
  138. }
  139. else
  140. {
  141. // Ports are in host byte order
  142. return Cmp(dwRemPort1, dwRemPort2, lResult);
  143. }
  144. }
  145. }
  146. }
  147. LONG
  148. IpNetCmp(
  149. DWORD dwIfIndex1,
  150. DWORD dwAddr1,
  151. DWORD dwIfIndex2,
  152. DWORD dwAddr2
  153. )
  154. {
  155. LONG lResult;
  156. // Index is a simple DWORD, not a port
  157. if (Cmp(dwIfIndex1, dwIfIndex2, lResult) isnot 0)
  158. {
  159. return lResult;
  160. }
  161. else
  162. {
  163. // Addrs are in network byte order
  164. return InetCmp(dwAddr1, dwAddr2, lResult);
  165. }
  166. }
  167. LONG
  168. IpForwardCmp(
  169. DWORD dwIpDest1,
  170. DWORD dwProto1,
  171. DWORD dwPolicy1,
  172. DWORD dwIpNextHop1,
  173. DWORD dwIpDest2,
  174. DWORD dwProto2,
  175. DWORD dwPolicy2,
  176. DWORD dwIpNextHop2
  177. )
  178. {
  179. LONG lResult;
  180. // Addrs are in network byte order
  181. if (InetCmp(dwIpDest1, dwIpDest2, lResult) isnot 0)
  182. {
  183. return lResult;
  184. }
  185. else
  186. {
  187. // Proto is a simple DWORD, not a port
  188. if (Cmp(dwProto1, dwProto2, lResult) isnot 0)
  189. {
  190. return lResult;
  191. }
  192. else
  193. {
  194. // Policy is a simple DWORD, not a port
  195. if (Cmp(dwPolicy1, dwPolicy2, lResult) isnot 0)
  196. {
  197. return lResult;
  198. }
  199. else
  200. {
  201. // Addrs are in network byte order
  202. return InetCmp(dwIpNextHop1, dwIpNextHop2, lResult);
  203. }
  204. }
  205. }
  206. }