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.

183 lines
5.5 KiB

  1. #include <nt.h>
  2. #include <ntrtl.h>
  3. #include <nturtl.h>
  4. #include <windows.h>
  5. #include <winsock2.h>
  6. #include <wsipx.h>
  7. #include <svcguid.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <ws2atm.h>
  11. GUID ATMAType = SVCID_DNS_TYPE_ATMA;
  12. #define BUFFSIZE 3000
  13. _cdecl
  14. main(int argc, char **argv)
  15. {
  16. HANDLE hLib;
  17. WCHAR Buffer[BUFFSIZE];
  18. PWSAQUERYSETW Query = (PWSAQUERYSETW)Buffer;
  19. HANDLE hRnr;
  20. DWORD dwIp;
  21. DWORD dwQuerySize = BUFFSIZE;
  22. WSADATA wsaData;
  23. ANSI_STRING asServiceInstanceName;
  24. UNICODE_STRING usServiceInstanceName;
  25. WCHAR UnicodeStringBuf[1024];
  26. ANSI_STRING asContext;
  27. UNICODE_STRING usContext;
  28. WCHAR UnicodeStringBuf2[1024];
  29. AFPROTOCOLS lpAfpProtocols[1];
  30. usServiceInstanceName.Length = 0;
  31. usServiceInstanceName.MaximumLength = 1024;
  32. usServiceInstanceName.Buffer = UnicodeStringBuf;
  33. usContext.Length = 0;
  34. usContext.MaximumLength = 1024;
  35. usContext.Buffer = UnicodeStringBuf2;
  36. if ( argc != 2 )
  37. {
  38. printf( "\nUsage: rnrtst <Name>\n" );
  39. return( -1 );
  40. }
  41. RtlInitAnsiString( &asServiceInstanceName, argv[1] );
  42. RtlAnsiStringToUnicodeString( &usServiceInstanceName,
  43. &asServiceInstanceName,
  44. FALSE );
  45. WSAStartup(MAKEWORD(1, 1), &wsaData);
  46. memset(Query, 0, sizeof(*Query));
  47. Query->dwSize = sizeof(*Query);
  48. if ( usServiceInstanceName.Buffer[0] != L'*' )
  49. {
  50. Query->lpszServiceInstanceName = usServiceInstanceName.Buffer;
  51. }
  52. Query->lpServiceClassId = &ATMAType;
  53. Query->lpVersion = 0;
  54. Query->dwNameSpace = NS_ALL;
  55. Query->lpNSProviderId = 0;
  56. Query->lpszContext = NULL;
  57. Query->dwNumberOfProtocols = 1;
  58. lpAfpProtocols[0].iAddressFamily = AF_ATM;
  59. lpAfpProtocols[0].iProtocol = PF_ATM;
  60. Query->lpafpProtocols = lpAfpProtocols;
  61. if( WSALookupServiceBegin( Query,
  62. LUP_RETURN_NAME |
  63. LUP_RETURN_TYPE |
  64. LUP_RETURN_VERSION |
  65. LUP_RETURN_COMMENT |
  66. LUP_RETURN_ADDR |
  67. LUP_RETURN_BLOB,
  68. &hRnr ) == SOCKET_ERROR )
  69. {
  70. printf( "LookupBegin failed %d\n", GetLastError() );
  71. }
  72. while ( WSALookupServiceNext( hRnr,
  73. 0,
  74. &dwQuerySize,
  75. Query ) == NO_ERROR )
  76. {
  77. PCSADDR_INFO csaddrInfo;
  78. PSOCKADDR_ATM sockaddrAtm;
  79. printf( "Next got: \n" );
  80. printf( " dwSize = %d\n",
  81. Query->dwSize );
  82. printf( " dwOutputFlags = %d\n",
  83. Query->dwOutputFlags );
  84. printf( " lpszServiceInstanceName = %ws\n",
  85. Query->lpszServiceInstanceName );
  86. if ( Query->lpVersion )
  87. {
  88. printf( " lpVersion->dwVersion = %d\n",
  89. Query->lpVersion->dwVersion );
  90. printf( " lpVersion->ecHow = %d\n",
  91. Query->lpVersion->ecHow );
  92. }
  93. if ( Query->lpszComment )
  94. {
  95. printf( " lpszComment = %ws\n",
  96. Query->lpszComment );
  97. }
  98. printf( " dwNameSpace = %d\n",
  99. Query->dwNameSpace );
  100. if ( Query->lpszContext )
  101. {
  102. printf( " lpszContext = %ws\n",
  103. Query->lpszContext );
  104. }
  105. printf( " dwNumberOfCsAddrs = %d\n",
  106. Query->dwNumberOfCsAddrs );
  107. if ( Query->dwNumberOfCsAddrs )
  108. {
  109. DWORD iter;
  110. csaddrInfo = Query->lpcsaBuffer;
  111. for ( iter = 0; iter < Query->dwNumberOfCsAddrs; iter++ )
  112. {
  113. sockaddrAtm =
  114. (PSOCKADDR_ATM) csaddrInfo->RemoteAddr.lpSockaddr;
  115. printf( " CsAddrInfo[%d]\n", iter );
  116. printf( " iSocketType = %d\n",
  117. csaddrInfo->iSocketType );
  118. printf( " iProtocol = %d\n",
  119. csaddrInfo->iProtocol );
  120. printf( " ATM address (Remote)\n" );
  121. printf( " Address Type = %d\n",
  122. sockaddrAtm->satm_number.AddressType );
  123. printf( " Address Length = %d\n",
  124. sockaddrAtm->satm_number.NumofDigits );
  125. if ( sockaddrAtm->satm_number.AddressType == ATM_E164 )
  126. printf( " Address = %s\n",
  127. sockaddrAtm->satm_number.Addr );
  128. else
  129. {
  130. DWORD jiter;
  131. printf( " Address = " );
  132. for ( jiter = 0; jiter < ATM_ADDR_SIZE; jiter++ )
  133. {
  134. printf( "%02x", sockaddrAtm->satm_number.Addr[jiter] );
  135. }
  136. printf( "\n" );
  137. }
  138. csaddrInfo++;
  139. }
  140. }
  141. }
  142. printf( "Next finished with %d\n", GetLastError() );
  143. if( WSALookupServiceEnd( hRnr ) )
  144. {
  145. printf( "ServiceEnd failed %d\n", GetLastError() );
  146. }
  147. WSACleanup();
  148. return(0);
  149. }