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.

134 lines
4.7 KiB

  1. // -*- mode: C++; tab-width: 4; indent-tabs-mode: nil -*- (for GNU Emacs)
  2. //
  3. // Copyright (c) 1985-2000 Microsoft Corporation
  4. //
  5. // This file is part of the Microsoft Research IPv6 Network Protocol Stack.
  6. // You should have received a copy of the Microsoft End-User License Agreement
  7. // for this software along with this release; see the file "license.txt".
  8. // If not, please see http://www.research.microsoft.com/msripv6/license.htm,
  9. // or write to Microsoft Research, One Microsoft Way, Redmond, WA 98052-6399.
  10. //
  11. // Abstract:
  12. //
  13. // Common transport layer code. This file contains code for routines
  14. // that are common to both TCP and UDP.
  15. //
  16. #include "oscfg.h"
  17. #include "ndis.h"
  18. #include "tdi.h"
  19. #include "tdistat.h"
  20. #include "tdikrnl.h"
  21. #include "ip6imp.h"
  22. #include "transprt.h"
  23. #define NO_TCP_DEFS 1
  24. #include "tcpdeb.h"
  25. //* BuildTDIAddress - Build a TDI address structure.
  26. //
  27. // Called when we need to build a TDI address structure. We fill in
  28. // the specifed buffer with the correct information in the correct
  29. // format.
  30. //
  31. void // Returns: Nothing.
  32. BuildTDIAddress(
  33. uchar *Buffer, // Buffer to fill in as TDI address structure.
  34. IPv6Addr *Addr, // IP address to fill in.
  35. ulong ScopeId, // Scope id to fill in.
  36. ushort Port) // Port to fill in.
  37. {
  38. PTRANSPORT_ADDRESS XportAddr;
  39. PTA_ADDRESS TAAddr;
  40. XportAddr = (PTRANSPORT_ADDRESS)Buffer;
  41. XportAddr->TAAddressCount = 1;
  42. TAAddr = XportAddr->Address;
  43. TAAddr->AddressType = TDI_ADDRESS_TYPE_IP6;
  44. TAAddr->AddressLength = sizeof(TDI_ADDRESS_IP6);
  45. ((PTDI_ADDRESS_IP6)TAAddr->Address)->sin6_port = Port;
  46. ((PTDI_ADDRESS_IP6)TAAddr->Address)->sin6_scope_id = ScopeId;
  47. RtlCopyMemory(((PTDI_ADDRESS_IP6)TAAddr->Address)->sin6_addr, Addr,
  48. sizeof(IPv6Addr));
  49. }
  50. //* UpdateConnInfo - Update a connection information structure.
  51. //
  52. // Called when we need to update a connection information structure. We
  53. // copy any options, and create a transport address. If any buffer is
  54. // too small we return an error.
  55. //
  56. TDI_STATUS // Returns: TDI_SUCCESS if ok, TDI_BUFFER_OVERFLOW for an error.
  57. UpdateConnInfo(
  58. PTDI_CONNECTION_INFORMATION ConnInfo, // Structure to fill in.
  59. IPv6Addr *SrcAddress, // Source IP address.
  60. ulong SrcScopeId, // Scope id for address.
  61. ushort SrcPort) // Source port.
  62. {
  63. TDI_STATUS Status = TDI_SUCCESS; // Default status to return.
  64. uint AddrLength;
  65. if (ConnInfo != NULL) {
  66. ConnInfo->UserDataLength = 0; // No user data.
  67. #if 0
  68. // Fill in the options. If the provided buffer is too small,
  69. // we'll truncate the options and return an error. Otherwise
  70. // we'll copy the whole IP option buffer.
  71. if (ConnInfo->OptionsLength) {
  72. if (ConnInfo->OptionsLength < OptInfo->ioi_optlength) {
  73. Status = TDI_BUFFER_OVERFLOW;
  74. OptLength = ConnInfo->OptionsLength;
  75. } else
  76. OptLength = OptInfo->ioi_optlength;
  77. RtlCopyMemory(ConnInfo->Options, OptInfo->ioi_options, OptLength);
  78. ConnInfo->OptionsLength = OptLength;
  79. }
  80. #endif
  81. // Options are copied. Build a TRANSPORT_ADDRESS structure in
  82. // the buffer.
  83. if ((AddrLength = ConnInfo->RemoteAddressLength) != 0) {
  84. // Make sure we have at least enough to fill in the count and type.
  85. if (AddrLength >= TCP_TA_SIZE) {
  86. // The address fits. Fill it in.
  87. ConnInfo->RemoteAddressLength = TCP_TA_SIZE;
  88. BuildTDIAddress(ConnInfo->RemoteAddress, SrcAddress,
  89. SrcScopeId, SrcPort);
  90. } else {
  91. ConnInfo->RemoteAddressLength = 0;
  92. Status = TDI_INVALID_PARAMETER;
  93. }
  94. }
  95. }
  96. return Status;
  97. }
  98. //* SystemUpTime - get time since system boot in milliseconds.
  99. //
  100. // Get our system uptime in ticks and then convert it into milliseconds.
  101. // This resolution is small enough for most purposes and big enough for
  102. // a reasonable length of time (48 days) to fit into a 32-bit word.
  103. // For fast timestamps, however, it is best to use tick counts directly.
  104. //
  105. // REVIEW: rework transports to use a more directly available time unit?
  106. //
  107. unsigned long // Returns: Low order 32-bits worth of time since boot in ms.
  108. SystemUpTime(
  109. void)
  110. {
  111. LARGE_INTEGER TickCount;
  112. KeQueryTickCount(&TickCount); // In ticks.
  113. TickCount.QuadPart *= KeQueryTimeIncrement(); // In 100-ns units.
  114. TickCount.QuadPart /= 10000; // In milliseconds.
  115. return(TickCount.LowPart);
  116. }