Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenpipe.c
Go to the documentation of this file.
00001 /* $Id: $ 00002 * 00003 * COPYRIGHT: See COPYING in the top level directory 00004 * PROJECT: ReactOS kernel 00005 * FILE: subsys/system/dhcp/pipe.c 00006 * PURPOSE: DHCP client pipe 00007 * PROGRAMMER: arty 00008 */ 00009 00010 #include <rosdhcp.h> 00011 00012 #define NDEBUG 00013 #include <reactos/debug.h> 00014 00015 static HANDLE CommPipe = INVALID_HANDLE_VALUE, CommThread; 00016 DWORD CommThrId; 00017 00018 #define COMM_PIPE_OUTPUT_BUFFER sizeof(COMM_DHCP_REQ) 00019 #define COMM_PIPE_INPUT_BUFFER sizeof(COMM_DHCP_REPLY) 00020 #define COMM_PIPE_DEFAULT_TIMEOUT 1000 00021 00022 DWORD PipeSend( COMM_DHCP_REPLY *Reply ) { 00023 DWORD Written = 0; 00024 BOOL Success = 00025 WriteFile( CommPipe, 00026 Reply, 00027 sizeof(*Reply), 00028 &Written, 00029 NULL ); 00030 return Success ? Written : -1; 00031 } 00032 00033 DWORD WINAPI PipeThreadProc( LPVOID Parameter ) { 00034 DWORD BytesRead; 00035 COMM_DHCP_REQ Req; 00036 COMM_DHCP_REPLY Reply; 00037 BOOL Result, Connected; 00038 00039 while( TRUE ) { 00040 Connected = ConnectNamedPipe( CommPipe, NULL ) ? 00041 TRUE : GetLastError() == ERROR_PIPE_CONNECTED; 00042 00043 if (!Connected) { 00044 DbgPrint("DHCP: Could not connect named pipe\n"); 00045 CloseHandle( CommPipe ); 00046 CommPipe = INVALID_HANDLE_VALUE; 00047 break; 00048 } 00049 00050 Result = ReadFile( CommPipe, &Req, sizeof(Req), &BytesRead, NULL ); 00051 if( Result ) { 00052 switch( Req.Type ) { 00053 case DhcpReqQueryHWInfo: 00054 DSQueryHWInfo( PipeSend, &Req ); 00055 break; 00056 00057 case DhcpReqLeaseIpAddress: 00058 DSLeaseIpAddress( PipeSend, &Req ); 00059 break; 00060 00061 case DhcpReqReleaseIpAddress: 00062 DSReleaseIpAddressLease( PipeSend, &Req ); 00063 break; 00064 00065 case DhcpReqRenewIpAddress: 00066 DSRenewIpAddressLease( PipeSend, &Req ); 00067 break; 00068 00069 case DhcpReqStaticRefreshParams: 00070 DSStaticRefreshParams( PipeSend, &Req ); 00071 break; 00072 00073 case DhcpReqGetAdapterInfo: 00074 DSGetAdapterInfo( PipeSend, &Req ); 00075 break; 00076 00077 default: 00078 DPRINT1("Unrecognized request type %d\n", Req.Type); 00079 ZeroMemory( &Reply, sizeof( COMM_DHCP_REPLY ) ); 00080 Reply.Reply = 0; 00081 PipeSend( &Reply ); 00082 break; 00083 } 00084 } 00085 DisconnectNamedPipe( CommPipe ); 00086 } 00087 00088 return TRUE; 00089 } 00090 00091 HANDLE PipeInit() { 00092 CommPipe = CreateNamedPipeW 00093 ( DHCP_PIPE_NAME, 00094 PIPE_ACCESS_DUPLEX | FILE_FLAG_FIRST_PIPE_INSTANCE, 00095 PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, 00096 1, 00097 COMM_PIPE_OUTPUT_BUFFER, 00098 COMM_PIPE_INPUT_BUFFER, 00099 COMM_PIPE_DEFAULT_TIMEOUT, 00100 NULL ); 00101 00102 if( CommPipe == INVALID_HANDLE_VALUE ) { 00103 DbgPrint("DHCP: Could not create named pipe\n"); 00104 return CommPipe; 00105 } 00106 00107 CommThread = CreateThread( NULL, 0, PipeThreadProc, NULL, 0, &CommThrId ); 00108 00109 if( !CommThread ) { 00110 CloseHandle( CommPipe ); 00111 CommPipe = INVALID_HANDLE_VALUE; 00112 } 00113 00114 return CommPipe; 00115 } 00116 00117 VOID PipeDestroy() { 00118 CloseHandle( CommPipe ); 00119 CommPipe = INVALID_HANDLE_VALUE; 00120 } Generated on Fri May 25 2012 04:21:30 for ReactOS by
1.7.6.1
|