ReactOS  0.4.15-dev-3324-gda4e15f
pipe.c File Reference
#include <rosdhcp.h>
#include <reactos/debug.h>
Include dependency graph for pipe.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define COMM_PIPE_OUTPUT_BUFFER   sizeof(COMM_DHCP_REQ)
 
#define COMM_PIPE_INPUT_BUFFER   sizeof(COMM_DHCP_REPLY)
 
#define COMM_PIPE_DEFAULT_TIMEOUT   1000
 

Functions

DWORD PipeSend (HANDLE CommPipe, COMM_DHCP_REPLY *Reply)
 
DWORD WINAPI PipeThreadProc (LPVOID Parameter)
 
HANDLE PipeInit (HANDLE hStopEvent)
 

Macro Definition Documentation

◆ COMM_PIPE_DEFAULT_TIMEOUT

#define COMM_PIPE_DEFAULT_TIMEOUT   1000

Definition at line 16 of file pipe.c.

◆ COMM_PIPE_INPUT_BUFFER

#define COMM_PIPE_INPUT_BUFFER   sizeof(COMM_DHCP_REPLY)

Definition at line 15 of file pipe.c.

◆ COMM_PIPE_OUTPUT_BUFFER

#define COMM_PIPE_OUTPUT_BUFFER   sizeof(COMM_DHCP_REQ)

Definition at line 14 of file pipe.c.

◆ NDEBUG

#define NDEBUG

Definition at line 11 of file pipe.c.

Function Documentation

◆ PipeInit()

HANDLE PipeInit ( HANDLE  hStopEvent)

Definition at line 171 of file pipe.c.

172 {
174 }
DWORD WINAPI PipeThreadProc(LPVOID Parameter)
Definition: pipe.c:39
HANDLE hStopEvent
Definition: dhcpcsvc.c:19
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:136
#define NULL
Definition: types.h:112

Referenced by ServiceMain().

◆ PipeSend()

DWORD PipeSend ( HANDLE  CommPipe,
COMM_DHCP_REPLY Reply 
)

Definition at line 18 of file pipe.c.

18  {
19  DWORD Written = 0;
20  OVERLAPPED Overlapped = {0};
21  BOOL Success =
22  WriteFile( CommPipe,
23  Reply,
24  sizeof(*Reply),
25  &Written,
26  &Overlapped);
27  if (!Success)
28  {
29  WaitForSingleObject(CommPipe, INFINITE);
30  Success = GetOverlappedResult(CommPipe,
31  &Overlapped,
32  &Written,
33  TRUE);
34  }
35 
36  return Success ? Written : -1;
37 }
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
BOOL WINAPI GetOverlappedResult(IN HANDLE hFile, IN LPOVERLAPPED lpOverlapped, OUT LPDWORD lpNumberOfBytesTransferred, IN BOOL bWait)
Definition: iocompl.c:221
#define TRUE
Definition: types.h:120
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
#define INFINITE
Definition: serial.h:102

Referenced by PipeThreadProc().

◆ PipeThreadProc()

DWORD WINAPI PipeThreadProc ( LPVOID  Parameter)

Definition at line 39 of file pipe.c.

