ReactOS  0.4.12-dev-102-g4b7f1e0
dhcpcsvc.c File Reference
#include <rosdhcp.h>
#include <winsvc.h>
#include <debug.h>
Include dependency graph for dhcpcsvc.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

DWORD APIENTRY DhcpCApiInitialize (LPDWORD Version)
 
VOID APIENTRY DhcpCApiCleanup (VOID)
 
DWORD APIENTRY DhcpQueryHWInfo (DWORD AdapterIndex, PDWORD MediaType, PDWORD Mtu, PDWORD Speed)
 
DWORD APIENTRY DhcpLeaseIpAddress (DWORD AdapterIndex)
 
DWORD APIENTRY DhcpReleaseIpAddressLease (DWORD AdapterIndex)
 
DWORD APIENTRY DhcpRenewIpAddressLease (DWORD AdapterIndex)
 
DWORD APIENTRY DhcpStaticRefreshParams (DWORD AdapterIndex, DWORD Address, DWORD Netmask)
 
DWORD APIENTRY DhcpNotifyConfigChange (LPWSTR ServerName, LPWSTR AdapterName, BOOL NewIpAddress, DWORD IpIndex, DWORD IpAddress, DWORD SubnetMask, INT DhcpAction)
 
DWORD APIENTRY DhcpRequestParams (DWORD Flags, PVOID Reserved, LPWSTR AdapterName, LPDHCPCAPI_CLASSID ClassId, DHCPCAPI_PARAMS_ARRAY SendParams, DHCPCAPI_PARAMS_ARRAY RecdParams, LPBYTE Buffer, LPDWORD pSize, LPWSTR RequestIdStr)
 
DWORD APIENTRY DhcpRosGetAdapterInfo (DWORD AdapterIndex, PBOOL DhcpEnabled, PDWORD DhcpServer, time_t *LeaseObtained, time_t *LeaseExpires)
 
static VOID UpdateServiceStatus (DWORD dwState)
 
static DWORD WINAPI ServiceControlHandler (DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
 
VOID WINAPI ServiceMain (DWORD argc, LPWSTR *argv)
 
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 

Variables

static WCHAR ServiceName [] = L"DHCP"
 
SERVICE_STATUS_HANDLE ServiceStatusHandle = 0
 
SERVICE_STATUS ServiceStatus
 
HANDLE hStopEvent = NULL
 
static HANDLE PipeHandle = INVALID_HANDLE_VALUE
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file dhcpcsvc.c.

Function Documentation

◆ DhcpCApiCleanup()

VOID APIENTRY DhcpCApiCleanup ( VOID  )

Definition at line 69 of file dhcpcsvc.c.

Referenced by getDhcpInfoForAdapter(), INetCfgComponentControl_fnApplyRegistryChanges(), IpReleaseAddress(), and IpRenewAddress().

70 {
73 }
#define CloseHandle
Definition: compat.h:398
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21

◆ DhcpCApiInitialize()

DWORD APIENTRY DhcpCApiInitialize ( LPDWORD  Version)

Definition at line 24 of file dhcpcsvc.c.

Referenced by getDhcpInfoForAdapter(), INetCfgComponentControl_fnApplyRegistryChanges(), IpReleaseAddress(), and IpRenewAddress().

25 {
26  DWORD PipeMode;
27 
28  /* Wait for the pipe to be available */
30  {
31  /* No good, we failed */
32  return GetLastError();
33  }
34 
35  /* It's available, let's try to open it */
39  NULL,
41  0,
42  NULL);
43 
44  /* Check if we succeeded in opening the pipe */
46  {
47  /* We didn't */
48  return GetLastError();
49  }
50 
51  /* Change the pipe into message mode */
52  PipeMode = PIPE_READMODE_MESSAGE;
53  if (!SetNamedPipeHandleState(PipeHandle, &PipeMode, NULL, NULL))
54  {
55  /* Mode change failed */
58  return GetLastError();
59  }
60  else
61  {
62  /* We're good to go */
63  *Version = 2;
64  return NO_ERROR;
65  }
66 }
#define CloseHandle
Definition: compat.h:398
IN PVOID IN PVOID IN USHORT Version
Definition: pci.h:359
BOOL WINAPI WaitNamedPipeW(LPCWSTR lpNamedPipeName, DWORD nTimeOut)
Definition: npipe.c:458
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define NMPWAIT_USE_DEFAULT_WAIT
Definition: winbase.h:134
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define NO_ERROR
Definition: dderror.h:5
#define FILE_SHARE_READ
Definition: compat.h:125
#define GENERIC_WRITE
Definition: nt_native.h:90
smooth NULL
Definition: ftsmooth.c:416
#define OPEN_EXISTING
Definition: compat.h:426
BOOL WINAPI SetNamedPipeHandleState(HANDLE hNamedPipe, LPDWORD lpMode, LPDWORD lpMaxCollectionCount, LPDWORD lpCollectDataTimeout)
Definition: npipe.c:774
unsigned long DWORD
Definition: ntddk_ex.h:95
#define GENERIC_READ
Definition: compat.h:124
#define PIPE_READMODE_MESSAGE
Definition: winbase.h:170
#define DHCP_PIPE_NAME
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21
#define CreateFileW
Definition: compat.h:400

