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
12 #include <reactos/debug.h>
14 static HANDLE CommPipe
= INVALID_HANDLE_VALUE
, CommThread
;
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
21 DWORD
PipeSend( COMM_DHCP_REPLY
*Reply
) {
29 return Success
? Written
: -1;
32 DWORD WINAPI
PipeThreadProc( LPVOID Parameter
) {
35 COMM_DHCP_REPLY Reply
;
36 BOOL Result
, Connected
;
39 Connected
= ConnectNamedPipe( CommPipe
, NULL
) ?
40 TRUE
: GetLastError() == ERROR_PIPE_CONNECTED
;
43 DbgPrint("DHCP: Could not connect named pipe\n");
44 CloseHandle( CommPipe
);
45 CommPipe
= INVALID_HANDLE_VALUE
;
49 Result
= ReadFile( CommPipe
, &Req
, sizeof(Req
), &BytesRead
, NULL
);
52 case DhcpReqQueryHWInfo
:
53 DSQueryHWInfo( PipeSend
, &Req
);
56 case DhcpReqLeaseIpAddress
:
57 DSLeaseIpAddress( PipeSend
, &Req
);
60 case DhcpReqReleaseIpAddress
:
61 DSReleaseIpAddressLease( PipeSend
, &Req
);
64 case DhcpReqRenewIpAddress
:
65 DSRenewIpAddressLease( PipeSend
, &Req
);
68 case DhcpReqStaticRefreshParams
:
69 DSStaticRefreshParams( PipeSend
, &Req
);
72 case DhcpReqGetAdapterInfo
:
73 DSGetAdapterInfo( PipeSend
, &Req
);
77 DPRINT1("Unrecognized request type %d\n", Req
.Type
);
78 ZeroMemory( &Reply
, sizeof( COMM_DHCP_REPLY
) );
84 DisconnectNamedPipe( CommPipe
);
91 CommPipe
= CreateNamedPipeW
93 PIPE_ACCESS_DUPLEX
| FILE_FLAG_FIRST_PIPE_INSTANCE
,
94 PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
| PIPE_WAIT
,
96 COMM_PIPE_OUTPUT_BUFFER
,
97 COMM_PIPE_INPUT_BUFFER
,
98 COMM_PIPE_DEFAULT_TIMEOUT
,
101 if( CommPipe
== INVALID_HANDLE_VALUE
) {
102 DbgPrint("DHCP: Could not create named pipe\n");
106 CommThread
= CreateThread( NULL
, 0, PipeThreadProc
, NULL
, 0, &CommThrId
);
109 CloseHandle( CommPipe
);
110 CommPipe
= INVALID_HANDLE_VALUE
;
117 CloseHandle( CommPipe
);
118 CommPipe
= INVALID_HANDLE_VALUE
;