39  {
41  COMM_DHCP_REQ Req;
42  COMM_DHCP_REPLY Reply;
43  BOOL Result, Connected;
44  HANDLE Events[2];
45  HANDLE CommPipe;
46  OVERLAPPED Overlapped = {0};
47  DWORD dwError;
48 
49  DPRINT("PipeThreadProc(%p)\n", Parameter);
50 
51  CommPipe = CreateNamedPipeW
55  1,
59  NULL );
60  if (CommPipe == INVALID_HANDLE_VALUE)
61  {
62  DbgPrint("DHCP: Could not create named pipe\n");
63  return FALSE;
64  }
65 
66  Events[0] = (HANDLE)Parameter;
67  Events[1] = CommPipe;
68 
69  while( TRUE )
70  {
71  Connected = ConnectNamedPipe(CommPipe, &Overlapped);
72  if (!Connected)
73  {
74  dwError = GetLastError();
75  if (dwError == ERROR_IO_PENDING)
76  {
78  DPRINT("WaitForMultipleObjects() returned %lu\n", dwError);
79  if (dwError == WAIT_OBJECT_0 + 1)
80  {
81  Connected = GetOverlappedResult(CommPipe,
82  &Overlapped,
83  &BytesRead,
84  TRUE);
85  }
86  else if (dwError == WAIT_OBJECT_0)
87  {
88  CancelIo(CommPipe);
89  CloseHandle(CommPipe);
90  CommPipe = INVALID_HANDLE_VALUE;
91  break;
92  }
93  }
94  }
95 
96  if (!Connected) {
97  DbgPrint("DHCP: Could not connect named pipe\n");
98  CloseHandle( CommPipe );
99  CommPipe = INVALID_HANDLE_VALUE;
100  break;
101  }
102 
103  Result = ReadFile(CommPipe, &Req, sizeof(Req), &BytesRead, &Overlapped);
104  if (!Result)
105  {
106  dwError = GetLastError();
107  if (dwError == ERROR_IO_PENDING)
108  {
110  DPRINT("WaitForMultipleObjects() returned %lu\n", dwError);
111  if (dwError == WAIT_OBJECT_0 + 1)
112  {
113  Result = GetOverlappedResult(CommPipe,
114  &Overlapped,
115  &BytesRead,
116  TRUE);
117  }
118  else if (dwError == WAIT_OBJECT_0)
119  {
120  CancelIo(CommPipe);
121  DisconnectNamedPipe( CommPipe );
122  CloseHandle(CommPipe);
123  CommPipe = INVALID_HANDLE_VALUE;
124  break;
125  }
126  }
127  }
128 
129  if( Result ) {
130  switch( Req.Type ) {
131  case DhcpReqQueryHWInfo:
132  DSQueryHWInfo( PipeSend, CommPipe, &Req );
133  break;
134 
136  DSLeaseIpAddress( PipeSend, CommPipe, &Req );
137  break;
138 
140  DSReleaseIpAddressLease( PipeSend, CommPipe, &Req );
141  break;
142 
144  DSRenewIpAddressLease( PipeSend, CommPipe, &Req );
145  break;
146 
148  DSStaticRefreshParams( PipeSend, CommPipe, &Req );
149  break;
150 
152  DSGetAdapterInfo( PipeSend, CommPipe, &Req );
153  break;
154 
155  default:
156  DPRINT1("Unrecognized request type %d\n", Req.Type);
157  ZeroMemory( &Reply, sizeof( COMM_DHCP_REPLY ) );
158  Reply.Reply = 0;
159  PipeSend(CommPipe, &Reply );
160  break;
161  }
162  }
163  DisconnectNamedPipe( CommPipe );
164  }
165 
166  DPRINT("Pipe thread stopped!\n");
167 
168  return TRUE;
169 }
#define COMM_PIPE_DEFAULT_TIMEOUT
Definition: pipe.c:16
#define CloseHandle
Definition: compat.h:598
#define DbgPrint
Definition: hal.h:12
#define PIPE_TYPE_MESSAGE
Definition: winbase.h:168
BOOL WINAPI GetOverlappedResult(IN HANDLE hFile, IN LPOVERLAPPED lpOverlapped, OUT LPDWORD lpNumberOfBytesTransferred, IN BOOL bWait)
Definition: iocompl.c:221
#define TRUE
Definition: types.h:120
#define PIPE_WAIT
Definition: winbase.h:171
#define INVALID_HANDLE_VALUE
Definition: compat.h:590
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1040
#define ZeroMemory
Definition: winbase.h:1664
DWORD DSReleaseIpAddressLease(PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req)
Definition: api.c:90
_In_ PVOID Parameter
Definition: ldrtypes.h:241
#define ERROR_IO_PENDING
Definition: dderror.h:15
DWORD WINAPI WaitForMultipleObjects(IN DWORD nCount, IN CONST HANDLE *lpHandles, IN BOOL bWaitAll, IN DWORD dwMilliseconds)
Definition: synch.c:151
_Must_inspect_result_ _In_ WDFIOTARGET _In_opt_ WDFREQUEST _In_opt_ PWDF_MEMORY_DESCRIPTOR _In_opt_ PLONGLONG _In_opt_ PWDF_REQUEST_SEND_OPTIONS _Out_opt_ PULONG_PTR BytesRead
Definition: wdfiotarget.h:859
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
DWORD PipeSend(HANDLE CommPipe, COMM_DHCP_REPLY *Reply)
Definition: pipe.c:18
BOOL WINAPI CancelIo(IN HANDLE hFile)
Definition: deviceio.c:290
_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
#define COMM_PIPE_INPUT_BUFFER
Definition: pipe.c:15
#define FILE_FLAG_FIRST_PIPE_INSTANCE
Definition: piperead.cpp:20
DWORD DSLeaseIpAddress(PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req)
Definition: api.c:36
#define WAIT_OBJECT_0
Definition: winbase.h:403
#define PIPE_ACCESS_DUPLEX
Definition: winbase.h:164
unsigned long DWORD
Definition: ntddk_ex.h:95
#define COMM_PIPE_OUTPUT_BUFFER
Definition: pipe.c:14
static HANDLE(WINAPI *pOpenThread)(DWORD dwDesiredAccess
BOOL WINAPI DisconnectNamedPipe(HANDLE hNamedPipe)
Definition: npipe.c:961
DWORD DSQueryHWInfo(PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req)
Definition: api.c:68
#define PIPE_READMODE_MESSAGE
Definition: winbase.h:170
DWORD DSRenewIpAddressLease(PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req)
Definition: api.c:129
DWORD DSStaticRefreshParams(PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req)
Definition: api.c:165
#define DHCP_PIPE_NAME
HANDLE Events[2]
Definition: schedsvc.c:40
DWORD DSGetAdapterInfo(PipeSendFunc Send, HANDLE CommPipe, COMM_DHCP_REQ *Req)
Definition: api.c:209
#define ReadFile(a, b, c, d, e)
Definition: compat.h:601
#define NULL
Definition: types.h:112
#define DPRINT1
Definition: precomp.h:8
#define DPRINT
Definition: sndvol32.h:71
HANDLE WINAPI CreateNamedPipeW(LPCWSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD nMaxInstances, DWORD nOutBufferSize, DWORD nInBufferSize, DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: npipe.c:246
#define FILE_FLAG_OVERLAPPED
Definition: disk.h:46
#define INFINITE
Definition: serial.h:102
BOOL WINAPI ConnectNamedPipe(IN HANDLE hNamedPipe, IN LPOVERLAPPED lpOverlapped)
Definition: npipe.c:701

Referenced by PipeInit().