mirror of
https://github.com/reactos/reactos.git
synced 2025-04-25 08:00:24 +00:00
[DHCPCSVC] Implement DhcpAcquireParameters and DhcpReleaseParameters
TODO: The AdapterName parameter should be a unicode string. Fix this later.
This commit is contained in:
parent
f135cab83e
commit
4514e748f0
8 changed files with 198 additions and 15 deletions
|
@ -509,7 +509,7 @@ PDHCP_ADAPTER AdapterFindIndex( unsigned int indx ) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
PDHCP_ADAPTER AdapterFindName( const WCHAR *name ) {
|
||||
PDHCP_ADAPTER AdapterFindName( const CHAR *name ) {
|
||||
PDHCP_ADAPTER Adapter;
|
||||
PLIST_ENTRY ListEntry;
|
||||
|
||||
|
@ -517,7 +517,7 @@ PDHCP_ADAPTER AdapterFindName( const WCHAR *name ) {
|
|||
ListEntry != &AdapterList;
|
||||
ListEntry = ListEntry->Flink ) {
|
||||
Adapter = CONTAINING_RECORD( ListEntry, DHCP_ADAPTER, ListEntry );
|
||||
if( !_wcsicmp( Adapter->IfMib.wszName, name ) ) return Adapter;
|
||||
if( !stricmp((const CHAR*)Adapter->IfMib.bDescr, name ) ) return Adapter;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
|
|
@ -33,6 +33,101 @@ VOID ApiFree() {
|
|||
|
||||
/* This represents the service portion of the DHCP client API */
|
||||
|
||||
DWORD
|
||||
DSAcquireParams(
|
||||
_In_ PipeSendFunc Send,
|
||||
_In_ HANDLE CommPipe,
|
||||
_Out_ COMM_DHCP_REQ *Req)
|
||||
{
|
||||
COMM_DHCP_REPLY Reply;
|
||||
PDHCP_ADAPTER Adapter;
|
||||
struct protocol* proto;
|
||||
|
||||
DPRINT1("DSAcquireParams()\n");
|
||||
|
||||
ApiLock();
|
||||
|
||||
Adapter = AdapterFindName(Req->Body.AcquireParams.AdapterName);
|
||||
DPRINT1("Adapter: %p\n", Adapter);
|
||||
|
||||
if (Adapter == NULL || Adapter->DhclientState.state == S_STATIC)
|
||||
{
|
||||
Reply.Reply = 0;
|
||||
ApiUnlock();
|
||||
return Send(CommPipe, &Reply);
|
||||
}
|
||||
|
||||
Reply.Reply = 1;
|
||||
|
||||
proto = find_protocol_by_adapter(&Adapter->DhclientInfo);
|
||||
if (proto)
|
||||
remove_protocol(proto);
|
||||
|
||||
add_protocol(Adapter->DhclientInfo.name,
|
||||
Adapter->DhclientInfo.rfdesc, got_one,
|
||||
&Adapter->DhclientInfo);
|
||||
|
||||
Adapter->DhclientInfo.client->state = S_INIT;
|
||||
state_reboot(&Adapter->DhclientInfo);
|
||||
|
||||
if (hAdapterStateChangedEvent != NULL)
|
||||
SetEvent(hAdapterStateChangedEvent);
|
||||
|
||||
ApiUnlock();
|
||||
|
||||
return Send(CommPipe, &Reply);
|
||||
}
|
||||
|
||||
|
||||
DWORD
|
||||
DSReleaseParams(
|
||||
_In_ PipeSendFunc Send,
|
||||
_In_ HANDLE CommPipe,
|
||||
_Out_ COMM_DHCP_REQ *Req)
|
||||
{
|
||||
COMM_DHCP_REPLY Reply;
|
||||
PDHCP_ADAPTER Adapter;
|
||||
struct protocol* proto;
|
||||
|
||||
DPRINT1("DSReleaseParams()\n");
|
||||
|
||||
ApiLock();
|
||||
|
||||
Adapter = AdapterFindName(Req->Body.AcquireParams.AdapterName);
|
||||
DPRINT1("Adapter: %p\n", Adapter);
|
||||
|
||||
Reply.Reply = Adapter ? 1 : 0;
|
||||
|
||||
if (Adapter)
|
||||
{
|
||||
if (Adapter->NteContext)
|
||||
{
|
||||
DeleteIPAddress(Adapter->NteContext);
|
||||
Adapter->NteContext = 0;
|
||||
}
|
||||
if (Adapter->RouterMib.dwForwardNextHop)
|
||||
{
|
||||
DeleteIpForwardEntry(&Adapter->RouterMib);
|
||||
Adapter->RouterMib.dwForwardNextHop = 0;
|
||||
}
|
||||
|
||||
proto = find_protocol_by_adapter(&Adapter->DhclientInfo);
|
||||
if (proto)
|
||||
remove_protocol(proto);
|
||||
|
||||
Adapter->DhclientInfo.client->active = NULL;
|
||||
Adapter->DhclientInfo.client->state = S_INIT;
|
||||
|
||||
if (hAdapterStateChangedEvent != NULL)
|
||||
SetEvent(hAdapterStateChangedEvent);
|
||||
}
|
||||
|
||||
ApiUnlock();
|
||||
|
||||
return Send(CommPipe, &Reply);
|
||||
}
|
||||
|
||||
|
||||
DWORD DSLeaseIpAddress( PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req ) {
|
||||
COMM_DHCP_REPLY Reply;
|
||||
PDHCP_ADAPTER Adapter;
|
||||
|
|
|
@ -377,11 +377,21 @@ DWORD WINAPI PipeThreadProc( LPVOID Parameter ) {
|
|||
}
|
||||
}
|
||||
|
||||
if( Result ) {
|
||||
switch( Req.Type ) {
|
||||
case DhcpReqQueryHWInfo:
|
||||
DSQueryHWInfo( PipeSend, CommPipe, &Req );
|
||||
break;
|
||||
if( Result )
|
||||
{
|
||||
switch( Req.Type )
|
||||
{
|
||||
case DhcpReqAcquireParams:
|
||||
DSAcquireParams(PipeSend, CommPipe, &Req);
|
||||
break;
|
||||
|
||||
case DhcpReqReleaseParams:
|
||||
DSReleaseParams(PipeSend, CommPipe, &Req);
|
||||
break;
|
||||
|
||||
case DhcpReqQueryHWInfo:
|
||||
DSQueryHWInfo(PipeSend, CommPipe, &Req);
|
||||
break;
|
||||
|
||||
case DhcpReqLeaseIpAddress:
|
||||
DSLeaseIpAddress( PipeSend, CommPipe, &Req );
|
||||
|
|
|
@ -74,6 +74,69 @@ DhcpCApiCleanup(VOID)
|
|||
PipeHandle = INVALID_HANDLE_VALUE;
|
||||
}
|
||||
|
||||
|
||||
/* FIXME: The adapter name should be a unicode string */
|
||||
DWORD
|
||||
APIENTRY
|
||||
DhcpAcquireParameters(
|
||||
_In_ PSTR AdapterName)
|
||||
{
|
||||
COMM_DHCP_REQ Req;
|
||||
COMM_DHCP_REPLY Reply;
|
||||
DWORD BytesRead;
|
||||
BOOL Result;
|
||||
|
||||
DPRINT1("DhcpAcquireParameters(%s)\n", AdapterName);
|
||||
|
||||
ASSERT(PipeHandle != INVALID_HANDLE_VALUE);
|
||||
|
||||
Req.Type = DhcpReqAcquireParams;
|
||||
strcpy(Req.Body.AcquireParams.AdapterName, AdapterName);
|
||||
|
||||
Result = TransactNamedPipe(PipeHandle,
|
||||
&Req, sizeof(Req),
|
||||
&Reply, sizeof(Reply),
|
||||
&BytesRead, NULL);
|
||||
if (!Result)
|
||||
{
|
||||
/* Pipe transaction failed */
|
||||
return GetLastError();
|
||||
}
|
||||
|
||||
return Reply.Reply;
|
||||
}
|
||||
|
||||
/* FIXME: The adapter name should be a unicode string */
|
||||
DWORD
|
||||
APIENTRY
|
||||
DhcpReleaseParameters(
|
||||
_In_ PSTR AdapterName)
|
||||
{
|
||||
COMM_DHCP_REQ Req;
|
||||
COMM_DHCP_REPLY Reply;
|
||||
DWORD BytesRead;
|
||||
BOOL Result;
|
||||
|
||||
DPRINT1("DhcpReleaseParameters(%s)\n", AdapterName);
|
||||
|
||||
ASSERT(PipeHandle != INVALID_HANDLE_VALUE);
|
||||
|
||||
Req.Type = DhcpReqReleaseParams;
|
||||
strcpy(Req.Body.AcquireParams.AdapterName, AdapterName);
|
||||
|
||||
Result = TransactNamedPipe(PipeHandle,
|
||||
&Req, sizeof(Req),
|
||||
&Reply, sizeof(Reply),
|
||||
&BytesRead, NULL);
|
||||
if (!Result)
|
||||
{
|
||||
/* Pipe transaction failed */
|
||||
return GetLastError();
|
||||
}
|
||||
|
||||
return Reply.Reply;
|
||||
}
|
||||
|
||||
DWORD APIENTRY
|
||||
DhcpQueryHWInfo(DWORD AdapterIndex,
|
||||
PDWORD MediaType,
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
# PURPOSE: dhcpcsvc exports
|
||||
# COPYRIGHT: Copyright 2006 Ge van Geldorp <gvg@reactos.org>
|
||||
#
|
||||
@ stub DhcpAcquireParameters
|
||||
@ stdcall DhcpAcquireParameters(str)
|
||||
@ stub DhcpAcquireParametersByBroadcast
|
||||
@ stdcall DhcpCApiCleanup()
|
||||
@ stdcall DhcpCApiInitialize(ptr)
|
||||
|
@ -27,7 +27,7 @@
|
|||
@ stub DhcpRegisterParamChange
|
||||
@ stdcall DhcpReleaseIpAddressLease(long)
|
||||
@ stub DhcpReleaseIpAddressLeaseEx
|
||||
@ stub DhcpReleaseParameters
|
||||
@ stdcall DhcpReleaseParameters(str)
|
||||
@ stub DhcpRemoveDNSRegistrations
|
||||
@ stdcall DhcpRenewIpAddressLease(long)
|
||||
@ stub DhcpRenewIpAddressLeaseEx
|
||||
|
|
|
@ -90,6 +90,7 @@ void AdapterStop(VOID);
|
|||
extern PDHCP_ADAPTER AdapterGetFirst(VOID);
|
||||
extern PDHCP_ADAPTER AdapterGetNext(PDHCP_ADAPTER);
|
||||
extern PDHCP_ADAPTER AdapterFindIndex( unsigned int AdapterIndex );
|
||||
extern PDHCP_ADAPTER AdapterFindName(const CHAR *name);
|
||||
extern PDHCP_ADAPTER AdapterFindInfo( struct interface_info *info );
|
||||
extern PDHCP_ADAPTER AdapterFindByHardwareAddress( u_int8_t haddr[16], u_int8_t hlen );
|
||||
extern HANDLE PipeInit(HANDLE hStopEvent);
|
||||
|
@ -97,6 +98,8 @@ extern VOID ApiInit(VOID);
|
|||
extern VOID ApiFree(VOID);
|
||||
extern VOID ApiLock(VOID);
|
||||
extern VOID ApiUnlock(VOID);
|
||||
extern DWORD DSAcquireParams(PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req);
|
||||
extern DWORD DSReleaseParams(PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req);
|
||||
extern DWORD DSQueryHWInfo( PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req );
|
||||
extern DWORD DSLeaseIpAddress( PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req );
|
||||
extern DWORD DSRenewIpAddressLease( PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req );
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#define ROSDHCP_PIPE_H
|
||||
|
||||
enum {
|
||||
DhcpReqAcquireParams,
|
||||
DhcpReqReleaseParams,
|
||||
DhcpReqLeaseIpAddress,
|
||||
DhcpReqQueryHWInfo,
|
||||
DhcpReqReleaseIpAddress,
|
||||
|
@ -12,7 +14,12 @@ enum {
|
|||
typedef struct _COMM_DHCP_REQ {
|
||||
UINT Type;
|
||||
DWORD AdapterIndex;
|
||||
union {
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
CHAR AdapterName[64];
|
||||
} AcquireParams;
|
||||
struct {
|
||||
BOOL Inserted;
|
||||
} PnpEvent;
|
||||
|
|
|
@ -5,6 +5,16 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
DWORD
|
||||
APIENTRY
|
||||
DhcpAcquireParameters(
|
||||
_In_ PSTR AdapterName);
|
||||
|
||||
DWORD
|
||||
APIENTRY
|
||||
DhcpReleaseParameters(
|
||||
_In_ PSTR AdapterName);
|
||||
|
||||
DWORD APIENTRY DhcpLeaseIpAddress( DWORD AdapterIndex );
|
||||
DWORD APIENTRY DhcpQueryHWInfo( DWORD AdapterIndex,
|
||||
PDWORD MediaType,
|
||||
|
@ -23,11 +33,6 @@ DhcpNotifyConfigChange(LPWSTR ServerName,
|
|||
DWORD IpAddress,
|
||||
DWORD SubnetMask,
|
||||
int DhcpAction);
|
||||
DWORD APIENTRY DhcpRosGetAdapterInfo( DWORD AdapterIndex,
|
||||
PBOOL DhcpEnabled,
|
||||
PDWORD DhcpServer,
|
||||
time_t *LeaseObtained,
|
||||
time_t *LeaseExpires );
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue