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.

225 lines
4.8 KiB

  1. #ifndef VXD
  2. #include <nt.h>
  3. #include <ntrtl.h>
  4. #include <nturtl.h>
  5. #include <windef.h>
  6. #include <winbase.h>
  7. #include <netconp.h>
  8. #include <assert.h>
  9. #include <stdio.h>
  10. #include <winsock.h>
  11. #include <wsahelp.h>
  12. #include <nb30.h>
  13. #include <nbtioctl.h>
  14. //#include "../../tcpip/commands/common/tcpcmd.h"
  15. #else
  16. #include "vxdonly.h"
  17. #endif
  18. #define PROTODB_SIZE (_MAX_PATH + 10)
  19. #define SERVDB_SIZE (_MAX_PATH + 10)
  20. #define MAX_FAST_TDI_ADDRESS 32
  21. #define TDI_QUERY_PURGE_CACHE 97
  22. #define TDI_QUERY_CONNECTION_LIST 98
  23. #define TDI_QUERY_CACHE_STATUS 99
  24. #define TDI_DHCP_TEST 133
  25. #define TDI_BCAST_RESOLVED_NAMES 134
  26. #define NETBIOS_NAME_SIZE 16
  27. /*
  28. * Display Modes.
  29. */
  30. #define ADAPTERSTATUS 0x0001
  31. #define ADAPTERSTATUSIP 0x0002
  32. #define BCAST 0x0004
  33. #define CACHE 0x0008
  34. #define CONNECTION 0x0010
  35. #define CONNECTION_ALL 0x0020
  36. #define CONNECTION_WITH_IP 0x0040
  37. #define CONNECTION_WITH_IP_ALL 0x0080
  38. #define DHCP 0x0100
  39. #define NAMES 0x0200
  40. #define NAMES_ALL 0x0400
  41. #define NAME_RELEASE_REFRESH 0x0800 // not really a display mode
  42. #define RESYNC 0x1000 // not really a display mode
  43. //
  44. enum eSTATE
  45. {
  46. NBT_RECONNECTING, // waiting for the worker thread to run NbtConnect
  47. NBT_IDLE, // not Transport connection
  48. NBT_ASSOCIATED, // associated with an address element
  49. NBT_CONNECTING, // establishing Transport connection
  50. NBT_SESSION_INBOUND, // waiting for a session request after tcp connection setup inbound
  51. NBT_SESSION_WAITACCEPT, // waiting for accept after a listen has been satisfied
  52. NBT_SESSION_OUTBOUND, // waiting for a session response after tcp connection setup
  53. NBT_SESSION_UP, // got positive response
  54. NBT_DISCONNECTING, // sent a disconnect down to Tcp, but it hasn't completed yet
  55. NBT_DISCONNECTED // a session has been disconnected but not closed with TCP yet
  56. };
  57. //
  58. // These are other states for connections that are not explicitly used by
  59. // NBT but are returned on the NbtQueryConnectionList call.
  60. //
  61. #define LISTENING 20
  62. #define UNBOUND 21
  63. #if 0
  64. struct {
  65. long TdiError;
  66. NTSTATUS UnixError;
  67. } UnixErrorMap[] = {
  68. {STATUS_INVALID_PARAMETER,EINVAL},
  69. {STATUS_INVALID_NETWORK_RESPONSE,ENETDOWN},
  70. {STATUS_INVALID_NETWORK_RESPONSE,ENODEV},
  71. {STATUS_INVALID_NETWORK_RESPONSE,ENXIO},
  72. {STATUS_NETWORK_BUSY,EBUSY},
  73. {STATUS_INSUFFICIENT_RESOURCES,ENOSR},
  74. {STATUS_ACCESS_DENIED,EACCES},
  75. {STATUS_LINK_FAILED,ECONNRESET},
  76. {STATUS_REMOTE_NOT_LISTENING,ECONNREFUSED},
  77. {STATUS_IO_TIMEOUT,ETIMEDOUT},
  78. {STATUS_BAD_NETWORK_PATH,ENETUNREACH},
  79. {STATUS_BAD_NETWORK_PATH,EHOSTUNREACH},
  80. {0,0}
  81. };
  82. #endif
  83. //
  84. // The format of Adapter Status responses
  85. //
  86. typedef struct
  87. {
  88. ADAPTER_STATUS AdapterInfo;
  89. NAME_BUFFER Names[32];
  90. } tADAPTERSTATUS;
  91. // 1234567890123456
  92. #define SPACES " "
  93. #define ClearNcb( PNCB ) { \
  94. RtlZeroMemory( PNCB , sizeof (NCB) ); \
  95. RtlMoveMemory( (PNCB)->ncb_name, SPACES, sizeof(SPACES)-1 );\
  96. RtlMoveMemory( (PNCB)->ncb_callname, SPACES, sizeof(SPACES)-1 );\
  97. }
  98. //
  99. // the defines that do the right thing
  100. //
  101. NTSTATUS
  102. DeviceIoCtrl(
  103. IN HANDLE fd,
  104. IN PVOID ReturnBuffer,
  105. IN ULONG BufferSize,
  106. IN ULONG Ioctl,
  107. IN PVOID pInput,
  108. IN ULONG SizeInput
  109. );
  110. #define CALL_DRIVER DeviceIoCtrl
  111. //----------------------------------------------------------------------
  112. //
  113. // Function Prototypes
  114. //
  115. typedef struct
  116. {
  117. ADAPTER_STATUS AdapterInfo;
  118. tREMOTE_CACHE Names[32];
  119. } tREMOTE;
  120. NTSTATUS
  121. ReadRegistry(
  122. IN PUCHAR pScope
  123. );
  124. NTSTATUS
  125. GetInterfaceList(
  126. );
  127. HANDLE
  128. OpenNbt(
  129. IN ULONG Index
  130. );
  131. VOID
  132. PrintKorM(
  133. IN PVOID pBytesIn
  134. );
  135. NTSTATUS
  136. GetNames(
  137. IN HANDLE fd,
  138. IN LONG WhichNames
  139. );
  140. NTSTATUS
  141. GetConnections(
  142. IN HANDLE fd,
  143. IN LONG Display
  144. );
  145. NTSTATUS
  146. Resync(
  147. IN HANDLE fd
  148. );
  149. NTSTATUS
  150. ReleaseNamesThenRefresh(
  151. IN HANDLE fd
  152. );
  153. PCHAR
  154. gethost(ULONG addr,
  155. BOOLEAN Convert);
  156. NTSTATUS
  157. GetBcastResolvedNames(
  158. IN HANDLE fd
  159. );
  160. NTSTATUS
  161. Dhcp(
  162. IN HANDLE fd
  163. );
  164. VOID
  165. FormattedDump(
  166. PCHAR far_p,
  167. LONG len
  168. );
  169. VOID
  170. HexDumpLine(
  171. PCHAR pch,
  172. ULONG len,
  173. PCHAR s,
  174. PCHAR t
  175. );
  176. NTSTATUS
  177. AdapterStatus(
  178. IN HANDLE fd,
  179. IN PCHAR RemoteName
  180. );
  181. NTSTATUS
  182. AdapterStatusIpAddr(
  183. IN HANDLE fd,
  184. IN PCHAR RemoteName,
  185. IN LONG Display
  186. );
  187. NTSTATUS
  188. GetIpAddress(
  189. IN HANDLE fd,
  190. OUT PULONG pIpAddress
  191. );