ReactOS  0.4.12-dev-51-ge94618b
pipe.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: See COPYING in the top level directory
3  * PROJECT: ReactOS kernel
4  * FILE: subsys/system/dhcp/pipe.c
5  * PURPOSE: DHCP client pipe
6  * PROGRAMMER: arty
7  */
8 
9 #include <rosdhcp.h>
10 
11 #define NDEBUG
12 #include <reactos/debug.h>
13 
16 
17 #define COMM_PIPE_OUTPUT_BUFFER sizeof(COMM_DHCP_REQ)
18 #define COMM_PIPE_INPUT_BUFFER sizeof(COMM_DHCP_REPLY)
19 #define COMM_PIPE_DEFAULT_TIMEOUT 1000
20 
22  DWORD Written = 0;
23  BOOL Success =
24  WriteFile( CommPipe,
25  Reply,
26  sizeof(*Reply),
27  &Written,
28  NULL );
29  return Success ? Written : -1;
30 }
31 
34  COMM_DHCP_REQ Req;
35  COMM_DHCP_REPLY Reply;
36  BOOL Result, Connected;
37 
38  while( TRUE ) {
39  Connected = ConnectNamedPipe( CommPipe, NULL ) ?
41 
42  if (!Connected) {
43  DbgPrint("DHCP: Could not connect named pipe\n");
44  CloseHandle( CommPipe );
45  CommPipe = INVALID_HANDLE_VALUE;
46  break;
47  }
48 
49  Result = ReadFile( CommPipe, &Req, sizeof(Req), &BytesRead, NULL );
50  if( Result ) {
51  switch( Req.Type ) {
52  case DhcpReqQueryHWInfo:
53  DSQueryHWInfo( PipeSend, &Req );
54  break;
55 
57  DSLeaseIpAddress( PipeSend, &Req );
58  break;
59 
62  break;
63 
66  break;
67 
70  break;
71 
73  DSGetAdapterInfo( PipeSend, &Req );
74  break;
75 
76  default:
77  DPRINT1("Unrecognized request type %d\n", Req.Type);
78  ZeroMemory( &Reply, sizeof( COMM_DHCP_REPLY ) );
79  Reply.Reply = 0;
80  PipeSend( &Reply );
81  break;
82  }
83  }
84  DisconnectNamedPipe( CommPipe );
85  }
86 
87  return TRUE;
88 }
89 
91  CommPipe = CreateNamedPipeW
95  1,
99  NULL );
100 
101  if( CommPipe == INVALID_HANDLE_VALUE ) {
102  DbgPrint("DHCP: Could not create named pipe\n");
103  return CommPipe;
104  }
105 
107 
108  if( !CommThread ) {
109  CloseHandle( CommPipe );
110  CommPipe = INVALID_HANDLE_VALUE;
111  }
112 
113  return CommPipe;
114 }
115 
117  CloseHandle( CommPipe );
118  CommPipe = INVALID_HANDLE_VALUE;
119 }
#define TRUE
Definition: types.h:120
#define COMM_PIPE_DEFAULT_TIMEOUT
Definition: pipe.c:19
DWORD WINAPI PipeThreadProc(LPVOID Parameter)
Definition: pipe.c:32
#define CloseHandle
Definition: compat.h:398
#define DbgPrint
Definition: loader.c:25
#define PIPE_TYPE_MESSAGE
Definition: winbase.h:168
#define PIPE_WAIT
Definition: winbase.h:171
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
_In_ PVOID Parameter
Definition: ldrtypes.h:239
DWORD DSGetAdapterInfo(PipeSendFunc Send, COMM_DHCP_REQ *Req)
Definition: api.c:209
HANDLE PipeInit()
Definition: pipe.c:90
DWORD DSRenewIpAddressLease(PipeSendFunc Send, COMM_DHCP_REQ *Req)
Definition: api.c:129
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:112
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
#define COMM_PIPE_INPUT_BUFFER
Definition: pipe.c:18
#define FILE_FLAG_FIRST_PIPE_INSTANCE
Definition: piperead.cpp:20
VOID PipeDestroy()
Definition: pipe.c:116
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
DWORD DSStaticRefreshParams(PipeSendFunc Send, COMM_DHCP_REQ *Req)
Definition: api.c:165
unsigned int BOOL
Definition: ntddk_ex.h:94
#define PIPE_ACCESS_DUPLEX
Definition: winbase.h:164
unsigned long DWORD
Definition: ntddk_ex.h:95
#define COMM_PIPE_OUTPUT_BUFFER
Definition: pipe.c:17
DWORD DSQueryHWInfo(PipeSendFunc Send, COMM_DHCP_REQ *Req)
Definition: api.c:68
#define ERROR_PIPE_CONNECTED
Definition: winerror.h:352
DWORD CommThrId
Definition: pipe.c:15
BOOL WINAPI DisconnectNamedPipe(HANDLE hNamedPipe)
Definition: npipe.c:961
#define WINAPI
Definition: msvc.h:20
#define PIPE_READMODE_MESSAGE
Definition: winbase.h:170
static HANDLE CommThread
Definition: pipe.c:14
#define DHCP_PIPE_NAME
DWORD DSReleaseIpAddressLease(PipeSendFunc Send, COMM_DHCP_REQ *Req)
Definition: api.c:90
DWORD DSLeaseIpAddress(PipeSendFunc Send, COMM_DHCP_REQ *Req)
Definition: api.c:36
static HANDLE CommPipe
Definition: pipe.c:14
#define DPRINT1
Definition: precomp.h:8
HANDLE WINAPI CreateNamedPipeW(LPCWSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD nMaxInstances, DWORD nOutBufferSize, DWORD nInBufferSize, DWORD nDefaultTimeOut, LPSECURITY_ATTRIBUTES lpSecurityAttributes)
Definition: npipe.c:246
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
BOOL WINAPI ConnectNamedPipe(IN HANDLE hNamedPipe, IN LPOVERLAPPED lpOverlapped)
Definition: npipe.c:701
_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
DWORD PipeSend(COMM_DHCP_REPLY *Reply)
Definition: pipe.c:21