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.

181 lines
3.6 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. MODULE NAME
  4. winsock.c
  5. ABSTRACT
  6. This module contains support for the Winsock2
  7. Autodial callout.
  8. AUTHOR
  9. Anthony Discolo (adiscolo) 15-May-1996
  10. REVISION HISTORY
  11. --*/
  12. #define UNICODE
  13. #define _UNICODE
  14. #include <nt.h>
  15. #include <ntrtl.h>
  16. #include <nturtl.h>
  17. #include <stdlib.h>
  18. #include <windows.h>
  19. #include <acd.h>
  20. #include <debug.h>
  21. #include <winsock2.h>
  22. #include <svcguid.h>
  23. #include <wsipx.h>
  24. #include <wsnetbs.h>
  25. #include "autodial.h"
  26. #define GuidEqual(g1, g2) RtlEqualMemory((g1), (g2), sizeof (GUID))
  27. //
  28. // GUIDs we know about.
  29. //
  30. GUID HostnameGuid = SVCID_INET_HOSTADDRBYNAME;
  31. GUID AddressGuid = SVCID_INET_HOSTADDRBYINETSTRING;
  32. BOOL
  33. WSAttemptAutodialAddr(
  34. IN const struct sockaddr FAR *name,
  35. IN int namelen
  36. )
  37. {
  38. struct sockaddr_in *sin;
  39. struct sockaddr_ipx *sipx;
  40. struct sockaddr_nb *snb;
  41. ACD_ADDR addr;
  42. RtlZeroMemory(&addr, sizeof(ACD_ADDR));
  43. //
  44. // We only know about a few address families.
  45. //
  46. switch (name->sa_family) {
  47. case AF_INET:
  48. sin = (struct sockaddr_in *)name;
  49. addr.fType = ACD_ADDR_IP;
  50. addr.ulIpaddr = sin->sin_addr.s_addr;
  51. break;
  52. case AF_IPX:
  53. sipx = (struct sockaddr_ipx *)name;
  54. return FALSE;
  55. break;
  56. case AF_NETBIOS:
  57. snb = (struct sockaddr_nb *)name;
  58. addr.fType = ACD_ADDR_NB;
  59. RtlCopyMemory(&addr.cNetbios, snb->snb_name, NETBIOS_NAME_LENGTH);
  60. break;
  61. default:
  62. return FALSE;
  63. }
  64. return AcsHlpAttemptConnection(&addr);
  65. } // WSAttemptAutodialAddr
  66. BOOL
  67. WSAttemptAutodialName(
  68. IN const LPWSAQUERYSETW lpqsRestrictions
  69. )
  70. {
  71. ACD_ADDR addr;
  72. RtlZeroMemory(&addr, sizeof(ACD_ADDR));
  73. //
  74. // If there is no address, then
  75. // we're done.
  76. //
  77. if (lpqsRestrictions->lpszServiceInstanceName == NULL)
  78. return FALSE;
  79. if (GuidEqual(lpqsRestrictions->lpServiceClassId, &HostnameGuid)) {
  80. //
  81. // This is a hostname.
  82. //
  83. addr.fType = ACD_ADDR_INET;
  84. if (!WideCharToMultiByte(
  85. CP_ACP,
  86. 0,
  87. lpqsRestrictions->lpszServiceInstanceName,
  88. -1,
  89. addr.szInet,
  90. ACD_ADDR_INET_LEN - 1,
  91. 0,
  92. 0))
  93. {
  94. return FALSE;
  95. }
  96. return AcsHlpAttemptConnection(&addr);
  97. }
  98. else if (GuidEqual(lpqsRestrictions->lpServiceClassId, &AddressGuid)) {
  99. CHAR szIpAddress[17];
  100. //
  101. // This is an IP address.
  102. //
  103. addr.fType = ACD_ADDR_IP;
  104. if (!WideCharToMultiByte(
  105. CP_ACP,
  106. 0,
  107. lpqsRestrictions->lpszServiceInstanceName,
  108. -1,
  109. szIpAddress,
  110. sizeof (szIpAddress) - 1,
  111. 0,
  112. 0))
  113. {
  114. return FALSE;
  115. }
  116. _strlwr(szIpAddress);
  117. addr.ulIpaddr = inet_addr(szIpAddress);
  118. if (addr.ulIpaddr == INADDR_NONE)
  119. return FALSE;
  120. return AcsHlpAttemptConnection(&addr);
  121. }
  122. return FALSE;
  123. } // WSAttemptAutodialName
  124. VOID
  125. WSNoteSuccessfulHostentLookup(
  126. IN const char FAR *name,
  127. IN const ULONG ipaddr
  128. )
  129. {
  130. ACD_ADDR addr;
  131. ACD_ADAPTER adapter;
  132. //
  133. // If there is no address, then
  134. // we're done.
  135. //
  136. if (name == NULL || !strlen(name))
  137. return;
  138. addr.fType = ACD_ADDR_INET;
  139. strcpy((PCHAR)&addr.szInet, name);
  140. adapter.fType = ACD_ADAPTER_IP;
  141. adapter.ulIpaddr = ipaddr;
  142. AcsHlpNoteNewConnection(&addr, &adapter);
  143. } // WSNoteSuccessfulHostentLookup