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.

159 lines
3.1 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. routing\ip\rtrmgr\compare.c
  5. Abstract:
  6. File contains the following functions
  7. PortCmp
  8. Cmp
  9. InetCmp
  10. UdpCmp
  11. TcpCmp
  12. IpNetCmp
  13. All these functions behave like strcmp. They return >0 if first argument is greater
  14. than the second, <0 if the second is greater than the first and 0 if they are equal
  15. These functions should be revised to make them more effecient
  16. Revision History:
  17. Amritansh Raghav 6/8/95 Created
  18. Amritansh Raghav 10/18/95 The functions now return >0,0,<0 instead of +1,0,-1
  19. --*/
  20. #include "allinc.h"
  21. #include "winsock2.h"
  22. LONG
  23. UdpCmp(
  24. DWORD dwAddr1,
  25. DWORD dwPort1,
  26. DWORD dwAddr2,
  27. DWORD dwPort2
  28. )
  29. {
  30. LONG lResult;
  31. if(InetCmp(dwAddr1,dwAddr2,lResult))
  32. {
  33. return lResult;
  34. }
  35. else
  36. {
  37. return PortCmp(dwPort1,dwPort2,lResult);
  38. }
  39. }
  40. LONG
  41. TcpCmp(
  42. DWORD dwLocalAddr1,
  43. DWORD dwLocalPort1,
  44. DWORD dwRemAddr1,
  45. DWORD dwRemPort1,
  46. DWORD dwLocalAddr2,
  47. DWORD dwLocalPort2,
  48. DWORD dwRemAddr2,
  49. DWORD dwRemPort2
  50. )
  51. {
  52. LONG lResult;
  53. if(InetCmp(dwLocalAddr1,dwLocalAddr2,lResult) isnot 0)
  54. {
  55. return lResult;
  56. }
  57. else
  58. {
  59. if(PortCmp(dwLocalPort1,dwLocalPort2,lResult) isnot 0)
  60. {
  61. return lResult;
  62. }
  63. else
  64. {
  65. if(InetCmp(dwRemAddr1,dwRemAddr2,lResult) isnot 0)
  66. {
  67. return lResult;
  68. }
  69. else
  70. {
  71. return PortCmp(dwRemPort1,dwRemPort2,lResult);
  72. }
  73. }
  74. }
  75. }
  76. LONG
  77. IpNetCmp(
  78. DWORD dwIfIndex1,
  79. DWORD dwAddr1,
  80. DWORD dwIfIndex2,
  81. DWORD dwAddr2
  82. )
  83. {
  84. LONG lResult;
  85. //
  86. // Index is a simple DWORD, not a port
  87. //
  88. if(dwIfIndex1 != dwIfIndex2)
  89. {
  90. if(dwIfIndex1 < dwIfIndex2)
  91. {
  92. return -1;
  93. }
  94. else
  95. {
  96. return 1;
  97. }
  98. }
  99. else
  100. {
  101. return InetCmp(dwAddr1,dwAddr2,lResult);
  102. }
  103. }
  104. LONG
  105. IpForwardCmp(
  106. DWORD dwIpDest1,
  107. DWORD dwProto1,
  108. DWORD dwPolicy1,
  109. DWORD dwIpNextHop1,
  110. DWORD dwIpDest2,
  111. DWORD dwProto2,
  112. DWORD dwPolicy2,
  113. DWORD dwIpNextHop2
  114. )
  115. {
  116. LONG lResult;
  117. if(InetCmp(dwIpDest1,dwIpDest2,lResult) isnot 0)
  118. {
  119. return lResult;
  120. }
  121. else
  122. {
  123. if(Cmp(dwProto1,dwProto2,lResult) isnot 0)
  124. {
  125. return lResult;
  126. }
  127. else
  128. {
  129. if(Cmp(dwPolicy1,dwPolicy2,lResult) isnot 0)
  130. {
  131. return lResult;
  132. }
  133. else
  134. {
  135. return InetCmp(dwIpNextHop1,dwIpNextHop2,lResult);
  136. }
  137. }
  138. }
  139. }