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.

141 lines
2.7 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. udp.c
  5. Abstract:
  6. Boot loader UDP routines.
  7. Author:
  8. Chuck Lenzmeier (chuckl) December 27, 1996
  9. Revision History:
  10. Notes:
  11. --*/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. ULONG UdpNextPort = 0;
  15. USHORT UdpUnicastDestinationPort;
  16. #if 0
  17. USHORT UdpMulticastDestinationPort;
  18. ULONG UdpMulticastDestinationAddress;
  19. USHORT UdpMulticastSourcePort;
  20. ULONG UdpMulticastSourceAddress;
  21. #endif
  22. USHORT
  23. UdpAssignUnicastPort (
  24. VOID
  25. )
  26. {
  27. if ( UdpNextPort == 0 ) {
  28. UdpNextPort = (ArcGetRelativeTime() & 0x7fff) | 0x8000;
  29. } else if ( ++UdpNextPort > 0xffff ) {
  30. UdpNextPort = 0x8000;
  31. }
  32. UdpUnicastDestinationPort = SWAP_WORD( UdpNextPort );
  33. #if 0
  34. UdpMulticastDestinationPort = 0;
  35. #endif
  36. RomSetReceiveStatus(
  37. UdpUnicastDestinationPort
  38. #if 0
  39. ,
  40. UdpMulticastDestinationPort,
  41. UdpMulticastDestinationAddress,
  42. UdpMulticastSourcePort,
  43. UdpMulticastSourceAddress
  44. #endif
  45. );
  46. return (USHORT)UdpUnicastDestinationPort;
  47. } // UdpAssignUnicastPort
  48. #if 0
  49. VOID
  50. UdpSetMulticastPort (
  51. IN USHORT DestinationPort,
  52. IN ULONG DestinationAddress,
  53. IN USHORT SourcePort,
  54. IN ULONG SourceAddress
  55. )
  56. {
  57. UdpMulticastDestinationPort = DestinationPort;
  58. UdpMulticastDestinationAddress = DestinationAddress;
  59. UdpMulticastSourcePort = SourcePort;
  60. UdpMulticastSourceAddress = SourceAddress;
  61. RomSetReceiveStatus(
  62. UdpUnicastDestinationPort,
  63. UdpMulticastDestinationPort,
  64. UdpMulticastDestinationAddress,
  65. UdpMulticastSourcePort,
  66. UdpMulticastSourceAddress
  67. );
  68. return;
  69. } // UdpSetMulticastPort
  70. #endif
  71. ULONG
  72. UdpReceive (
  73. IN PVOID Buffer,
  74. IN ULONG BufferLength,
  75. OUT PULONG RemoteHost,
  76. OUT PUSHORT RemotePort,
  77. IN ULONG Timeout
  78. )
  79. //
  80. // Read in packet from the specified socket. The host and port
  81. // the packet comes from is filled in fhost and fport.
  82. // The data is put in buffer buf, which should have size len. If no packet
  83. // arrives in tmo seconds, then 0 is returned.
  84. // Otherwise it returns the size of the packet read.
  85. //
  86. {
  87. return RomReceiveUdpPacket( Buffer, BufferLength, Timeout, RemoteHost, RemotePort );
  88. } // UdpReceive
  89. ULONG
  90. UdpSend (
  91. IN PVOID Buffer,
  92. IN ULONG BufferLength,
  93. IN ULONG RemoteHost,
  94. IN USHORT RemotePort
  95. )
  96. //
  97. // writes a packet to the specified socket. The host and port the packet
  98. // should go to should be in fhost and fport
  99. // The data should be put in buffer buf, and should have size len.
  100. // It usually returns the number of characters sent, or -1 on failure.
  101. //
  102. {
  103. return RomSendUdpPacket( Buffer, BufferLength, RemoteHost, RemotePort );
  104. } // UdpSend