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.

113 lines
1.8 KiB

  1. #include "precomp.h"
  2. DWORD
  3. VerifyPortsForProtocol(
  4. PORT Port,
  5. PROTOCOL Protocol
  6. )
  7. {
  8. DWORD dwError = 0;
  9. switch (Port.PortType) {
  10. case PORT_UNIQUE:
  11. if (Port.wPort < 0) {
  12. dwError = ERROR_INVALID_PARAMETER;
  13. BAIL_ON_WIN32_ERROR(dwError);
  14. }
  15. switch (Protocol.ProtocolType) {
  16. case PROTOCOL_UNIQUE:
  17. if ((Protocol.dwProtocol != TCP_PROTOCOL) &&
  18. (Protocol.dwProtocol != UDP_PROTOCOL)) {
  19. if (Port.wPort != 0) {
  20. dwError = ERROR_INVALID_PARAMETER;
  21. BAIL_ON_WIN32_ERROR(dwError);
  22. }
  23. }
  24. break;
  25. default:
  26. dwError = ERROR_INVALID_PARAMETER;
  27. BAIL_ON_WIN32_ERROR(dwError);
  28. break;
  29. }
  30. break;
  31. default:
  32. dwError = ERROR_INVALID_PARAMETER;
  33. BAIL_ON_WIN32_ERROR(dwError);
  34. break;
  35. }
  36. error:
  37. return (dwError);
  38. }
  39. BOOL
  40. EqualPorts(
  41. IN PORT OldPort,
  42. IN PORT NewPort
  43. )
  44. {
  45. BOOL bMatches = FALSE;
  46. if (OldPort.PortType == NewPort.PortType) {
  47. switch(OldPort.PortType) {
  48. case PORT_UNIQUE:
  49. if (OldPort.wPort == NewPort.wPort) {
  50. bMatches = TRUE;
  51. }
  52. break;
  53. }
  54. }
  55. return (bMatches);
  56. }
  57. VOID
  58. CopyPorts(
  59. IN PORT InPort,
  60. OUT PPORT pOutPort
  61. )
  62. {
  63. memcpy(
  64. pOutPort,
  65. &InPort,
  66. sizeof(PORT)
  67. );
  68. }
  69. BOOL
  70. MatchPorts(
  71. PORT PortToMatch,
  72. PORT PortTemplate
  73. )
  74. {
  75. switch (PortTemplate.PortType) {
  76. case PORT_UNIQUE:
  77. if (PortToMatch.wPort) {
  78. if (PortToMatch.wPort != PortTemplate.wPort) {
  79. return (FALSE);
  80. }
  81. }
  82. break;
  83. }
  84. return (TRUE);
  85. }