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.

292 lines
6.6 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. dhcp.c
  5. Abstract:
  6. Functions to get information from VDHCP.VXD
  7. Contents:
  8. (OpenDhcpVxdHandle)
  9. (DhcpVxdRequest)
  10. DhcpReleaseAdapterIpAddress
  11. DhcpRenewAdapterIpAddress
  12. (ReleaseOrRenewAddress)
  13. IsMediaDisconnected
  14. Author:
  15. Richard L Firth (rfirth) 30-Nov-1994
  16. Revision History:
  17. 30-Nov-1994 rfirth
  18. Created
  19. --*/
  20. #include "stdafx.h"
  21. #include "NetConn.h"
  22. #include "w9xdhcp.h"
  23. #include "vxd32.h"
  24. #ifdef __cplusplus
  25. extern "C" {
  26. #endif
  27. //
  28. // Private constants.
  29. //
  30. #define DHCP_IS_MEDIA_DISCONNECTED 5
  31. #define PRIVATE static
  32. //
  33. // private prototypes
  34. //
  35. PRIVATE
  36. DWORD
  37. OpenDhcpVxdHandle(
  38. void
  39. );
  40. PRIVATE
  41. WORD
  42. DhcpVxdRequest(
  43. IN DWORD Handle,
  44. IN WORD Request,
  45. IN WORD BufferLength,
  46. OUT LPVOID Buffer
  47. );
  48. PRIVATE
  49. WORD
  50. ReleaseOrRenewAddress(
  51. UINT Request,
  52. UINT AddressLength,
  53. LPBYTE Address
  54. );
  55. //
  56. // data
  57. //
  58. //
  59. // functions
  60. //
  61. BOOL
  62. IsMediaDisconnected(
  63. IN OUT DWORD iae_context
  64. )
  65. {
  66. DWORD handle;
  67. handle = OpenDhcpVxdHandle();
  68. if( handle ) {
  69. WORD result;
  70. DWORD MediaStatus = iae_context;
  71. result = DhcpVxdRequest( handle,
  72. DHCP_IS_MEDIA_DISCONNECTED,
  73. sizeof(MediaStatus),
  74. &MediaStatus
  75. );
  76. OsCloseVxdHandle( handle );
  77. if( result == 0 && MediaStatus == TRUE ) return TRUE;
  78. }
  79. return FALSE;
  80. }
  81. /*******************************************************************************
  82. *
  83. * OpenDhcpVxdHandle
  84. *
  85. * On Snowball, just retrieves the (real-mode) entry point address to the VxD
  86. *
  87. * ENTRY nothing
  88. *
  89. * EXIT DhcpVxdEntryPoint set
  90. *
  91. * RETURNS DhcpVxdEntryPoint
  92. *
  93. * ASSUMES 1. We are running in V86 mode
  94. *
  95. ******************************************************************************/
  96. PRIVATE DWORD
  97. OpenDhcpVxdHandle()
  98. {
  99. return OsOpenVxdHandle("VDHCP", VDHCP_Device_ID);
  100. }
  101. /*******************************************************************************
  102. *
  103. * DhcpVxdRequest
  104. *
  105. * Makes a DHCP VxD request - passes a function code, parameter buffer and
  106. * length to the (real-mode/V86) VxD entry-point
  107. *
  108. * ENTRY Handle - handle for Win32 call
  109. * Request - DHCP VxD request
  110. * BufferLength - length of Buffer
  111. * Buffer - pointer to request-specific parameters
  112. *
  113. * EXIT depends on request
  114. *
  115. * RETURNS Success - 0
  116. * Failure - ERROR_PATH_NOT_FOUND
  117. * Returned if a specified adapter address could not be
  118. * found
  119. *
  120. * ERROR_BUFFER_OVERFLOW
  121. * Returned if the supplied buffer is too small to contain
  122. * the requested information
  123. *
  124. * ASSUMES
  125. *
  126. ******************************************************************************/
  127. PRIVATE WORD
  128. DhcpVxdRequest(DWORD Handle, WORD Request, WORD BufferLength, LPVOID Buffer)
  129. {
  130. return (WORD) OsSubmitVxdRequest( Handle,
  131. (INT)Request,
  132. (LPVOID)Buffer,
  133. (INT)BufferLength );
  134. }
  135. /*******************************************************************************
  136. *
  137. * DhcpReleaseAdapterIpAddress
  138. *
  139. * Attempts to release the IP address for an adapter
  140. *
  141. * ENTRY AdapterInfo - describing adapter to release address for
  142. *
  143. * EXIT nothing
  144. *
  145. * RETURNS Success - TRUE
  146. * Failure - FALSE
  147. *
  148. ******************************************************************************/
  149. DWORD
  150. DhcpReleaseAdapterIpAddress(PADAPTER_INFO AdapterInfo)
  151. {
  152. WORD result;
  153. result = ReleaseOrRenewAddress(DHCP_RELEASE_IPADDRESS,
  154. AdapterInfo->AddressLength,
  155. AdapterInfo->Address
  156. );
  157. return (DWORD)result;
  158. }
  159. /*******************************************************************************
  160. *
  161. * DhcpRenewAdapterIpAddress
  162. *
  163. * Attempts to renew the IP address for an adapter
  164. *
  165. * ENTRY AdapterInfo - describing adapter to renew address for
  166. *
  167. * EXIT nothing
  168. *
  169. * RETURNS Success - TRUE
  170. * Failure - FALSE
  171. *
  172. * ASSUMES
  173. *
  174. ******************************************************************************/
  175. DWORD
  176. DhcpRenewAdapterIpAddress(PADAPTER_INFO AdapterInfo)
  177. {
  178. WORD result;
  179. result = ReleaseOrRenewAddress(DHCP_RENEW_IPADDRESS,
  180. AdapterInfo->AddressLength,
  181. AdapterInfo->Address
  182. );
  183. return (DWORD)result;
  184. }
  185. /*******************************************************************************
  186. *
  187. * ReleaseOrRenewAddress
  188. *
  189. * Given a physical adapter address and length, renews or releases the IP
  190. * address lease for this adapter
  191. *
  192. * ENTRY Request - DHCP_RELEASE_IPADDRESS or DHCP_RENEW_IPADDRESS
  193. * AddressLength - length of Address
  194. * Address - pointer to byte array which is physical adapter
  195. * address
  196. *
  197. * EXIT nothing
  198. *
  199. * RETURNS Success - ERROR_SUCCESS
  200. * Failure - ERROR_NOT_ENOUGH_MEMORY
  201. * ERROR_FILE_NOT_FOUND
  202. * ERROR_PATH_NOT_FOUND
  203. * ERROR_BUFFER_OVERFLOW
  204. *
  205. * ASSUMES
  206. *
  207. ******************************************************************************/
  208. PRIVATE WORD
  209. ReleaseOrRenewAddress(UINT Request, UINT AddressLength, LPBYTE Address)
  210. {
  211. DWORD handle;
  212. handle = OpenDhcpVxdHandle();
  213. if (handle)
  214. {
  215. LPDHCP_HW_INFO info;
  216. WORD result;
  217. WORD length;
  218. length = sizeof(DHCP_HW_INFO) + AddressLength;
  219. info = (LPDHCP_HW_INFO)LocalAlloc(LPTR, length);
  220. if (!info)
  221. {
  222. return ERROR_NOT_ENOUGH_MEMORY;
  223. }
  224. info->OffsetHardwareAddress = sizeof(*info);
  225. info->HardwareLength = AddressLength;
  226. memcpy(info + 1, Address, AddressLength);
  227. result = DhcpVxdRequest(handle, (WORD)Request, length, (LPVOID)info);
  228. OsCloseVxdHandle(handle);
  229. LocalFree(info);
  230. return result;
  231. }
  232. return ERROR_FILE_NOT_FOUND;
  233. }
  234. #ifdef __cplusplus
  235. }
  236. #endif