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.

77 lines
1.6 KiB

  1. /*++
  2. Copyright (c) 1989-2001 Microsoft Corporation
  3. Module Name:
  4. testsvc.c
  5. Abstract:
  6. the test driver for testing the functionality of SmbGetHostByName
  7. Author:
  8. Jiandong Ruan
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. VOID
  13. SmbGetHostByName(
  14. PSMB_DNS_BUFFER dns
  15. );
  16. void _cdecl main(void)
  17. {
  18. LPWSTR CommandLine;
  19. WSADATA WsaData;
  20. int Argc;
  21. LPWSTR *Argv;
  22. HANDLE handle;
  23. SMB_DNS_BUFFER dns;
  24. CHAR Buffer[40];
  25. setlocale(LC_ALL, "");
  26. SmbSetTraceRoutine(printf);
  27. CommandLine = GetCommandLineW();
  28. if (NULL == CommandLine) {
  29. exit (1);
  30. }
  31. Argv = CommandLineToArgvW(CommandLine, &Argc);
  32. if (Argc < 2) {
  33. printf ("Usage %ws name\n", Argv[0]);
  34. exit (1);
  35. }
  36. if (WSAStartup(MAKEWORD(2, 0), &WsaData) == SOCKET_ERROR) {
  37. printf ("Failed to startup Winsock2\n");
  38. exit (1);
  39. }
  40. dns.Id = 1;
  41. wcscpy(dns.Name, Argv[1]);
  42. dns.NameLen = wcslen(Argv[1]) + 1;
  43. dns.Name[dns.NameLen - 1] = L'\0';
  44. SmbGetHostByName(&dns);
  45. if (dns.Resolved) {
  46. printf ("Canon Name: %ws\n", dns.Name);
  47. if (dns.IpAddrsList[0].sin_family == SMB_AF_INET6) {
  48. if (inet_ntoa6(Buffer, 40, &dns.IpAddrsList[0].ip6)) {
  49. printf ("\tIP6 Addr: %s\n", Buffer);
  50. } else {
  51. printf ("\tUnexpected failed\n");
  52. }
  53. } else {
  54. printf ("\tIP4 Addr: %s\n", inet_ntoa(*(struct in_addr*)(&dns.IpAddrsList[0].ip4.sin4_addr)));
  55. }
  56. } else {
  57. printf ("Cannot resolve %ws\n", dns.Name);
  58. }
  59. }