◆ DhcpLeaseIpAddress()

DWORD APIENTRY DhcpLeaseIpAddress ( DWORD  AdapterIndex)

Definition at line 111 of file dhcpcsvc.c.

112 {
113  COMM_DHCP_REQ Req;
114  COMM_DHCP_REPLY Reply;
116  BOOL Result;
117 
119 
121  Req.AdapterIndex = AdapterIndex;
122 
123  Result = TransactNamedPipe(PipeHandle,
124  &Req, sizeof(Req),
125  &Reply, sizeof(Reply),
126  &BytesRead, NULL);
127  if (!Result)
128  {
129  /* Pipe transaction failed */
130  return 0;
131  }
132 
133  return Reply.Reply;
134 }
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOL WINAPI TransactNamedPipe(IN HANDLE hNamedPipe, IN LPVOID lpInBuffer, IN DWORD nInBufferSize, OUT LPVOID lpOutBuffer, IN DWORD nOutBufferSize, OUT LPDWORD lpBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: npipe.c:1315
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255

◆ DhcpNotifyConfigChange()

DWORD APIENTRY DhcpNotifyConfigChange ( LPWSTR  ServerName,
LPWSTR  AdapterName,
BOOL  NewIpAddress,
DWORD  IpIndex,
DWORD  IpAddress,
DWORD  SubnetMask,
INT  DhcpAction 
)

Set new TCP/IP parameters and notify DHCP client service of this

Parameters
[in]ServerNameNULL for local machine
[in]AdapterNameIPHLPAPI name of adapter to change
[in]NewIpAddressTRUE if IP address changes
[in]IpAddressNew IP address (network byte order)
[in]SubnetMaskNew subnet mask (network byte order)
[in]DhcpAction0 - don't modify 1 - enable DHCP 2 - disable DHCP
Returns
non-zero on success
Remarks
Undocumented by Microsoft

Definition at line 246 of file dhcpcsvc.c.

253 {
254  DPRINT1("DHCPCSVC: DhcpNotifyConfigChange not implemented yet\n");
255  return 0;
256 }
#define DPRINT1
Definition: precomp.h:8

◆ DhcpQueryHWInfo()

DWORD APIENTRY DhcpQueryHWInfo ( DWORD  AdapterIndex,
PDWORD  MediaType,
PDWORD  Mtu,
PDWORD  Speed 
)

Definition at line 76 of file dhcpcsvc.c.

80 {
81  COMM_DHCP_REQ Req;
82  COMM_DHCP_REPLY Reply;
84  BOOL Result;
85 
87 
89  Req.AdapterIndex = AdapterIndex;
90 
92  &Req, sizeof(Req),
93  &Reply, sizeof(Reply),
94  &BytesRead, NULL);
95  if (!Result)
96  {
97  /* Pipe transaction failed */
98  return 0;
99  }
100 
101  if (Reply.Reply == 0)
102  return 0;
103 
104  *MediaType = Reply.QueryHWInfo.MediaType;
105  *Mtu = Reply.QueryHWInfo.Mtu;
106  *Speed = Reply.QueryHWInfo.Speed;
107  return 1;
108 }
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
struct _COMM_DHCP_REPLY::@3288 QueryHWInfo
BOOL WINAPI TransactNamedPipe(IN HANDLE hNamedPipe, IN LPVOID lpInBuffer, IN DWORD nInBufferSize, OUT LPVOID lpOutBuffer, IN DWORD nOutBufferSize, OUT LPDWORD lpBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: npipe.c:1315
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255

◆ DhcpReleaseIpAddressLease()

DWORD APIENTRY DhcpReleaseIpAddressLease ( DWORD  AdapterIndex)

Definition at line 137 of file dhcpcsvc.c.

Referenced by IpReleaseAddress().

138 {
139  COMM_DHCP_REQ Req;
140  COMM_DHCP_REPLY Reply;
142  BOOL Result;
143 
145 
147  Req.AdapterIndex = AdapterIndex;
148 
149  Result = TransactNamedPipe(PipeHandle,
150  &Req, sizeof(Req),
151  &Reply, sizeof(Reply),
152  &BytesRead, NULL);
153  if (!Result)
154  {
155  /* Pipe transaction failed */
156  return 0;
157  }
158 
159  return Reply.Reply;
160 }
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOL WINAPI TransactNamedPipe(IN HANDLE hNamedPipe, IN LPVOID lpInBuffer, IN DWORD nInBufferSize, OUT LPVOID lpOutBuffer, IN DWORD nOutBufferSize, OUT LPDWORD lpBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: npipe.c:1315
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255

◆ DhcpRenewIpAddressLease()

DWORD APIENTRY DhcpRenewIpAddressLease ( DWORD  AdapterIndex)

Definition at line 163 of file dhcpcsvc.c.

Referenced by IpRenewAddress().

164 {
165  COMM_DHCP_REQ Req;
166  COMM_DHCP_REPLY Reply;
168  BOOL Result;
169 
171 
173  Req.AdapterIndex = AdapterIndex;
174 
175  Result = TransactNamedPipe(PipeHandle,
176  &Req, sizeof(Req),
177  &Reply, sizeof(Reply),
178  &BytesRead, NULL);
179  if (!Result)
180  {
181  /* Pipe transaction failed */
182  return 0;
183  }
184 
185  return Reply.Reply;
186 }
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOL WINAPI TransactNamedPipe(IN HANDLE hNamedPipe, IN LPVOID lpInBuffer, IN DWORD nInBufferSize, OUT LPVOID lpOutBuffer, IN DWORD nOutBufferSize, OUT LPDWORD lpBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: npipe.c:1315
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255

◆ DhcpRequestParams()

DWORD APIENTRY DhcpRequestParams ( DWORD  Flags,
PVOID  Reserved,
LPWSTR  AdapterName,
LPDHCPCAPI_CLASSID  ClassId,
DHCPCAPI_PARAMS_ARRAY  SendParams,
DHCPCAPI_PARAMS_ARRAY  RecdParams,
LPBYTE  Buffer,
LPDWORD  pSize,
LPWSTR  RequestIdStr 
)

Definition at line 259 of file dhcpcsvc.c.

268 {
270  return 0;
271 }
#define UNIMPLEMENTED
Definition: debug.h:114

◆ DhcpRosGetAdapterInfo()

DWORD APIENTRY DhcpRosGetAdapterInfo ( DWORD  AdapterIndex,
PBOOL  DhcpEnabled,
PDWORD  DhcpServer,
time_t LeaseObtained,
time_t LeaseExpires 
)

Get DHCP info for an adapter

Parameters
[in]AdapterIndexIndex of the adapter (iphlpapi-style) for which info is requested
[out]DhcpEnabledReturns whether DHCP is enabled for the adapter
[out]DhcpServerReturns DHCP server IP address (255.255.255.255 if no server reached yet), in network byte order
[out]LeaseObtainedReturns time at which the lease was obtained
[out]LeaseExpiresReturns time at which the lease will expire
Returns
non-zero on success
Remarks
This is a ReactOS-only routine

Definition at line 298 of file dhcpcsvc.c.

Referenced by getDhcpInfoForAdapter().

303 {
304  COMM_DHCP_REQ Req;
305  COMM_DHCP_REPLY Reply;
307  BOOL Result;
308 
310 
312  Req.AdapterIndex = AdapterIndex;
313 
314  Result = TransactNamedPipe(PipeHandle,
315  &Req, sizeof(Req),
316  &Reply, sizeof(Reply),
317  &BytesRead, NULL);
318 
319  if (Result && Reply.Reply != 0)
320  *DhcpEnabled = Reply.GetAdapterInfo.DhcpEnabled;
321  else
322  *DhcpEnabled = FALSE;
323 
324  if (*DhcpEnabled)
325  {
326  *DhcpServer = Reply.GetAdapterInfo.DhcpServer;
327  *LeaseObtained = Reply.GetAdapterInfo.LeaseObtained;
328  *LeaseExpires = Reply.GetAdapterInfo.LeaseExpires;
329  }
330  else
331  {
332  *DhcpServer = INADDR_NONE;
333  *LeaseObtained = 0;
334  *LeaseExpires = 0;
335  }
336 
337  return Reply.Reply;
338 }
struct _COMM_DHCP_REPLY::@3289 GetAdapterInfo
#define INADDR_NONE
Definition: tcp.c:42
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOL WINAPI TransactNamedPipe(IN HANDLE hNamedPipe, IN LPVOID lpInBuffer, IN DWORD nInBufferSize, OUT LPVOID lpOutBuffer, IN DWORD nOutBufferSize, OUT LPDWORD lpBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: npipe.c:1315
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255

◆ DhcpStaticRefreshParams()

DWORD APIENTRY DhcpStaticRefreshParams ( DWORD  AdapterIndex,
DWORD  Address,
DWORD  Netmask 
)

Definition at line 189 of file dhcpcsvc.c.

Referenced by INetCfgComponentControl_fnApplyRegistryChanges().

192 {
193  COMM_DHCP_REQ Req;
194  COMM_DHCP_REPLY Reply;
196  BOOL Result;
197 
199 
201  Req.AdapterIndex = AdapterIndex;
202  Req.Body.StaticRefreshParams.IPAddress = Address;
203  Req.Body.StaticRefreshParams.Netmask = Netmask;
204 
205  Result = TransactNamedPipe(PipeHandle,
206  &Req, sizeof(Req),
207  &Reply, sizeof(Reply),
208  &BytesRead, NULL);
209  if (!Result)
210  {
211  /* Pipe transaction failed */
212  return 0;
213  }
214 
215  return Reply.Reply;
216 }
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
union _COMM_DHCP_REQ::@3283 Body
smooth NULL
Definition: ftsmooth.c:416
static WCHAR Address[46]
Definition: ping.c:68
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
BOOL WINAPI TransactNamedPipe(IN HANDLE hNamedPipe, IN LPVOID lpInBuffer, IN DWORD nInBufferSize, OUT LPVOID lpOutBuffer, IN DWORD nOutBufferSize, OUT LPDWORD lpBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: npipe.c:1315
static HANDLE PipeHandle
Definition: dhcpcsvc.c:21
_Must_inspect_result_ _In_ PFILE_OBJECT _In_opt_ PLARGE_INTEGER _In_ ULONG _In_ FLT_IO_OPERATION_FLAGS _Out_opt_ PULONG BytesRead
Definition: fltkernel.h:1255
struct _COMM_DHCP_REQ::@3283::@3287 StaticRefreshParams

◆ DllMain()

BOOL WINAPI DllMain ( HINSTANCE  hinstDLL,
DWORD  fdwReason,
LPVOID  lpvReserved 
)

Definition at line 438 of file dhcpcsvc.c.

441 {
442  switch (fdwReason)
443  {
444  case DLL_PROCESS_ATTACH:
445  DisableThreadLibraryCalls(hinstDLL);
446  break;
447 
448  case DLL_PROCESS_DETACH:
449  break;
450  }
451 
452  return TRUE;
453 }
#define TRUE
Definition: types.h:120
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
#define DLL_PROCESS_DETACH
Definition: compat.h:119

◆ ServiceControlHandler()

static DWORD WINAPI ServiceControlHandler ( DWORD  dwControl,
DWORD  dwEventType,
LPVOID  lpEventData,
LPVOID  lpContext 
)
static

Definition at line 367 of file dhcpcsvc.c.

Referenced by ServiceMain().

371 {
372  switch (dwControl)
373  {
377  if (hStopEvent != NULL)
379  return ERROR_SUCCESS;
380 
383  &ServiceStatus);
384  return ERROR_SUCCESS;
385 
386  default:
388  }
389 }
#define ERROR_SUCCESS
Definition: deptool.c:10
SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: dhcpcsvc.c:17
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:679
static VOID UpdateServiceStatus(DWORD dwState)
Definition: dhcpcsvc.c:342
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:957
HANDLE hStopEvent
Definition: dhcpcsvc.c:19
smooth NULL
Definition: ftsmooth.c:416
#define SERVICE_CONTROL_INTERROGATE
Definition: winsvc.h:39
SERVICE_STATUS ServiceStatus
Definition: dhcpcsvc.c:18
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:92
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40

◆ ServiceMain()

static VOID CALLBACK ServiceMain ( DWORD  argc,
LPWSTR argv 
)

Definition at line 392 of file dhcpcsvc.c.

393 {
396  NULL);
397  if (!ServiceStatusHandle)
398  {
399  DPRINT1("DHCPCSVC: Unable to register service control handler (%lx)\n", GetLastError());
400  return;
401  }
402 
404 
405  /* Create the stop event */
407  if (hStopEvent == NULL)
408  {
410  return;
411  }
412 
414 
415  if (!init_client())
416  {
417  DPRINT1("DHCPCSVC: init_client() failed!\n");
419  return;
420  }
421 
422  DH_DbgPrint(MID_TRACE,("DHCP Service Started\n"));
423 
425 
426  DH_DbgPrint(MID_TRACE,("Going into dispatch()\n"));
427  DH_DbgPrint(MID_TRACE,("DHCPCSVC: DHCP service is starting up\n"));
428 
430 
431  DH_DbgPrint(MID_TRACE,("DHCPCSVC: DHCP service is shutting down\n"));
432  stop_client();
433 
435 }
#define MID_TRACE
Definition: debug.h:15
static DWORD WINAPI ServiceControlHandler(DWORD dwControl, DWORD dwEventType, LPVOID lpEventData, LPVOID lpContext)
Definition: dhcpcsvc.c:367
SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: dhcpcsvc.c:17
static WCHAR ServiceName[]
Definition: dhcpcsvc.c:15
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define SERVICE_START_PENDING
Definition: winsvc.h:22
static VOID UpdateServiceStatus(DWORD dwState)
Definition: dhcpcsvc.c:342
HANDLE WINAPI DECLSPEC_HOTPATCH CreateEventW(IN LPSECURITY_ATTRIBUTES lpEventAttributes OPTIONAL, IN BOOL bManualReset, IN BOOL bInitialState, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:597
#define SERVICE_STOPPED
Definition: winsvc.h:21
void stop_client(void)
Definition: dhclient.c:137
HANDLE hStopEvent
Definition: dhcpcsvc.c:19
#define SERVICE_RUNNING
Definition: winsvc.h:24
smooth NULL
Definition: ftsmooth.c:416
#define DH_DbgPrint(_t_, _x_)
Definition: debug.h:49
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerExW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION_EX lpHandlerProc, LPVOID lpContext)
Definition: sctrl.c:773
void dispatch(HANDLE hStopEvent)
Definition: dispatch.c:66
int init_client(void)
Definition: dhclient.c:111
#define DPRINT1
Definition: precomp.h:8

◆ UpdateServiceStatus()

static VOID UpdateServiceStatus ( DWORD  dwState)
static

Definition at line 342 of file dhcpcsvc.c.

Referenced by ServiceControlHandler(), and ServiceMain().

343 {
345  ServiceStatus.dwCurrentState = dwState;
346 
347  if (dwState == SERVICE_RUNNING)
349  else
351 
355 
356  if (dwState == SERVICE_START_PENDING ||
357  dwState == SERVICE_STOP_PENDING)
358  ServiceStatus.dwWaitHint = 1000;
359  else
361 
363  &ServiceStatus);
364 }
DWORD dwCurrentState
Definition: winsvc.h:100
SERVICE_STATUS_HANDLE ServiceStatusHandle
Definition: dhcpcsvc.c:17
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
#define SERVICE_START_PENDING
Definition: winsvc.h:22
DWORD dwServiceSpecificExitCode
Definition: winsvc.h:103
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:957
DWORD dwCheckPoint
Definition: winsvc.h:104
#define SERVICE_RUNNING
Definition: winsvc.h:24
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:960
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30
DWORD dwWaitHint
Definition: winsvc.h:105
DWORD dwWin32ExitCode
Definition: winsvc.h:102
DWORD dwServiceType
Definition: winsvc.h:99
DWORD dwControlsAccepted
Definition: winsvc.h:101
SERVICE_STATUS ServiceStatus
Definition: dhcpcsvc.c:18
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23

Variable Documentation

◆ hStopEvent

HANDLE hStopEvent = NULL

Definition at line 19 of file dhcpcsvc.c.

Referenced by dispatch().

◆ PipeHandle

◆ ServiceName

WCHAR ServiceName[] = L"DHCP"
static

Definition at line 15 of file dhcpcsvc.c.

Referenced by ServiceMain().

◆ ServiceStatus

◆ ServiceStatusHandle

SERVICE_STATUS_HANDLE ServiceStatusHandle = 0

Definition at line 17 of file dhcpcsvc.c.

Referenced by ServiceControlHandler(), ServiceMain(), and UpdateServiceStatus().