3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * FILE: subsys/system/dhcp/pipe.c
6 * PURPOSE: DHCP client pipe
13 #include <reactos/debug.h>
15 static HANDLE CommPipe
= INVALID_HANDLE_VALUE
, CommThread
;
18 #define COMM_PIPE_OUTPUT_BUFFER sizeof(COMM_DHCP_REQ)
19 #define COMM_PIPE_INPUT_BUFFER sizeof(COMM_DHCP_REPLY)
20 #define COMM_PIPE_DEFAULT_TIMEOUT 1000
22 DWORD
PipeSend( COMM_DHCP_REPLY
*Reply
) {
30 return Success
? Written
: -1;
33 DWORD WINAPI
PipeThreadProc( LPVOID Parameter
) {
34 DWORD BytesRead
, BytesWritten
;
36 COMM_DHCP_REPLY Reply
;
37 BOOL Result
, Connection
;
39 while( (Connection
= ConnectNamedPipe( CommPipe
, NULL
)) ) {
40 Result
= ReadFile( CommPipe
, &Req
, sizeof(Req
), &BytesRead
, NULL
);
43 case DhcpReqQueryHWInfo
:
44 BytesWritten
= DSQueryHWInfo( PipeSend
, &Req
);
47 case DhcpReqLeaseIpAddress
:
48 BytesWritten
= DSLeaseIpAddress( PipeSend
, &Req
);
51 case DhcpReqReleaseIpAddress
:
52 BytesWritten
= DSReleaseIpAddressLease( PipeSend
, &Req
);
55 case DhcpReqRenewIpAddress
:
56 BytesWritten
= DSRenewIpAddressLease( PipeSend
, &Req
);
59 case DhcpReqStaticRefreshParams
:
60 BytesWritten
= DSStaticRefreshParams( PipeSend
, &Req
);
63 case DhcpReqGetAdapterInfo
:
64 BytesWritten
= DSGetAdapterInfo( PipeSend
, &Req
);
68 DPRINT1("Unrecognized request type %d\n", Req
.Type
);
69 ZeroMemory( &Reply
, sizeof( COMM_DHCP_REPLY
) );
71 BytesWritten
= PipeSend( &Reply
);
75 DisconnectNamedPipe( CommPipe
);
82 CommPipe
= CreateNamedPipe
84 PIPE_ACCESS_DUPLEX
| FILE_FLAG_FIRST_PIPE_INSTANCE
,
85 PIPE_TYPE_MESSAGE
| PIPE_READMODE_MESSAGE
| PIPE_WAIT
,
87 COMM_PIPE_OUTPUT_BUFFER
,
88 COMM_PIPE_INPUT_BUFFER
,
89 COMM_PIPE_DEFAULT_TIMEOUT
,
92 if( CommPipe
== INVALID_HANDLE_VALUE
) {
93 DbgPrint("DHCP: Could not create named pipe\n");
97 CommThread
= CreateThread( NULL
, 0, PipeThreadProc
, NULL
, 0, &CommThrId
);
100 CloseHandle( CommPipe
);
101 CommPipe
= INVALID_HANDLE_VALUE
;
108 CloseHandle( CommPipe
);
109 CommPipe
= INVALID_HANDLE_VALUE
;