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
3.6 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 <rpc.h>
  11. #include <rpcdce.h>
  12. #include "..\setup.h"
  13. #define BUFFSIZE 3000
  14. char HexCharToDec(char cChar)
  15. {
  16. if(cChar >= '0' && cChar <= '9')
  17. return cChar - '0';
  18. else
  19. if(cChar >= 'a' && cChar <= 'f')
  20. return cChar - 'a' + 10;
  21. else
  22. if(cChar >= 'A' && cChar <= 'F')
  23. return cChar - 'A' + 10;
  24. else
  25. return -1;
  26. }
  27. int HexFillMem(LPVOID lpAddr, LPSTR lpszString)
  28. {
  29. BOOL bHexString = TRUE;
  30. UINT uIdx;
  31. u_char *lpChar = (u_char *)lpAddr;
  32. if(1 == strlen(lpszString)%2)
  33. bHexString = FALSE;
  34. else
  35. for (uIdx = 0; uIdx < strlen(lpszString); uIdx++)
  36. if(!(lpszString[uIdx] >= '0' && lpszString[uIdx] <= '9' ||
  37. lpszString[uIdx] >= 'a' && lpszString[uIdx] <= 'f' ||
  38. lpszString[uIdx] >= 'A' && lpszString[uIdx] <= 'F'))
  39. bHexString = FALSE;
  40. if(!bHexString)
  41. return -1;
  42. for(uIdx = 0; uIdx < strlen(lpszString)/2; uIdx++)
  43. *(lpChar + uIdx) = 16*HexCharToDec(lpszString[2*uIdx])+HexCharToDec(lpszString[2*uIdx+1]);
  44. return 0;
  45. }
  46. _cdecl
  47. main(int argc, char **argv)
  48. {
  49. DWORD dwAddrSize = BUFFSIZE;
  50. WCHAR AddressString[BUFFSIZE];
  51. DWORD ret;
  52. WSADATA wsaData;
  53. SOCKADDR_IN SockAddrTCP;
  54. SOCKADDR_IPX SockAddrIPX;
  55. WSAPROTOCOL_INFO wsaProtocolInfoTCP[5];
  56. WSAPROTOCOL_INFO wsaProtocolInfoIPX[5];
  57. int Result;
  58. int rgProtocol[2];
  59. DWORD dwBufLen;
  60. LPWSAPROTOCOL_INFO lpProtInf = NULL;
  61. WSAStartup( MAKEWORD(2, 0), &wsaData );
  62. rgProtocol[1] = 0;
  63. SockAddrTCP.sin_family = AF_INET;
  64. SockAddrTCP.sin_port = 80;
  65. SockAddrTCP.sin_addr.s_addr = inet_addr("157.55.80.37");
  66. rgProtocol[0] = IPPROTO_TCP;
  67. dwBufLen = 5*sizeof( WSAPROTOCOL_INFO );
  68. Result = WSAEnumProtocols( rgProtocol,
  69. wsaProtocolInfoTCP,
  70. &dwBufLen);
  71. if ( Result != SOCKET_ERROR )
  72. lpProtInf = wsaProtocolInfoTCP;
  73. else
  74. {
  75. printf( "WSAEnumProtocols failed 0x%.8x", WSAGetLastError() );
  76. }
  77. ret = WSAAddressToString( &SockAddrTCP,
  78. sizeof( SOCKADDR_IN ),
  79. NULL,
  80. AddressString,
  81. &dwAddrSize );
  82. if ( ret )
  83. {
  84. printf("Error: WSAAddressToString returned 0x%X\n", ret );
  85. printf(" GetLastError returned 0x%X\n", GetLastError() );
  86. }
  87. else
  88. {
  89. printf( "WSAAddressToString returned <%S>\n", AddressString );
  90. }
  91. SockAddrIPX.sa_family = AF_IPX;
  92. HexFillMem( SockAddrIPX.sa_netnum, "00002602" );
  93. HexFillMem( SockAddrIPX.sa_nodenum, "00a0c95ec894" );
  94. SockAddrIPX.sa_socket = 80;
  95. ret = WSAAddressToString( &SockAddrIPX,
  96. sizeof( SOCKADDR_IPX ),
  97. NULL,
  98. AddressString,
  99. &dwAddrSize );
  100. if ( ret )
  101. {
  102. printf("Error: WSAAddressToString returned 0x%X\n", ret );
  103. printf(" GetLastError returned 0x%X\n", GetLastError() );
  104. }
  105. else
  106. {
  107. printf( "WSAAddressToString returned <%S>\n", AddressString );
  108. }
  109. WSACleanup();
  110. return(0);
  111. }