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.

321 lines
7.7 KiB

  1. /*++
  2. Copyright (c) 1998 Microsoft Corporation
  3. Module Name:
  4. iphlpapi\namemap.c
  5. Abstract:
  6. Contains all the functions for mapping an interface name to
  7. a friendly name
  8. Revision History:
  9. AmritanR Created
  10. --*/
  11. #include "inc.h"
  12. DWORD
  13. InitNameMappers(
  14. VOID
  15. )
  16. {
  17. DWORD dwResult, i;
  18. //
  19. // For now all we need are the mappers for LAN, RRAS, and IP in IP
  20. //
  21. TempTable[0].hDll = NULL;
  22. TempTable[0].pfnInit = InitLanNameMapper;
  23. TempTable[0].pfnDeinit = DeinitLanNameMapper;
  24. TempTable[0].pfnMapGuid = NhiGetLanConnectionNameFromGuid;
  25. TempTable[0].pfnMapName = NhiGetGuidFromLanConnectionName;
  26. TempTable[0].pfnGetDescription = NhiGetLanConnectionDescriptionFromGuid;
  27. TempTable[1].hDll = NULL;
  28. TempTable[1].pfnInit = InitRasNameMapper;
  29. TempTable[1].pfnDeinit = DeinitRasNameMapper;
  30. TempTable[1].pfnMapGuid = NhiGetPhonebookNameFromGuid;
  31. TempTable[1].pfnMapName = NhiGetGuidFromPhonebookName;
  32. TempTable[1].pfnGetDescription = NhiGetPhonebookDescriptionFromGuid;
  33. #ifdef KSL_IPINIP
  34. TempTable[2].hDll = NULL;
  35. TempTable[2].pfnInit = InitIpIpNameMapper;
  36. TempTable[2].pfnDeinit = DeinitIpIpNameMapper;
  37. TempTable[2].pfnMapGuid = NhiGetIpIpNameFromGuid;
  38. TempTable[2].pfnMapName = NhiGetGuidFromIpIpName;
  39. TempTable[2].pfnGetDescription = NhiGetIpIpDescriptionFromGuid;
  40. #endif //KSL_IPINIP
  41. g_pNameMapperTable = TempTable;
  42. g_ulNumNameMappers = sizeof(TempTable)/sizeof(NH_NAME_MAPPER);
  43. for(i = 0; i < g_ulNumNameMappers; i++)
  44. {
  45. if(g_pNameMapperTable[i].pfnInit)
  46. {
  47. dwResult = (g_pNameMapperTable[i].pfnInit)();
  48. ASSERT(dwResult == NO_ERROR);
  49. }
  50. }
  51. return NO_ERROR;
  52. }
  53. VOID
  54. DeinitNameMappers(
  55. VOID
  56. )
  57. {
  58. ULONG i;
  59. for(i = 0; i < g_ulNumNameMappers; i++)
  60. {
  61. if(g_pNameMapperTable[i].pfnDeinit)
  62. {
  63. (g_pNameMapperTable[i].pfnDeinit)();
  64. }
  65. }
  66. g_ulNumNameMappers = 0;
  67. g_pNameMapperTable = NULL;
  68. }
  69. DWORD
  70. NhGetInterfaceNameFromDeviceGuid(
  71. IN GUID *pGuid,
  72. OUT PWCHAR pwszBuffer,
  73. IN OUT PULONG pulBufferSize,
  74. IN BOOL bCache,
  75. IN BOOL bRefresh
  76. )
  77. {
  78. DWORD dwResult, i, dwCount;
  79. PIP_INTERFACE_NAME_INFO pTable;
  80. //
  81. // Obtain a table of interface information,
  82. // map the device GUID to an interface GUID,
  83. // and invoke the interface-name query routine.
  84. //
  85. dwResult = NhpAllocateAndGetInterfaceInfoFromStack(&pTable,
  86. &dwCount,
  87. TRUE,
  88. GetProcessHeap(),
  89. 0);
  90. if (dwResult != NO_ERROR)
  91. {
  92. return dwResult;
  93. }
  94. dwResult = ERROR_NOT_FOUND;
  95. for (i = 0; i < dwCount; i++)
  96. {
  97. if (IsEqualGUID(&pTable[i].DeviceGuid, pGuid))
  98. {
  99. if (IsEqualGUID(&pTable[i].InterfaceGuid, &GUID_NULL))
  100. {
  101. pGuid = &pTable[i].DeviceGuid;
  102. }
  103. else
  104. {
  105. pGuid = &pTable[i].InterfaceGuid;
  106. }
  107. dwResult = NhGetInterfaceNameFromGuid(pGuid,
  108. pwszBuffer,
  109. pulBufferSize,
  110. bCache,
  111. bRefresh);
  112. break;
  113. }
  114. }
  115. HeapFree(GetProcessHeap(), 0, pTable);
  116. return dwResult;
  117. }
  118. DWORD
  119. NhGetInterfaceNameFromGuid(
  120. IN GUID *pGuid,
  121. OUT PWCHAR pwszBuffer,
  122. IN OUT PDWORD pdwBufferSize,
  123. IN BOOL bCache,
  124. IN BOOL bRefresh
  125. )
  126. {
  127. DWORD dwResult = ERROR_NOT_FOUND, i;
  128. //
  129. // Make sure that there is a buffer and its size is enough
  130. //
  131. for (;;)
  132. {
  133. //
  134. // Call the helpers
  135. //
  136. for(i = 0; i < g_ulNumNameMappers; i++)
  137. {
  138. dwResult = g_pNameMapperTable[i].pfnMapGuid(pGuid,
  139. pwszBuffer,
  140. pdwBufferSize,
  141. bRefresh,
  142. bCache);
  143. if((dwResult is NO_ERROR) || (dwResult is ERROR_INSUFFICIENT_BUFFER))
  144. {
  145. break;
  146. }
  147. }
  148. if((dwResult is NO_ERROR) || (dwResult is ERROR_INSUFFICIENT_BUFFER))
  149. {
  150. break;
  151. }
  152. //
  153. // So didnt match any - do the same thing again, but this time with
  154. // force a cache refresh
  155. //
  156. if(bRefresh)
  157. {
  158. break;
  159. }
  160. else
  161. {
  162. bRefresh = TRUE;
  163. }
  164. }
  165. return dwResult;
  166. }
  167. DWORD
  168. NhGetGuidFromInterfaceName(
  169. IN PWCHAR pwszBuffer,
  170. OUT GUID *pGuid,
  171. IN BOOL bCache,
  172. IN BOOL bRefresh
  173. )
  174. {
  175. DWORD dwResult = ERROR_NOT_FOUND, i;
  176. //
  177. // Make sure that there is a buffer and its size is enough
  178. //
  179. for (;;)
  180. {
  181. //
  182. // Call the helpers
  183. //
  184. for(i = 0; i < g_ulNumNameMappers; i++)
  185. {
  186. dwResult = g_pNameMapperTable[i].pfnMapName(pwszBuffer,
  187. pGuid,
  188. bRefresh,
  189. bCache);
  190. if(dwResult is NO_ERROR)
  191. {
  192. break;
  193. }
  194. }
  195. if(dwResult is NO_ERROR)
  196. {
  197. break;
  198. }
  199. //
  200. // So didnt match any - do the same thing again, but this time with
  201. // force a cache refresh
  202. //
  203. if(bRefresh)
  204. {
  205. break;
  206. }
  207. else
  208. {
  209. bRefresh = TRUE;
  210. }
  211. }
  212. return dwResult;
  213. }
  214. DWORD
  215. NhGetInterfaceDescriptionFromGuid(
  216. IN GUID *pGuid,
  217. OUT PWCHAR pwszBuffer,
  218. IN OUT PULONG pulBufferSize,
  219. IN BOOL bCache,
  220. IN BOOL bRefresh
  221. )
  222. {
  223. DWORD dwResult = ERROR_NOT_FOUND, i;
  224. //
  225. // Make sure that there is a buffer and its size is enough
  226. //
  227. for (;;)
  228. {
  229. //
  230. // Call the helpers
  231. //
  232. for(i = 0; i < g_ulNumNameMappers; i++)
  233. {
  234. dwResult = g_pNameMapperTable[i].pfnGetDescription(pGuid,
  235. pwszBuffer,
  236. pulBufferSize,
  237. bRefresh,
  238. bCache);
  239. if(dwResult is NO_ERROR)
  240. {
  241. break;
  242. }
  243. }
  244. if(dwResult is NO_ERROR)
  245. {
  246. break;
  247. }
  248. //
  249. // So didnt match any - do the same thing again, but this time with
  250. // force a cache refresh
  251. //
  252. if(bRefresh)
  253. {
  254. break;
  255. }
  256. else
  257. {
  258. bRefresh = TRUE;
  259. }
  260. }
  261. return dwResult;
  262. }