ReactOS.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
March
February
January
2007
December
November
October
September
August
July
June
May
April
March
February
January
2006
December
November
October
September
August
July
June
May
April
March
February
January
2005
December
November
October
September
August
July
June
May
April
March
February
January
2004
December
November
October
September
August
July
June
May
April
March
February
List overview
Download
Ros-diffs
April 2020
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008
----- 2007 -----
December 2007
November 2007
October 2007
September 2007
August 2007
July 2007
June 2007
May 2007
April 2007
March 2007
February 2007
January 2007
----- 2006 -----
December 2006
November 2006
October 2006
September 2006
August 2006
July 2006
June 2006
May 2006
April 2006
March 2006
February 2006
January 2006
----- 2005 -----
December 2005
November 2005
October 2005
September 2005
August 2005
July 2005
June 2005
May 2005
April 2005
March 2005
February 2005
January 2005
----- 2004 -----
December 2004
November 2004
October 2004
September 2004
August 2004
July 2004
June 2004
May 2004
April 2004
March 2004
February 2004
ros-diffs@reactos.org
45 participants
395 discussions
Start a n
N
ew thread
[reactos] 01/01: [ROSAUTOTEST] Change custom auto_array_ptr to std::unique_ptr
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=9ff3adb7d7c6636a1d040…
commit 9ff3adb7d7c6636a1d040d8e53f7203e9d1815a3 Author: Victor Perevertkin <victor.perevertkin(a)reactos.org> AuthorDate: Thu Apr 9 02:08:10 2020 +0300 Commit: Victor Perevertkin <victor.perevertkin(a)reactos.org> CommitDate: Thu Apr 9 02:08:10 2020 +0300 [ROSAUTOTEST] Change custom auto_array_ptr to std::unique_ptr --- modules/rostests/rosautotest/CMakeLists.txt | 1 + modules/rostests/rosautotest/CProcess.cpp | 6 +-- modules/rostests/rosautotest/CWebService.cpp | 30 ++++++------- modules/rostests/rosautotest/auto_array_ptr.h | 64 --------------------------- modules/rostests/rosautotest/precomp.h | 2 +- 5 files changed, 20 insertions(+), 83 deletions(-) diff --git a/modules/rostests/rosautotest/CMakeLists.txt b/modules/rostests/rosautotest/CMakeLists.txt index 21f0cdd5e23..f6b29583f6d 100644 --- a/modules/rostests/rosautotest/CMakeLists.txt +++ b/modules/rostests/rosautotest/CMakeLists.txt @@ -21,6 +21,7 @@ list(APPEND SOURCE precomp.h) add_executable(rosautotest ${SOURCE} ${CMAKE_CURRENT_BINARY_DIR}/rosautotestmsg.rc) +set_property(TARGET rosautotest PROPERTY CXX_STANDARD 11) set_module_type(rosautotest win32cui UNICODE) add_importlibs(rosautotest advapi32 shell32 user32 wininet msvcrt kernel32 ntdll) add_pch(rosautotest precomp.h SOURCE) diff --git a/modules/rostests/rosautotest/CProcess.cpp b/modules/rostests/rosautotest/CProcess.cpp index e462456564c..b7ca0603817 100644 --- a/modules/rostests/rosautotest/CProcess.cpp +++ b/modules/rostests/rosautotest/CProcess.cpp @@ -18,11 +18,11 @@ */ CProcess::CProcess(const wstring& CommandLine, LPSTARTUPINFOW StartupInfo) { - auto_array_ptr<WCHAR> CommandLinePtr(new WCHAR[CommandLine.size() + 1]); + unique_ptr<WCHAR[]> CommandLinePtr(new WCHAR[CommandLine.size() + 1]); - wcscpy(CommandLinePtr, CommandLine.c_str()); + wcscpy(CommandLinePtr.get(), CommandLine.c_str()); - if(!CreateProcessW(NULL, CommandLinePtr, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, StartupInfo, &m_ProcessInfo)) + if(!CreateProcessW(NULL, CommandLinePtr.get(), NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS, NULL, NULL, StartupInfo, &m_ProcessInfo)) TESTEXCEPTION("CreateProcessW failed\n"); } diff --git a/modules/rostests/rosautotest/CWebService.cpp b/modules/rostests/rosautotest/CWebService.cpp index 85ead6d9135..59d856a52d1 100644 --- a/modules/rostests/rosautotest/CWebService.cpp +++ b/modules/rostests/rosautotest/CWebService.cpp @@ -66,7 +66,7 @@ CWebService::DoRequest(const string& InputData) { const WCHAR szHeaders[] = L"Content-Type: application/x-www-form-urlencoded"; - auto_array_ptr<char> Data; + unique_ptr<char[]> Data; DWORD DataLength; /* Post our test results to the web service */ @@ -76,9 +76,9 @@ CWebService::DoRequest(const string& InputData) FATAL("HttpOpenRequestW failed\n"); Data.reset(new char[InputData.size() + 1]); - strcpy(Data, InputData.c_str()); + strcpy(Data.get(), InputData.c_str()); - if(!HttpSendRequestW(m_hHTTPRequest, szHeaders, lstrlenW(szHeaders), Data, (DWORD)InputData.size())) + if(!HttpSendRequestW(m_hHTTPRequest, szHeaders, lstrlenW(szHeaders), Data.get(), (DWORD)InputData.size())) FATAL("HttpSendRequestW failed\n"); /* Get the response */ @@ -87,7 +87,7 @@ CWebService::DoRequest(const string& InputData) Data.reset(new char[DataLength + 1]); - if(!InternetReadFile(m_hHTTPRequest, Data, DataLength, &DataLength)) + if(!InternetReadFile(m_hHTTPRequest, Data.get(), DataLength, &DataLength)) FATAL("InternetReadFile failed\n"); Data[DataLength] = 0; @@ -104,7 +104,7 @@ CWebService::DoRequest(const string& InputData) void CWebService::Finish(const char* TestType) { - auto_array_ptr<char> Response; + unique_ptr<char[]> Response; string Data; stringstream ss; @@ -120,9 +120,9 @@ CWebService::Finish(const char* TestType) Response.reset(DoRequest(Data)); - if (strcmp(Response, "OK")) + if (strcmp(Response.get(), "OK")) { - ss << "When finishing the test run, the server responded:" << endl << Response << endl; + ss << "When finishing the test run, the server responded:" << endl << Response.get() << endl; SSEXCEPTION; } } @@ -178,7 +178,7 @@ CWebService::GetTestID(const char* TestType) PCHAR CWebService::GetSuiteID(const char* TestType, CTestInfo* TestInfo) { - auto_array_ptr<char> SuiteID; + unique_ptr<char[]> SuiteID; string Data; Data = "action=getsuiteid"; @@ -193,11 +193,11 @@ CWebService::GetSuiteID(const char* TestType, CTestInfo* TestInfo) SuiteID.reset(DoRequest(Data)); /* Verify that this is really a number */ - if(!IsNumber(SuiteID)) + if(!IsNumber(SuiteID.get())) { stringstream ss; - ss << "Expected Suite ID, but received:" << endl << SuiteID << endl; + ss << "Expected Suite ID, but received:" << endl << SuiteID.get() << endl; SSEXCEPTION; } @@ -216,8 +216,8 @@ CWebService::GetSuiteID(const char* TestType, CTestInfo* TestInfo) void CWebService::Submit(const char* TestType, CTestInfo* TestInfo) { - auto_array_ptr<char> Response; - auto_array_ptr<char> SuiteID; + unique_ptr<char[]> Response; + unique_ptr<char[]> SuiteID; string Data; stringstream ss; @@ -233,15 +233,15 @@ CWebService::Submit(const char* TestType, CTestInfo* TestInfo) Data += "&testid="; Data += m_TestID; Data += "&suiteid="; - Data += SuiteID; + Data += SuiteID.get(); Data += "&log="; Data += EscapeString(TestInfo->Log); Response.reset(DoRequest(Data)); - if (strcmp(Response, "OK")) + if (strcmp(Response.get(), "OK")) { - ss << "When submitting the result, the server responded:" << endl << Response << endl; + ss << "When submitting the result, the server responded:" << endl << Response.get() << endl; SSEXCEPTION; } } diff --git a/modules/rostests/rosautotest/auto_array_ptr.h b/modules/rostests/rosautotest/auto_array_ptr.h deleted file mode 100644 index f53c3b04552..00000000000 --- a/modules/rostests/rosautotest/auto_array_ptr.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * PROJECT: ReactOS Automatic Testing Utility - * LICENSE: GPL-2.0+ (
https://spdx.org/licenses/GPL-2.0+
) - * PURPOSE: Template similar to std::auto_ptr for arrays - * COPYRIGHT: Copyright 2009 Colin Finck (colin(a)reactos.org) - */ - -template<typename Type> -class auto_array_ptr -{ -private: - Type* m_Ptr; - -public: - typedef Type element_type; - - /* Construct an auto_array_ptr from a pointer */ - explicit auto_array_ptr(Type* Ptr = 0) throw() - : m_Ptr(Ptr) - { - } - - /* Construct an auto_array_ptr from an existing auto_array_ptr */ - auto_array_ptr(auto_array_ptr<Type>& Right) throw() - : m_Ptr(Right.release()) - { - } - - /* Destruct the auto_array_ptr and remove the corresponding array from memory */ - ~auto_array_ptr() throw() - { - delete[] m_Ptr; - } - - /* Get the pointer address */ - Type* get() const throw() - { - return m_Ptr; - } - - /* Release the pointer */ - Type* release() throw() - { - Type* Tmp = m_Ptr; - m_Ptr = 0; - - return Tmp; - } - - /* Reset to a new pointer */ - void reset(Type* Ptr = 0) throw() - { - if(Ptr != m_Ptr) - delete[] m_Ptr; - - m_Ptr = Ptr; - } - - /* Simulate all the functionality of real arrays by casting the auto_array_ptr to Type* on demand */ - operator Type*() const throw() - { - return m_Ptr; - } -}; diff --git a/modules/rostests/rosautotest/precomp.h b/modules/rostests/rosautotest/precomp.h index 5e0f05b5794..0f46388a5e2 100644 --- a/modules/rostests/rosautotest/precomp.h +++ b/modules/rostests/rosautotest/precomp.h @@ -33,7 +33,7 @@ using namespace std; #include <reactos/buildno.h> /* Class includes */ -#include "auto_array_ptr.h" +// #include "auto_array_ptr.h" #include "CConfiguration.h" #include "CFatalException.h" #include "CInvalidParameterException.h"
4 years, 8 months
1
0
0
0
[reactos] 01/01: [User32] Fix Dialog Hang
by James Tabor
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=ee3ee2a65f66016063e75…
commit ee3ee2a65f66016063e7537b78e2dd7572a616a8 Author: James Tabor <james.tabor(a)reactos.org> AuthorDate: Wed Apr 8 14:49:38 2020 -0500 Commit: James Tabor <james.tabor(a)reactos.org> CommitDate: Wed Apr 8 14:49:38 2020 -0500 [User32] Fix Dialog Hang Patch by JIRA contributor I_Kill_Bugs. See CORE-5078. Also:
https://bugs.winehq.org/show_bug.cgi?id=48749
--- win32ss/user/user32/windows/dialog.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/win32ss/user/user32/windows/dialog.c b/win32ss/user/user32/windows/dialog.c index 1acb4f55306..c853e5f8ebd 100644 --- a/win32ss/user/user32/windows/dialog.c +++ b/win32ss/user/user32/windows/dialog.c @@ -936,8 +936,14 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate, if (IsWindowEnabled( owner )) { + HWND captured = NULL; disabled_owner = owner; EnableWindow( disabled_owner, FALSE ); + + captured = GetCapture(); + + if (captured) + SendMessageW(captured, WM_CANCELMODE, 0, 0); } } *modal_owner = owner;
4 years, 8 months
1
0
0
0
[reactos] 01/01: [SHIMLIB] Fix gcc8 build crashing when using shims
by Mark Jansen
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=6db3d8898475dbb7ae598…
commit 6db3d8898475dbb7ae598c3be520b4688ef21647 Author: Mark Jansen <mark.jansen(a)reactos.org> AuthorDate: Tue Apr 7 20:47:47 2020 +0200 Commit: Mark Jansen <mark.jansen(a)reactos.org> CommitDate: Tue Apr 7 20:47:47 2020 +0200 [SHIMLIB] Fix gcc8 build crashing when using shims --- dll/appcompat/shims/shimlib/shimlib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dll/appcompat/shims/shimlib/shimlib.c b/dll/appcompat/shims/shimlib/shimlib.c index 7ab8aa86e37..1d791a05bc5 100644 --- a/dll/appcompat/shims/shimlib/shimlib.c +++ b/dll/appcompat/shims/shimlib/shimlib.c @@ -100,7 +100,7 @@ BOOL ShimLib_StrAEqualsWNC(PCSTR szString, PCWSTR wszString) #endif -_SHMALLOC(".shm") SHIMREG _shim_start = { 0 }; +_SHMALLOC(".shm$AAA") SHIMREG _shim_start = { 0 }; _SHMALLOC(".shm$ZZZ") SHIMREG _shim_end = { 0 }; @@ -112,7 +112,7 @@ PHOOKAPI WINAPI ShimLib_GetHookAPIs(IN LPCSTR szCommandLine, IN LPCWSTR wszShimN { PSHIMREG ps = &_shim_start; ps++; - for (; ps != &_shim_end; ps++) + for (; ps < &_shim_end; ps++) { if (ps->GetHookAPIs != NULL && ps->ShimName != NULL) {
4 years, 8 months
1
0
0
0
[reactos] 06/06: [TCPIP] Remove duplicate declarations from ticonsts.h
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=167fa2c26ab4f1a3b8e51…
commit 167fa2c26ab4f1a3b8e51e6e9fa955030fd75a89 Author: Victor Perevertkin <victor.perevertkin(a)reactos.org> AuthorDate: Sat Dec 21 04:02:47 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Apr 7 05:32:40 2020 +0300 [TCPIP] Remove duplicate declarations from ticonsts.h --- drivers/network/tcpip/include/ticonsts.h | 24 ------------------------ sdk/lib/drivers/ip/network/loopback.c | 13 ++++++++++--- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/drivers/network/tcpip/include/ticonsts.h b/drivers/network/tcpip/include/ticonsts.h index 6d86b6787d5..cf125d99b10 100644 --- a/drivers/network/tcpip/include/ticonsts.h +++ b/drivers/network/tcpip/include/ticonsts.h @@ -32,31 +32,7 @@ #define TCPIP_PROTOCOL_NAME L"Tcpip" #endif /* _NTTEST_ */ -/* TCP/UDP/RawIP IOCTL code definitions */ - -#define FSCTL_TCP_BASE FILE_DEVICE_NETWORK - -#define _TCP_CTL_CODE(Function, Method, Access) \ - CTL_CODE(FSCTL_TCP_BASE, Function, Method, Access) - -#define IOCTL_TCP_QUERY_INFORMATION_EX \ - _TCP_CTL_CODE(0, METHOD_NEITHER, FILE_ANY_ACCESS) - -#define IOCTL_TCP_SET_INFORMATION_EX \ - _TCP_CTL_CODE(1, METHOD_BUFFERED, FILE_WRITE_ACCESS) - -#define IOCTL_SET_IP_ADDRESS \ - _TCP_CTL_CODE(14, METHOD_BUFFERED, FILE_WRITE_ACCESS) - -#define IOCTL_DELETE_IP_ADDRESS \ - _TCP_CTL_CODE(16, METHOD_BUFFERED, FILE_WRITE_ACCESS) - /* Unique error values for log entries */ #define TI_ERROR_DRIVERENTRY 0 -/* Internal status codes */ -#define IP_SUCCESS 0x0000 /* Successful */ -#define IP_NO_RESOURCES 0x0001 /* Not enough free resources */ -#define IP_NO_ROUTE_TO_DESTINATION 0x0002 /* No route to destination */ - /* EOF */ diff --git a/sdk/lib/drivers/ip/network/loopback.c b/sdk/lib/drivers/ip/network/loopback.c index e44cc69d3d7..c859ac7d2a8 100644 --- a/sdk/lib/drivers/ip/network/loopback.c +++ b/sdk/lib/drivers/ip/network/loopback.c @@ -36,7 +36,7 @@ VOID LoopTransmit( * NdisPacket = Pointer to NDIS packet to send * Offset = Offset in packet where packet data starts * LinkAddress = Pointer to link address - * Type = LAN protocol type (unused) + * Type = LAN protocol type */ { PCHAR PacketBuffer; @@ -49,6 +49,13 @@ VOID LoopTransmit( ASSERT_KM_POINTER(PC(NdisPacket)); ASSERT_KM_POINTER(PC(NdisPacket)->DLComplete); + if (Type != LAN_PROTO_IPv4) + { + TI_DbgPrint(MAX_TRACE, ("Received unsupported protocol %u\n", Type)); + PC(NdisPacket)->DLComplete(PC(NdisPacket)->Context, NdisPacket, NDIS_STATUS_NOT_SUPPORTED); + return; + } + TI_DbgPrint(MAX_TRACE, ("Called (NdisPacket = %x)\n", NdisPacket)); GetDataPtr( NdisPacket, 0, &PacketBuffer, &PacketLength ); @@ -112,7 +119,7 @@ NDIS_STATUS LoopRegisterAdapter( Loopback = IPCreateInterface(&BindInfo); if (!Loopback) return NDIS_STATUS_RESOURCES; - + Loopback->MTU = 16384; Loopback->Name.Buffer = L"Loopback"; @@ -124,7 +131,7 @@ NDIS_STATUS LoopRegisterAdapter( AddrInitIPv4(&Loopback->Broadcast, LOOPBACK_BCASTADDR_IPv4); IPRegisterInterface(Loopback); - + IPAddInterfaceRoute(Loopback); TI_DbgPrint(MAX_TRACE, ("Leaving.\n"));
4 years, 8 months
1
0
0
0
[reactos] 05/06: [SDK][IP] Pass IP options to ReceiveDatagramHandler
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=d5ad2057d7f9ef52ae321…
commit d5ad2057d7f9ef52ae3214ce78c6d6bbabaee3b0 Author: Victor Perevertkin <victor.perevertkin(a)reactos.org> AuthorDate: Fri Dec 20 23:19:41 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Apr 7 05:32:40 2020 +0300 [SDK][IP] Pass IP options to ReceiveDatagramHandler --- sdk/lib/drivers/ip/transport/datagram/datagram.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/sdk/lib/drivers/ip/transport/datagram/datagram.c b/sdk/lib/drivers/ip/transport/datagram/datagram.c index c910ed6c386..13acca1f181 100644 --- a/sdk/lib/drivers/ip/transport/datagram/datagram.c +++ b/sdk/lib/drivers/ip/transport/datagram/datagram.c @@ -74,8 +74,6 @@ DGDeliverData( */ { KIRQL OldIrql; - PTDI_IND_RECEIVE_DATAGRAM ReceiveHandler; - PVOID HandlerContext; LONG AddressLength; PVOID SourceAddress; ULONG BytesTaken; @@ -164,15 +162,22 @@ DGDeliverData( } else if (AddrFile->RegisteredReceiveDatagramHandler) { - TI_DbgPrint(MAX_TRACE, ("Calling receive event handler.\n")); + PTDI_IND_RECEIVE_DATAGRAM ReceiveHandler = AddrFile->ReceiveDatagramHandler; + PVOID HandlerContext = AddrFile->ReceiveDatagramHandlerContext; + PVOID OptionsData = NULL; + INT32 OptionsSize = 0; - ReceiveHandler = AddrFile->ReceiveDatagramHandler; - HandlerContext = AddrFile->ReceiveDatagramHandlerContext; + TI_DbgPrint(MAX_TRACE, ("Calling receive event handler.\n")); if (SrcAddress->Type == IP_ADDRESS_V4) { AddressLength = sizeof(IPv4_RAW_ADDRESS); SourceAddress = &SrcAddress->Address.IPv4Address; + OptionsSize = IPPacket->HeaderSize - sizeof(IPv4_HEADER); + if (OptionsSize > 0) + { + OptionsData = (PUCHAR)IPPacket->Header + sizeof(IPv4_HEADER); + } } else /* (Address->Type == IP_ADDRESS_V6) */ { @@ -183,11 +188,13 @@ DGDeliverData( ReferenceObject(AddrFile); UnlockObject(AddrFile, OldIrql); + TI_DbgPrint(MIN_TRACE, ("OptionsSize %d DataSize: %u\n", OptionsSize, DataSize)); + Status = (*ReceiveHandler)(HandlerContext, AddressLength, SourceAddress, - 0, - NULL, + OptionsSize, + OptionsData, TDI_RECEIVE_ENTIRE_MESSAGE, DataSize, DataSize, @@ -209,7 +216,6 @@ DGDeliverData( TI_DbgPrint(MAX_TRACE, ("Leaving.\n")); } - VOID DGReceiveComplete(PVOID Context, NTSTATUS Status, ULONG Count) { PDATAGRAM_RECEIVE_REQUEST ReceiveRequest = (PDATAGRAM_RECEIVE_REQUEST)Context;
4 years, 8 months
1
0
0
0
[reactos] 04/06: [TCPIP] Implement IOCTL_ICMP_ECHO_REQUEST in tcpip.sys Also clean up ICMP handling code in sdk/lib/drivers/ip CORE-10760
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=740a859e922e1a91a8822…
commit 740a859e922e1a91a88226b53acfd48f57c1767b Author: Victor Perevertkin <victor.perevertkin(a)reactos.org> AuthorDate: Mon Nov 18 20:55:10 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Apr 7 05:32:40 2020 +0300 [TCPIP] Implement IOCTL_ICMP_ECHO_REQUEST in tcpip.sys Also clean up ICMP handling code in sdk/lib/drivers/ip CORE-10760 --- drivers/network/tcpip/CMakeLists.txt | 1 + drivers/network/tcpip/include/icmp.h | 22 +- drivers/network/tcpip/include/precomp.h | 2 + drivers/network/tcpip/include/rawip.h | 10 + drivers/network/tcpip/tcpip/icmp.c | 431 +++++++++++++++++++++++++++++ drivers/network/tcpip/tcpip/main.c | 9 +- media/doc/README.WINE | 1 - sdk/lib/drivers/ip/network/icmp.c | 268 +++--------------- sdk/lib/drivers/ip/transport/rawip/rawip.c | 2 +- 9 files changed, 505 insertions(+), 241 deletions(-) diff --git a/drivers/network/tcpip/CMakeLists.txt b/drivers/network/tcpip/CMakeLists.txt index 0dd5a5271e0..53b2c571cff 100644 --- a/drivers/network/tcpip/CMakeLists.txt +++ b/drivers/network/tcpip/CMakeLists.txt @@ -17,6 +17,7 @@ list(APPEND SOURCE tcpip/cinfo.c tcpip/dispatch.c tcpip/fileobjs.c + tcpip/icmp.c tcpip/iinfo.c tcpip/info.c tcpip/lock.c diff --git a/drivers/network/tcpip/include/icmp.h b/drivers/network/tcpip/include/icmp.h index e0902e02737..eb0f9b3faed 100644 --- a/drivers/network/tcpip/include/icmp.h +++ b/drivers/network/tcpip/include/icmp.h @@ -7,12 +7,15 @@ #pragma once +#include <pshpack1.h> typedef struct ICMP_HEADER { - UCHAR Type; /* ICMP message type */ - UCHAR Code; /* ICMP message code */ - USHORT Checksum; /* ICMP message checksum */ - ULONG Unused; /* ICMP unused */ + UINT8 Type; /* ICMP message type */ + UINT8 Code; /* ICMP message code */ + UINT16 Checksum; /* ICMP message checksum */ + UINT16 Identifier; /* ICMP Echo message identifier */ + UINT16 Seq; /* ICMP Echo message sequence num */ } ICMP_HEADER, *PICMP_HEADER; +#include <poppack.h> /* ICMP message types */ #define ICMP_TYPE_ECHO_REPLY 0 /* Echo reply */ @@ -48,6 +51,12 @@ typedef struct ICMP_HEADER { /* ICMP codes for ICMP_TYPE_PARAMETER */ #define ICMP_CODE_TP_POINTER 1 /* Pointer indicates the error */ +NTSTATUS +DispEchoRequest( + PDEVICE_OBJECT DeviceObject, + PIRP Irp, + PIO_STACK_LOCATION IrpSp); + NTSTATUS ICMPSendDatagram( PADDRESS_FILE AddrFile, PTDI_CONNECTION_INFORMATION ConnInfo, @@ -63,11 +72,6 @@ VOID ICMPReceive( PIP_INTERFACE Interface, PIP_PACKET IPPacket); -VOID ICMPTransmit( - PIP_PACKET IPPacket, - PIP_TRANSMIT_COMPLETE Complete, - PVOID Context); - VOID ICMPReply( PIP_INTERFACE Interface, PIP_PACKET IPPacket, diff --git a/drivers/network/tcpip/include/precomp.h b/drivers/network/tcpip/include/precomp.h index a96c4a51c3e..3055bc57bd3 100644 --- a/drivers/network/tcpip/include/precomp.h +++ b/drivers/network/tcpip/include/precomp.h @@ -15,7 +15,9 @@ #include <tilists.h> #include <lock.h> #include <interface.h> +#include <fileobjs.h> #include <chew/chew.h> #include <pseh/pseh2.h> +#include <psdk/ipexport.h> #endif /* _TCPIP_PCH_ */ diff --git a/drivers/network/tcpip/include/rawip.h b/drivers/network/tcpip/include/rawip.h index 821fdb4f868..7a5feba27f8 100644 --- a/drivers/network/tcpip/include/rawip.h +++ b/drivers/network/tcpip/include/rawip.h @@ -36,4 +36,14 @@ NTSTATUS AddGenericHeaderIPv4( UINT ExtraLength, PVOID *NextHeader ); +NTSTATUS BuildRawIpPacket( + PADDRESS_FILE AddrFile, + PIP_PACKET Packet, + PIP_ADDRESS RemoteAddress, + USHORT RemotePort, + PIP_ADDRESS LocalAddress, + USHORT LocalPort, + PCHAR DataBuffer, + UINT DataLen); + /* EOF */ diff --git a/drivers/network/tcpip/tcpip/icmp.c b/drivers/network/tcpip/tcpip/icmp.c new file mode 100644 index 00000000000..7603e2551a5 --- /dev/null +++ b/drivers/network/tcpip/tcpip/icmp.c @@ -0,0 +1,431 @@ +/* + * PROJECT: ReactOS TCP/IP protocol driver + * LICENCE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later
) + * PURPOSE: ICMP functions implementation + * COPYRIGHT: 2019 Victor Perevertkin (victor.perevertkin(a)reactos.org) + */ + +#include "precomp.h" +#include <checksum.h> + + +#define UINT16_MAX (65535U) + +typedef struct _ICMP_PACKET_CONTEXT +{ + TDI_REQUEST TdiRequest; + KDPC TimeoutDpc; + KEVENT InitializationFinishedEvent; + KEVENT DatagramProcessedEvent; + LARGE_INTEGER TimerResolution; + INT64 StartTicks; + PIRP Irp; + PUCHAR CurrentReply; + UINT32 RemainingSize; + LONG nReplies; + PIO_WORKITEM FinishWorker; + KTIMER TimeoutTimer; +} ICMP_PACKET_CONTEXT, *PICMP_PACKET_CONTEXT; + +static volatile INT16 IcmpSequence = 0; + +static +UINT32 +GetReplyStatus(PICMP_HEADER IcmpHeader) +{ + switch (IcmpHeader->Type) + { + case ICMP_TYPE_ECHO_REPLY: + return IP_SUCCESS; + case ICMP_TYPE_DEST_UNREACH: + switch (IcmpHeader->Code) + { + case ICMP_CODE_DU_NET_UNREACH: + return IP_DEST_NET_UNREACHABLE; + case ICMP_CODE_DU_HOST_UNREACH: + return IP_DEST_HOST_UNREACHABLE; + case ICMP_CODE_DU_PROTOCOL_UNREACH: + return IP_DEST_PROT_UNREACHABLE; + case ICMP_CODE_DU_PORT_UNREACH: + return IP_DEST_PORT_UNREACHABLE; + case ICMP_CODE_DU_FRAG_DF_SET: + return IP_DEST_NET_UNREACHABLE; + case ICMP_CODE_DU_SOURCE_ROUTE_FAILED: + return IP_BAD_ROUTE; + default: + return IP_DEST_NET_UNREACHABLE; + } + case ICMP_TYPE_SOURCE_QUENCH: + return IP_SOURCE_QUENCH; + case ICMP_TYPE_TIME_EXCEEDED: + if (IcmpHeader->Code == ICMP_CODE_TE_REASSEMBLY) + return IP_TTL_EXPIRED_REASSEM; + else + return IP_TTL_EXPIRED_TRANSIT; + case ICMP_TYPE_PARAMETER: + return IP_PARAM_PROBLEM; + default: + return IP_REQ_TIMED_OUT; + } +} + +static +VOID +ClearReceiveHandler( + _In_ PADDRESS_FILE AddrFile) +{ + KIRQL OldIrql; + + LockObject(AddrFile, &OldIrql); + AddrFile->RegisteredReceiveDatagramHandler = FALSE; + UnlockObject(AddrFile, OldIrql); +} + +IO_WORKITEM_ROUTINE EndRequestHandler; + +VOID +NTAPI +EndRequestHandler( + PDEVICE_OBJECT DeviceObject, + PVOID _Context) +{ + PICMP_PACKET_CONTEXT Context = (PICMP_PACKET_CONTEXT)_Context; + PIO_STACK_LOCATION CurrentStack; + PIRP Irp; + UINT32 nReplies; + KIRQL OldIrql; + + KeWaitForSingleObject(&Context->DatagramProcessedEvent, Executive, KernelMode, FALSE, NULL); + + TI_DbgPrint(DEBUG_ICMP, ("Finishing request Context: %p\n", Context)); + + Irp = Context->Irp; + CurrentStack = IoGetCurrentIrpStackLocation(Irp); + + if (Context->nReplies > 0) + { + ((PICMP_ECHO_REPLY)Irp->AssociatedIrp.SystemBuffer)->Reserved = Context->nReplies; + Irp->IoStatus.Status = STATUS_SUCCESS; + Irp->IoStatus.Information = CurrentStack->Parameters.DeviceIoControl.OutputBufferLength; + } + else + { + PICMP_ECHO_REPLY ReplyBuffer = (PICMP_ECHO_REPLY)Irp->AssociatedIrp.SystemBuffer; + RtlZeroMemory(ReplyBuffer, sizeof(*ReplyBuffer)); + ReplyBuffer->Status = IP_REQ_TIMED_OUT; + + Irp->IoStatus.Status = STATUS_TIMEOUT; + Irp->IoStatus.Information = sizeof(*ReplyBuffer); + } + + // for debugging + nReplies = ((PICMP_ECHO_REPLY)Irp->AssociatedIrp.SystemBuffer)->Reserved; + + // taken from dispatch.c:IRPFinish + IoAcquireCancelSpinLock(&OldIrql); + IoSetCancelRoutine(Irp, NULL); + IoReleaseCancelSpinLock(OldIrql); + IoCompleteRequest(Irp, IO_NETWORK_INCREMENT); + + { + NTSTATUS _Status = FileCloseAddress(&Context->TdiRequest); + ASSERT(NT_SUCCESS(_Status)); + } + + IoFreeWorkItem(Context->FinishWorker); + ExFreePoolWithTag(Context, OUT_DATA_TAG); + + TI_DbgPrint(DEBUG_ICMP, ("Leaving, nReplies: %u\n", nReplies)); +} + +NTSTATUS +NTAPI +ReceiveDatagram( + _In_opt_ PVOID TdiEventContext, + _In_ LONG SourceAddressLength, + _In_reads_bytes_(SourceAddressLength) PVOID SourceAddress, + _In_ LONG OptionsLength, + _In_reads_bytes_opt_(OptionsLength) PVOID Options, + _In_ ULONG ReceiveDatagramFlags, + _In_ ULONG BytesIndicated, + _In_ ULONG BytesAvailable, + _Out_ ULONG *OutBytesTaken, + _In_ PVOID Tsdu, + _Out_opt_ PIRP *IoRequestPacket) +{ + PICMP_PACKET_CONTEXT Context = TdiEventContext; + PIPv4_HEADER IpHeader = Tsdu; + UINT16 IpHeaderSize = sizeof(IPv4_HEADER) + OptionsLength; + PICMP_HEADER IcmpHeader = (PICMP_HEADER)((PUCHAR)Tsdu + IpHeaderSize); + + PVOID DataBuffer = (PUCHAR)Tsdu + IpHeaderSize + sizeof(ICMP_HEADER); + INT32 DataSize = min(BytesAvailable, UINT16_MAX) - IpHeaderSize - sizeof(ICMP_HEADER); + + INT64 CurrentTime; + UINT32 RoundTripTime; + PICMP_ECHO_REPLY CurrentReply; + PUCHAR CurrentUserBuffer; + + // do not handle echo requests + if (DataSize >= 0 && IcmpHeader->Type == ICMP_TYPE_ECHO_REQUEST) + { + return STATUS_SUCCESS; + } + + KeWaitForSingleObject(&Context->InitializationFinishedEvent, Executive, KernelMode, FALSE, NULL); + KeClearEvent(&Context->DatagramProcessedEvent); + + ASSERT(SourceAddressLength == sizeof(IPAddr)); + TI_DbgPrint(DEBUG_ICMP, ("Received datagram Context: 0x%p\n", TdiEventContext)); + + CurrentTime = KeQueryPerformanceCounter(NULL).QuadPart; + RoundTripTime = (CurrentTime - Context->StartTicks) * 1000 / Context->TimerResolution.QuadPart; + CurrentReply = (PICMP_ECHO_REPLY)Context->CurrentReply; + + if (Context->RemainingSize >= sizeof(ICMP_ECHO_REPLY) && DataSize >= 0) + { + TI_DbgPrint(DEBUG_ICMP, ("RemainingSize: %u, RoundTripTime: %u\n", Context->RemainingSize, RoundTripTime)); + + memcpy(&CurrentReply->Address, SourceAddress, sizeof(CurrentReply->Address)); + CurrentReply->Status = GetReplyStatus(IcmpHeader); + CurrentReply->RoundTripTime = RoundTripTime; + CurrentReply->Reserved = 0; + CurrentReply->Data = NULL; + CurrentReply->DataSize = 0; + CurrentReply->Options.Ttl = IpHeader->Ttl; + CurrentReply->Options.Tos = IpHeader->Tos; + CurrentReply->Options.Flags = IpHeader->FlagsFragOfs >> 13; + CurrentReply->Options.OptionsData = NULL; + CurrentReply->Options.OptionsSize = 0; + + Context->RemainingSize -= sizeof(ICMP_ECHO_REPLY); + Context->CurrentReply += sizeof(ICMP_ECHO_REPLY); + } + + CurrentUserBuffer = (PUCHAR)Context->Irp->UserBuffer + (Context->CurrentReply - (PUCHAR)Context->Irp->AssociatedIrp.SystemBuffer); + + if (DataSize > 0 && Context->RemainingSize > 0) + { + UINT32 _DataSize = min(Context->RemainingSize, DataSize); + + memcpy(Context->CurrentReply + Context->RemainingSize - _DataSize, DataBuffer, _DataSize); + CurrentReply->Data = CurrentUserBuffer + Context->RemainingSize - _DataSize; + CurrentReply->DataSize = _DataSize; + + Context->RemainingSize -= _DataSize; + // Context->ReplyBuffer += _DataSize; + } + else + { + TI_DbgPrint(DEBUG_ICMP, ("RemainingSize: %u, DataSize: %d\n", Context->RemainingSize, DataSize)); + } + + if (OptionsLength > 0 && Context->RemainingSize > 0) + { + UINT32 _OptSize = min(Context->RemainingSize, OptionsLength); + + memcpy(Context->CurrentReply + Context->RemainingSize + _OptSize, Options, _OptSize); + CurrentReply->Options.OptionsData = CurrentUserBuffer + Context->RemainingSize + _OptSize; + CurrentReply->Options.OptionsSize = _OptSize; + + Context->RemainingSize -= _OptSize; + // Context->ReplyBuffer += _OptSize; + } + else + { + TI_DbgPrint(DEBUG_ICMP, ("RemainingSize: %u, OptSize: %d\n", Context->RemainingSize, OptionsLength)); + } + + Context->nReplies++; + + if (Context->RemainingSize < sizeof(ICMP_ECHO_REPLY)) + { + TI_DbgPrint(DEBUG_ICMP, ("The space is over: %u\n", Context->RemainingSize)); + + // if the timer was inserted, that means DPC has not been queued yet + if (KeCancelTimer(&Context->TimeoutTimer)) + { + PADDRESS_FILE AddrFile = (PADDRESS_FILE)Context->TdiRequest.Handle.AddressHandle; + ClearReceiveHandler(AddrFile); + + IoQueueWorkItem(Context->FinishWorker, &EndRequestHandler, DelayedWorkQueue, Context); + } + } + + KeSetEvent(&Context->DatagramProcessedEvent, IO_NO_INCREMENT, FALSE); + return STATUS_SUCCESS; +} + +KDEFERRED_ROUTINE TimeoutHandler; + +VOID +NTAPI +TimeoutHandler( + _In_ PKDPC Dpc, + _In_opt_ PVOID _Context, + _In_opt_ PVOID SystemArgument1, + _In_opt_ PVOID SystemArgument2) +{ + PICMP_PACKET_CONTEXT Context = (PICMP_PACKET_CONTEXT)_Context; + PADDRESS_FILE AddrFile = (PADDRESS_FILE)Context->TdiRequest.Handle.AddressHandle; + ClearReceiveHandler(AddrFile); + + IoQueueWorkItem(Context->FinishWorker, &EndRequestHandler, DelayedWorkQueue, _Context); +} + +NTSTATUS +DispEchoRequest( + _In_ PDEVICE_OBJECT DeviceObject, + _In_ PIRP Irp, + _In_ PIO_STACK_LOCATION IrpSp) +{ + PICMP_ECHO_REQUEST Request = Irp->AssociatedIrp.SystemBuffer; + UINT32 OutputBufferLength = IrpSp->Parameters.DeviceIoControl.OutputBufferLength; + UINT32 InputBufferLength = IrpSp->Parameters.DeviceIoControl.InputBufferLength; + NTSTATUS Status; + TDI_CONNECTION_INFORMATION ConnectionInfo; + TA_IP_ADDRESS RemoteAddressTa, LocalAddressTa; + PADDRESS_FILE AddrFile; + ULONG DataUsed; + PUCHAR Buffer; + UINT16 RequestSize; + PICMP_PACKET_CONTEXT SendContext; + KIRQL OldIrql; + LARGE_INTEGER RequestTimeout; + UINT8 SavedTtl; + + TI_DbgPrint(DEBUG_ICMP, ("About to send datagram, OutputBufferLength: %u, SystemBuffer: %p\n", OutputBufferLength, Irp->AssociatedIrp.SystemBuffer)); + + // check buffers + if (OutputBufferLength < sizeof(ICMP_ECHO_REPLY) || InputBufferLength < sizeof(ICMP_ECHO_REQUEST)) + { + return STATUS_INVALID_PARAMETER; + } + + // check request parameters + if ((Request->DataSize > UINT16_MAX - sizeof(ICMP_HEADER) - sizeof(IPv4_HEADER)) || + ((UINT32)Request->DataOffset + Request->DataSize > InputBufferLength) || + ((UINT32)Request->OptionsOffset + Request->OptionsSize > InputBufferLength)) + { + return STATUS_INVALID_PARAMETER; + } + + SendContext = ExAllocatePoolWithTag(NonPagedPool, sizeof(*SendContext), OUT_DATA_TAG); + if (!SendContext) + { + return STATUS_INSUFFICIENT_RESOURCES; + } + + RtlZeroMemory(&SendContext->TdiRequest, sizeof(SendContext->TdiRequest)); + SendContext->TdiRequest.RequestContext = Irp; + + // setting up everything needed for sending the packet + + RtlZeroMemory(&RemoteAddressTa, sizeof(RemoteAddressTa)); + RtlZeroMemory(&LocalAddressTa, sizeof(LocalAddressTa)); + RtlZeroMemory(&ConnectionInfo, sizeof(ConnectionInfo)); + + RemoteAddressTa.TAAddressCount = 1; + RemoteAddressTa.Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP; + RemoteAddressTa.Address[0].AddressType = TDI_ADDRESS_TYPE_IP; + RemoteAddressTa.Address[0].Address[0].in_addr = Request->Address; + + LocalAddressTa.TAAddressCount = 1; + LocalAddressTa.Address[0].AddressLength = TDI_ADDRESS_LENGTH_IP; + LocalAddressTa.Address[0].AddressType = TDI_ADDRESS_TYPE_IP; + LocalAddressTa.Address[0].Address[0].in_addr = 0; + + Status = FileOpenAddress(&SendContext->TdiRequest, &LocalAddressTa, IPPROTO_ICMP, FALSE, NULL); + + if (!NT_SUCCESS(Status)) + { + TI_DbgPrint(DEBUG_ICMP, ("Failed to open address file status: 0x%x\n", Status)); + + ExFreePoolWithTag(SendContext, OUT_DATA_TAG); + + return Status; + } + + AddrFile = (PADDRESS_FILE)SendContext->TdiRequest.Handle.AddressHandle; + + // setting up the context + + KeQueryPerformanceCounter(&SendContext->TimerResolution); + SendContext->Irp = Irp; + SendContext->CurrentReply = Irp->AssociatedIrp.SystemBuffer; + SendContext->RemainingSize = OutputBufferLength; + SendContext->nReplies = 0; + SendContext->FinishWorker = IoAllocateWorkItem(DeviceObject); + KeInitializeEvent(&SendContext->InitializationFinishedEvent, NotificationEvent, FALSE); + KeInitializeEvent(&SendContext->DatagramProcessedEvent, NotificationEvent, TRUE); + + KeInitializeDpc(&SendContext->TimeoutDpc, &TimeoutHandler, SendContext); + KeInitializeTimerEx(&SendContext->TimeoutTimer, SynchronizationTimer); + + RequestTimeout.QuadPart = (-1LL) * 10 * 1000 * Request->Timeout; + + ConnectionInfo.RemoteAddress = &RemoteAddressTa; + ConnectionInfo.RemoteAddressLength = sizeof(RemoteAddressTa); + + RequestSize = sizeof(ICMP_HEADER) + Request->DataSize; + + // making up the request packet + Buffer = ExAllocatePoolWithTag(NonPagedPool, RequestSize, OUT_DATA_TAG); + + if (!Buffer) + { + ExFreePoolWithTag(SendContext, OUT_DATA_TAG); + + return STATUS_INSUFFICIENT_RESOURCES; + } + + ((PICMP_HEADER)Buffer)->Type = ICMP_TYPE_ECHO_REQUEST; + ((PICMP_HEADER)Buffer)->Code = ICMP_TYPE_ECHO_REPLY; + ((PICMP_HEADER)Buffer)->Checksum = 0; + ((PICMP_HEADER)Buffer)->Identifier = (UINT_PTR)PsGetCurrentProcessId() & UINT16_MAX; + ((PICMP_HEADER)Buffer)->Seq = InterlockedIncrement16(&IcmpSequence); + memcpy(Buffer + sizeof(ICMP_HEADER), (PUCHAR)Request + Request->DataOffset, Request->DataSize); + ((PICMP_HEADER)Buffer)->Checksum = IPv4Checksum(Buffer, RequestSize, 0); + SavedTtl = Request->Ttl; + + RtlZeroMemory(Irp->AssociatedIrp.SystemBuffer, OutputBufferLength); + + LockObject(AddrFile, &OldIrql); + + AddrFile->TTL = SavedTtl; + AddrFile->ReceiveDatagramHandlerContext = SendContext; + AddrFile->ReceiveDatagramHandler = ReceiveDatagram; + AddrFile->RegisteredReceiveDatagramHandler = TRUE; + + UnlockObject(AddrFile, OldIrql); + + Status = AddrFile->Send(AddrFile, &ConnectionInfo, (PCHAR)Buffer, RequestSize, &DataUsed); + + // From this point we may receive a reply packet. + // But we are not ready for it thus InitializationFinishedEvent is needed (see below) + + SendContext->StartTicks = KeQueryPerformanceCounter(NULL).QuadPart; + + ExFreePoolWithTag(Buffer, OUT_DATA_TAG); + + if (!NT_SUCCESS(Status)) + { + NTSTATUS _Status; + + ClearReceiveHandler(AddrFile); + _Status = FileCloseAddress(&SendContext->TdiRequest); + ASSERT(NT_SUCCESS(_Status)); + + IoFreeWorkItem(SendContext->FinishWorker); + ExFreePoolWithTag(SendContext, OUT_DATA_TAG); + + TI_DbgPrint(DEBUG_ICMP, ("Failed to send a datagram: 0x%x\n", Status)); + return Status; + } + + IoMarkIrpPending(Irp); + KeSetTimer(&SendContext->TimeoutTimer, RequestTimeout, &SendContext->TimeoutDpc); + KeSetEvent(&SendContext->InitializationFinishedEvent, IO_NO_INCREMENT, FALSE); + + return STATUS_PENDING; +} diff --git a/drivers/network/tcpip/tcpip/main.c b/drivers/network/tcpip/tcpip/main.c index 919d0260221..b99a66f1092 100644 --- a/drivers/network/tcpip/tcpip/main.c +++ b/drivers/network/tcpip/tcpip/main.c @@ -475,12 +475,12 @@ TiDispatchInternal( /** * @brief Dispatch routine for IRP_MJ_DEVICE_CONTROL requests - * + * * @param[in] DeviceObject * Pointer to a device object for this driver * @param[in] Irp * Pointer to a I/O request packet - * + * * @return * Status of the operation */ @@ -538,6 +538,11 @@ TiDispatch( Status = DispTdiQueryIpHwAddress(DeviceObject, Irp, IrpSp); break; + case IOCTL_ICMP_ECHO_REQUEST: + TI_DbgPrint(MIN_TRACE, ("ICMP_ECHO_REQUEST\n")); + Status = DispEchoRequest(DeviceObject, Irp, IrpSp); + break; + default: TI_DbgPrint(MIN_TRACE, ("Unknown IOCTL 0x%X\n", IrpSp->Parameters.DeviceIoControl.IoControlCode)); diff --git a/media/doc/README.WINE b/media/doc/README.WINE index 5a0a9cb1a15..947ac3b1d97 100644 --- a/media/doc/README.WINE +++ b/media/doc/README.WINE @@ -270,7 +270,6 @@ gdi32 - dll/win32/gdi32/objects/linedda.c # Synced at 20090410 iphlpapi - - dll/win32/iphlpapi/icmp.c # Synced to WineStaging-1.7.55 modules/rostests/winetests/iphlpapi # Synced to WineStaging-1.9.11 kernel32 - diff --git a/sdk/lib/drivers/ip/network/icmp.c b/sdk/lib/drivers/ip/network/icmp.c index b95ecaa2edf..509f994b31f 100644 --- a/sdk/lib/drivers/ip/network/icmp.c +++ b/sdk/lib/drivers/ip/network/icmp.c @@ -26,95 +26,6 @@ NTSTATUS ICMPShutdown() return STATUS_SUCCESS; } -BOOLEAN PrepareICMPPacket( - PADDRESS_FILE AddrFile, - PIP_INTERFACE Interface, - PIP_PACKET IPPacket, - PIP_ADDRESS Destination, - PCHAR Data, - UINT DataSize) -/* - * FUNCTION: Prepares an ICMP packet - * ARGUMENTS: - * NTE = Pointer to net table entry to use - * Destination = Pointer to destination address - * DataSize = Size of dataarea - * RETURNS: - * Pointer to IP packet, NULL if there is not enough free resources - */ -{ - PNDIS_PACKET NdisPacket; - NDIS_STATUS NdisStatus; - PIPv4_HEADER IPHeader; - ULONG Size; - - TI_DbgPrint(DEBUG_ICMP, ("Called. DataSize (%d).\n", DataSize)); - - IPInitializePacket(IPPacket, IP_ADDRESS_V4); - - /* No special flags */ - IPPacket->Flags = 0; - - Size = sizeof(IPv4_HEADER) + DataSize; - - /* Allocate NDIS packet */ - NdisStatus = AllocatePacketWithBuffer( &NdisPacket, NULL, Size ); - - if( !NT_SUCCESS(NdisStatus) ) return FALSE; - - IPPacket->NdisPacket = NdisPacket; - IPPacket->MappedHeader = TRUE; - - GetDataPtr( IPPacket->NdisPacket, 0, - (PCHAR *)&IPPacket->Header, &IPPacket->TotalSize ); - ASSERT(IPPacket->TotalSize == Size); - - TI_DbgPrint(DEBUG_ICMP, ("Size (%d). Data at (0x%X).\n", Size, Data)); - TI_DbgPrint(DEBUG_ICMP, ("NdisPacket at (0x%X).\n", NdisPacket)); - - IPPacket->HeaderSize = sizeof(IPv4_HEADER); - IPPacket->Data = ((PCHAR)IPPacket->Header) + IPPacket->HeaderSize; - - TI_DbgPrint(DEBUG_ICMP, ("Copying Address: %x -> %x\n", - &IPPacket->DstAddr, Destination)); - - RtlCopyMemory(&IPPacket->DstAddr, Destination, sizeof(IP_ADDRESS)); - RtlCopyMemory(IPPacket->Data, Data, DataSize); - - /* Build IPv4 header. FIXME: IPv4 only */ - - IPHeader = (PIPv4_HEADER)IPPacket->Header; - - /* Version = 4, Length = 5 DWORDs */ - IPHeader->VerIHL = 0x45; - /* Normal Type-of-Service */ - IPHeader->Tos = 0; - /* Length of data and header */ - IPHeader->TotalLength = WH2N((USHORT)DataSize + sizeof(IPv4_HEADER)); - /* Identification */ - IPHeader->Id = (USHORT)Random(); - /* One fragment at offset 0 */ - IPHeader->FlagsFragOfs = 0; - /* Set TTL */ - if (AddrFile) - IPHeader->Ttl = AddrFile->TTL; - else - IPHeader->Ttl = 128; - /* Internet Control Message Protocol */ - IPHeader->Protocol = IPPROTO_ICMP; - /* Checksum is 0 (for later calculation of this) */ - IPHeader->Checksum = 0; - /* Source address */ - IPHeader->SrcAddr = Interface->Unicast.Address.IPv4Address; - /* Destination address */ - IPHeader->DstAddr = Destination->Address.IPv4Address; - - - TI_DbgPrint(MID_TRACE,("Leaving\n")); - - return TRUE; -} - NTSTATUS ICMPSendDatagram( PADDRESS_FILE AddrFile, PTDI_CONNECTION_INFORMATION ConnInfo, @@ -132,79 +43,10 @@ NTSTATUS ICMPSendDatagram( * Status of operation */ { - IP_PACKET Packet; - PTA_IP_ADDRESS RemoteAddressTa = (PTA_IP_ADDRESS)ConnInfo->RemoteAddress; - IP_ADDRESS RemoteAddress, LocalAddress; - NTSTATUS Status; - PNEIGHBOR_CACHE_ENTRY NCE; - KIRQL OldIrql; - - TI_DbgPrint(MID_TRACE,("Sending Datagram(%x %x %x %d)\n", - AddrFile, ConnInfo, BufferData, DataSize)); - TI_DbgPrint(MID_TRACE,("RemoteAddressTa: %x\n", RemoteAddressTa)); - - switch( RemoteAddressTa->Address[0].AddressType ) { - case TDI_ADDRESS_TYPE_IP: - RemoteAddress.Type = IP_ADDRESS_V4; - RemoteAddress.Address.IPv4Address = - RemoteAddressTa->Address[0].Address[0].in_addr; - break; - - default: - return STATUS_UNSUCCESSFUL; - } - - TI_DbgPrint(MID_TRACE,("About to get route to destination\n")); - - LockObject(AddrFile, &OldIrql); - - LocalAddress = AddrFile->Address; - if (AddrIsUnspecified(&LocalAddress)) - { - /* If the local address is unspecified (0), - * then use the unicast address of the - * interface we're sending over - */ - if(!(NCE = RouteGetRouteToDestination( &RemoteAddress ))) - { - UnlockObject(AddrFile, OldIrql); - return STATUS_NETWORK_UNREACHABLE; - } - - LocalAddress = NCE->Interface->Unicast; - } - else - { - if(!(NCE = NBLocateNeighbor( &LocalAddress, NULL ))) - { - UnlockObject(AddrFile, OldIrql); - return STATUS_INVALID_PARAMETER; - } - } - - Status = PrepareICMPPacket( AddrFile, - NCE->Interface, - &Packet, - &RemoteAddress, - BufferData, - DataSize ); + TI_DbgPrint(DEBUG_ICMP, ("Sending ICMP datagram (0x%x)\n", AddrFile)); - UnlockObject(AddrFile, OldIrql); - - if( !NT_SUCCESS(Status) ) - return Status; - - TI_DbgPrint(MID_TRACE,("About to send datagram\n")); - - Status = IPSendDatagram(&Packet, NCE); - if (!NT_SUCCESS(Status)) - return Status; - - *DataUsed = DataSize; - - TI_DbgPrint(MID_TRACE,("Leaving\n")); - - return STATUS_SUCCESS; + /* just forward the call to RawIP handler */ + return RawIPSendDatagram(AddrFile, ConnInfo, BufferData, DataSize, DataUsed); } @@ -218,81 +60,34 @@ VOID ICMPReceive( * IPPacket = Pointer to an IP packet that was received */ { - PICMP_HEADER ICMPHeader; - - TI_DbgPrint(DEBUG_ICMP, ("Called.\n")); - - ICMPHeader = (PICMP_HEADER)IPPacket->Data; - - TI_DbgPrint(DEBUG_ICMP, ("Size (%d).\n", IPPacket->TotalSize)); - - TI_DbgPrint(DEBUG_ICMP, ("HeaderSize (%d).\n", IPPacket->HeaderSize)); - - TI_DbgPrint(DEBUG_ICMP, ("Type (%d).\n", ICMPHeader->Type)); + PICMP_HEADER ICMPHeader = (PICMP_HEADER)IPPacket->Data; + UINT32 DataSize = IPPacket->TotalSize - IPPacket->HeaderSize; - TI_DbgPrint(DEBUG_ICMP, ("Code (%d).\n", ICMPHeader->Code)); + TI_DbgPrint(DEBUG_ICMP, ("ICMPReceive: Size (%d) HeaderSize (%d) Type (%d) Code (%d) Checksum (0x%x)\n", + IPPacket->TotalSize, IPPacket->HeaderSize, ICMPHeader->Type, ICMPHeader->Code, ICMPHeader->Checksum)); - TI_DbgPrint(DEBUG_ICMP, ("Checksum (0x%X).\n", ICMPHeader->Checksum)); - - /* Checksum ICMP header and data */ - if (!IPv4CorrectChecksum(IPPacket->Data, IPPacket->TotalSize - IPPacket->HeaderSize)) { - TI_DbgPrint(DEBUG_ICMP, ("Bad ICMP checksum.\n")); - /* Discard packet */ + /* Discard too short packets */ + if (DataSize < sizeof(ICMP_HEADER)) + { + TI_DbgPrint(DEBUG_ICMP, ("Packet doesn't fit ICMP header. Discarded\n")); return; } - RawIpReceive(Interface, IPPacket); - - switch (ICMPHeader->Type) { - case ICMP_TYPE_ECHO_REQUEST: - ICMPReply( Interface, IPPacket, ICMP_TYPE_ECHO_REPLY, 0 ); - break; - - case ICMP_TYPE_ECHO_REPLY: - break; - - default: - TI_DbgPrint(DEBUG_ICMP, - ("Discarded ICMP datagram of unknown type %d.\n", - ICMPHeader->Type)); - /* Discard packet */ - break; + /* Discard packets with bad checksum */ + if (!IPv4CorrectChecksum(IPPacket->Data, DataSize)) + { + TI_DbgPrint(DEBUG_ICMP, ("Bad ICMP checksum. Packet discarded\n")); + return; } -} - -VOID ICMPTransmit( - PIP_PACKET IPPacket, - PIP_TRANSMIT_COMPLETE Complete, - PVOID Context) -/* - * FUNCTION: Transmits an ICMP packet - * ARGUMENTS: - * NTE = Pointer to net table entry to use (NULL if don't care) - * IPPacket = Pointer to IP packet to transmit - */ -{ - PNEIGHBOR_CACHE_ENTRY NCE; - - TI_DbgPrint(DEBUG_ICMP, ("Called.\n")); - - /* Calculate checksum of ICMP header and data */ - ((PICMP_HEADER)IPPacket->Data)->Checksum = (USHORT) - IPv4Checksum(IPPacket->Data, IPPacket->TotalSize - IPPacket->HeaderSize, 0); + RawIpReceive(Interface, IPPacket); - /* Get a route to the destination address */ - if ((NCE = RouteGetRouteToDestination(&IPPacket->DstAddr))) { - /* Send the packet */ - IPSendDatagram(IPPacket, NCE); - } else { - /* No route to destination (or no free resources) */ - TI_DbgPrint(DEBUG_ICMP, ("No route to destination address 0x%X.\n", - IPPacket->DstAddr.Address.IPv4Address)); - IPPacket->Free(IPPacket); + if (ICMPHeader->Type == ICMP_TYPE_ECHO_REQUEST) + { + ICMPReply(Interface, IPPacket, ICMP_TYPE_ECHO_REPLY, 0); } } - VOID ICMPReply( PIP_INTERFACE Interface, PIP_PACKET IPPacket, @@ -314,19 +109,36 @@ VOID ICMPReply( { UINT DataSize; IP_PACKET NewPacket; + ADDRESS_FILE FakeAddrFile; + PNEIGHBOR_CACHE_ENTRY NCE; TI_DbgPrint(DEBUG_ICMP, ("Called. Type (%d) Code (%d).\n", Type, Code)); DataSize = IPPacket->TotalSize - IPPacket->HeaderSize; - if( !PrepareICMPPacket(NULL, Interface, &NewPacket, &IPPacket->SrcAddr, - IPPacket->Data, DataSize) ) return; + /* First check if we have a route to sender */ + NCE = RouteGetRouteToDestination(&IPPacket->SrcAddr); + if (!NCE) + { + return; + } + + /* This is the only data needed to generate a packet */ + FakeAddrFile.Protocol = IPPROTO_ICMP; + FakeAddrFile.TTL = 128; + + if (!NT_SUCCESS(BuildRawIpPacket( + &FakeAddrFile, &NewPacket, &IPPacket->SrcAddr, 0, &Interface->Unicast, 0, IPPacket->Data, DataSize))) + { + return; + } ((PICMP_HEADER)NewPacket.Data)->Type = Type; ((PICMP_HEADER)NewPacket.Data)->Code = Code; ((PICMP_HEADER)NewPacket.Data)->Checksum = 0; + ((PICMP_HEADER)NewPacket.Data)->Checksum = (USHORT)IPv4Checksum(NewPacket.Data, DataSize, 0); - ICMPTransmit(&NewPacket, NULL, NULL); + IPSendDatagram(&NewPacket, NCE); } /* EOF */ diff --git a/sdk/lib/drivers/ip/transport/rawip/rawip.c b/sdk/lib/drivers/ip/transport/rawip/rawip.c index 180f545db39..7e7fb22436a 100644 --- a/sdk/lib/drivers/ip/transport/rawip/rawip.c +++ b/sdk/lib/drivers/ip/transport/rawip/rawip.c @@ -46,7 +46,7 @@ NTSTATUS AddGenericHeaderIPv4( &IPPacket->TotalSize ); IPPacket->MappedHeader = TRUE; - IPPacket->HeaderSize = 20; + IPPacket->HeaderSize = sizeof(IPv4_HEADER); TI_DbgPrint(MAX_TRACE, ("Allocated %d bytes for headers at 0x%X.\n", BufferSize, IPPacket->Header));
4 years, 8 months
1
0
0
0
[reactos] 03/06: [IPHLPAPI] Make icmp functions use IOCTL_ICMP_ECHO_REQUEST from tcpip.sys This adds missing features like using events and APCs within IcmpSendEcho2 functions and others. CORE-10742 CORE-14411
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=dd2ff41dfcf0834118227…
commit dd2ff41dfcf08341182273309205666a1a82c31a Author: Victor Perevertkin <victor.perevertkin(a)reactos.org> AuthorDate: Mon Nov 18 20:54:03 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Apr 7 05:32:40 2020 +0300 [IPHLPAPI] Make icmp functions use IOCTL_ICMP_ECHO_REQUEST from tcpip.sys This adds missing features like using events and APCs within IcmpSendEcho2 functions and others. CORE-10742 CORE-14411 Co-authored-by: Tim Crawford <crawfxrd(a)gmail.com> --- dll/win32/iphlpapi/icmp.c | 1423 +++++++++++--------------------------- dll/win32/iphlpapi/iphlpapi.spec | 4 +- sdk/include/psdk/ipexport.h | 51 +- sdk/include/psdk/tcpioctl.h | 3 + 4 files changed, 464 insertions(+), 1017 deletions(-) diff --git a/dll/win32/iphlpapi/icmp.c b/dll/win32/iphlpapi/icmp.c index dec33c13ca9..b32aeca8876 100644 --- a/dll/win32/iphlpapi/icmp.c +++ b/dll/win32/iphlpapi/icmp.c @@ -1,1129 +1,552 @@ /* - * ICMP - * - * Francois Gouget, 1999, based on the work of - * RW Hall, 1999, based on public domain code PING.C by Mike Muus (1983) - * and later works (c) 1989 Regents of Univ. of California - see copyright - * notice at end of source-code. - * Copyright 2015 Sebastian Lackner - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + * PROJECT: ReactOS IP Helper API + * LICENSE: LGPL-2.1-or-later (
https://spdx.org/licenses/LGPL-2.1-or-later
) + * PURPOSE: ICMP functions + * COPYRIGHT: 2016 Tim Crawford (crawfxrd(a)gmail.com) + * 2019 Victor Perevertkin (victor.perevertkin(a)reactos.org) */ -/* Future work: - * - Systems like FreeBSD don't seem to support the IP_TTL option and maybe others. - * But using IP_HDRINCL and building the IP header by hand might work. - * - Not all IP options are supported. - * - Are ICMP handles real handles, i.e. inheritable and all? There might be some - * more work to do here, including server side stuff with synchronization. - * - This API should probably be thread safe. Is it really? - * - Using the winsock functions has not been tested. - */ - -#ifdef __REACTOS__ #include "iphlpapi_private.h" -#else // ! __REACTOS__ -#include "config.h" -#include "wine/port.h" - -#include <sys/types.h> -#ifdef HAVE_SYS_SOCKET_H -# include <sys/socket.h> -#endif -#ifdef HAVE_NETDB_H -# include <netdb.h> -#endif -#ifdef HAVE_NETINET_IN_SYSTM_H -# include <netinet/in_systm.h> -#endif -#ifdef HAVE_NETINET_IN_H -# include <netinet/in.h> -#endif - -#ifdef HAVE_SYS_TIME_H -# include <sys/time.h> -#endif -#include <stdarg.h> -#include <string.h> -#include <stdio.h> -#include <errno.h> -#include <fcntl.h> -#ifdef HAVE_UNISTD_H -# include <unistd.h> -#endif -#ifdef HAVE_ARPA_INET_H -# include <arpa/inet.h> -#endif -#ifdef HAVE_SYS_POLL_H -# include <sys/poll.h> -#endif -#ifdef HAVE_SYS_WAIT_H -# include <sys/wait.h> -#endif - -#define USE_WS_PREFIX - -#include "windef.h" -#include "winbase.h" -#include "winerror.h" -#include "winternl.h" -#include "ipexport.h" -#include "icmpapi.h" -#include "wine/debug.h" -#endif // ! __REACTOS__ - -/* Set up endianness macros for the ip and ip_icmp BSD headers */ -#ifndef BIG_ENDIAN -#define BIG_ENDIAN 4321 -#endif -#ifndef LITTLE_ENDIAN -#define LITTLE_ENDIAN 1234 -#endif -#ifndef BYTE_ORDER -#ifdef WORDS_BIGENDIAN -#define BYTE_ORDER BIG_ENDIAN -#else -#define BYTE_ORDER LITTLE_ENDIAN -#endif -#endif /* BYTE_ORDER */ - -#define u_int16_t WORD -#define u_int32_t DWORD - -/* These are BSD headers. We use these here because they are needed on - * libc5 Linux systems. On other platforms they are usually simply more - * complete than the native stuff, and cause less portability problems - * so we use them anyway. - */ -#include "ip.h" -#include "ip_icmp.h" +WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi); -WINE_DEFAULT_DEBUG_CHANNEL(icmp); -WINE_DECLARE_DEBUG_CHANNEL(winediag); - +HANDLE +WINAPI +Icmp6CreateFile(void) +{ + HANDLE IcmpFile; + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\Ip6"); + NTSTATUS Status; + + InitializeObjectAttributes( + &ObjectAttributes, + &DeviceName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + + Status = NtCreateFile( + &IcmpFile, + GENERIC_EXECUTE, + &ObjectAttributes, + &IoStatusBlock, + NULL, + FILE_ATTRIBUTE_NORMAL, + FILE_SHARE_READ | FILE_SHARE_WRITE, + FILE_OPEN_IF, + 0, + NULL, + 0); + + if (!NT_SUCCESS(Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); + return INVALID_HANDLE_VALUE; + } -typedef struct { - int sid; - IP_OPTION_INFORMATION default_opts; -} icmp_t; + return IcmpFile; +} -#define IP_OPTS_UNKNOWN 0 -#define IP_OPTS_DEFAULT 1 -#define IP_OPTS_CUSTOM 2 +DWORD +WINAPI +Icmp6ParseReplies( + _In_ LPVOID ReplyBuffer, + _In_ DWORD ReplySize) +{ + PICMPV6_ECHO_REPLY pEcho; -/* The sequence number is unique process wide, so that all threads - * have a distinct sequence number. - */ -static LONG icmp_sequence=0; + if (ReplyBuffer == NULL || ReplySize == 0) + return 0; -static int in_cksum(u_short *addr, int len) -{ - int nleft=len; - u_short *w = addr; - int sum = 0; - u_short answer = 0; - - while (nleft > 1) { - sum += *w++; - nleft -= 2; - } + pEcho = (PICMPV6_ECHO_REPLY)ReplyBuffer; - if (nleft == 1) { - *(u_char *)(&answer) = *(u_char *)w; - sum += answer; + // XXX: MSDN also says IP_TTL_EXPIRED_TRANSIT. + if (pEcho->Status == IP_SUCCESS) + { + return 1; } - sum = (sum >> 16) + (sum & 0xffff); - sum += (sum >> 16); - answer = ~sum; - return(answer); + SetLastError(pEcho->Status); + return 0; } - - -/* - * Exported Routines. - */ - -/*********************************************************************** - * Icmp6CreateFile (IPHLPAPI.@) - */ -HANDLE WINAPI Icmp6CreateFile(VOID) +DWORD +WINAPI +Icmp6SendEcho2( + _In_ HANDLE IcmpHandle, + _In_opt_ HANDLE Event, + _In_opt_ PIO_APC_ROUTINE ApcRoutine, + _In_opt_ PVOID ApcContext, + _In_ struct sockaddr_in6 *SourceAddress, + _In_ struct sockaddr_in6 *DestinationAddress, + _In_ LPVOID RequestData, + _In_ WORD RequestSize, + _In_ PIP_OPTION_INFORMATION RequestOptions, + _Out_ LPVOID ReplyBuffer, + _In_ DWORD ReplySize, + _In_ DWORD Timeout) { - icmp_t* icp; -#ifdef __REACTOS__ - int sid; - WSADATA wsaData; + HANDLE hEvent; + PIO_STATUS_BLOCK IoStatusBlock; + PVOID InputBuffer; + ULONG InputBufferLength; + //ULONG OutputBufferLength; + PICMPV6_ECHO_REQUEST Request; + NTSTATUS Status; + + InputBufferLength = sizeof(ICMPV6_ECHO_REQUEST) + RequestSize; - if (WSAStartup(MAKEWORD(2, 2), &wsaData) != ERROR_SUCCESS) + if (ReplySize < sizeof(ICMPV6_ECHO_REPLY) + sizeof(IO_STATUS_BLOCK)) { - ERR_(winediag)("Failed to use ICMPV6 (network ping), this requires special permissions.\n"); - return INVALID_HANDLE_VALUE; + SetLastError(IP_BUF_TOO_SMALL); + return 0; } - sid=socket(AF_INET6,SOCK_RAW,IPPROTO_ICMPV6); -#else + // IO_STATUS_BLOCK will be stored inside ReplyBuffer (in the end) + // that's because the function may return before device request ends + IoStatusBlock = (PIO_STATUS_BLOCK)((PUCHAR)ReplyBuffer + ReplySize - sizeof(IO_STATUS_BLOCK)); + ReplySize -= sizeof(IO_STATUS_BLOCK); - int sid=socket(AF_INET6,SOCK_RAW,IPPROTO_ICMPV6); - if (sid < 0) + InputBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, InputBufferLength); + if (InputBuffer == NULL) { - /* Mac OS X supports non-privileged ICMP via SOCK_DGRAM type. */ - sid=socket(AF_INET6,SOCK_DGRAM,IPPROTO_ICMPV6); - } -#endif - if (sid < 0) { - ERR_(winediag)("Failed to use ICMPV6 (network ping), this requires special permissions.\n"); - SetLastError(ERROR_ACCESS_DENIED); - return INVALID_HANDLE_VALUE; + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return 0; } - icp=HeapAlloc(GetProcessHeap(), 0, sizeof(*icp)); - if (icp==NULL) { -#ifdef __REACTOS__ - closesocket(sid); - WSACleanup(); -#else - close(sid); -#endif - SetLastError(IP_NO_RESOURCES); - return INVALID_HANDLE_VALUE; - } - icp->sid=sid; - icp->default_opts.OptionsSize=IP_OPTS_UNKNOWN; - return (HANDLE)icp; -} + Request = (PICMPV6_ECHO_REQUEST)InputBuffer; + Request->DestinationAddress.sin6_port = DestinationAddress->sin6_port; + Request->DestinationAddress.sin6_flowinfo = DestinationAddress->sin6_flowinfo; + CopyMemory(&(Request->DestinationAddress.sin6_addr), &(DestinationAddress->sin6_addr), sizeof(Request->DestinationAddress.sin6_addr)); + Request->DestinationAddress.sin6_scope_id = DestinationAddress->sin6_scope_id; -/*********************************************************************** - * Icmp6SendEcho2 (IPHLPAPI.@) - */ -DWORD WINAPI Icmp6SendEcho2( - HANDLE IcmpHandle, - HANDLE Event, - PIO_APC_ROUTINE ApcRoutine, - PVOID ApcContext, - struct sockaddr_in6* SourceAddress, - struct sockaddr_in6* DestinationAddress, - LPVOID RequestData, - WORD RequestSize, - PIP_OPTION_INFORMATION RequestOptions, - LPVOID ReplyBuffer, - DWORD ReplySize, - DWORD Timeout - ) -{ - FIXME("(%p, %p, %p, %p, %p, %p, %p, %d, %p, %p, %d, %d): stub\n", IcmpHandle, Event, - ApcRoutine, ApcContext, SourceAddress, DestinationAddress, RequestData, - RequestSize, RequestOptions, ReplyBuffer, ReplySize, Timeout); - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return 0; -} + Request->SourceAddress.sin6_port = SourceAddress->sin6_port; + Request->SourceAddress.sin6_flowinfo = SourceAddress->sin6_flowinfo; + CopyMemory(&(Request->SourceAddress.sin6_addr), &(SourceAddress->sin6_addr), sizeof(Request->SourceAddress.sin6_addr)); + Request->SourceAddress.sin6_scope_id = SourceAddress->sin6_scope_id; + // XXX: What is this and why is it sometimes 0x72? + Request->Unknown1 = 0x72; -/*********************************************************************** - * IcmpCreateFile (IPHLPAPI.@) - */ -HANDLE WINAPI IcmpCreateFile(VOID) -{ -#ifndef __REACTOS__ - static int once; -#endif - icmp_t* icp; -#ifdef __REACTOS__ - int sid; - WSADATA wsaData; - - if (WSAStartup(MAKEWORD(2, 2), &wsaData) != ERROR_SUCCESS) + Request->Timeout = Timeout; + Request->Ttl = RequestOptions->Ttl; + Request->Flags = RequestOptions->Flags; + + if (RequestSize > 0) { - ERR_(winediag)("Failed to use ICMPV6 (network ping), this requires special permissions.\n"); - return INVALID_HANDLE_VALUE; + CopyMemory((PBYTE)InputBuffer + sizeof(ICMPV6_ECHO_REQUEST), RequestData, RequestSize); } - sid=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP); - if (sid < 0) { - ERR_(winediag)("Failed to use ICMP (network ping), this requires special permissions.\n"); - SetLastError(ERROR_ACCESS_DENIED); - return INVALID_HANDLE_VALUE; + + if (Event == NULL && ApcRoutine == NULL) + { + hEvent = CreateEventW(NULL, FALSE, FALSE, NULL); + } + else + { + hEvent = Event; + } + + Status = NtDeviceIoControlFile( + IcmpHandle, + hEvent, + ApcRoutine, + ApcContext, + IoStatusBlock, + IOCTL_ICMP_ECHO_REQUEST, + InputBuffer, + InputBufferLength, + ReplyBuffer, + ReplySize); // TODO: Determine how Windows calculates OutputBufferLength. + + if (Event != NULL || ApcRoutine != NULL) + { + SetLastError(RtlNtStatusToDosError(Status)); + HeapFree(GetProcessHeap(), 0, InputBuffer); + return 0; } -#else - int sid=socket(AF_INET,SOCK_RAW,IPPROTO_ICMP); - if (sid < 0) + if (Status == STATUS_PENDING) { - /* Mac OS X supports non-privileged ICMP via SOCK_DGRAM type. */ - sid=socket(AF_INET,SOCK_DGRAM,IPPROTO_ICMP); + Status = NtWaitForSingleObject(hEvent, FALSE, NULL); + + if (NT_SUCCESS(Status)) + { + Status = IoStatusBlock->Status; + } } - if (sid < 0 && !once++) { - FIXME_(winediag)("Failed to use ICMP (network ping), this requires special permissions.\n"); - FIXME_(winediag)("Falling back to system 'ping' command as a workaround.\n"); + + CloseHandle(hEvent); + HeapFree(GetProcessHeap(), 0, InputBuffer); + + if (!NT_SUCCESS(Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); + return 0; } -#endif - - icp=HeapAlloc(GetProcessHeap(), 0, sizeof(*icp)); - if (icp==NULL) { -#ifdef __REACTOS__ - closesocket(sid); - WSACleanup(); -#else - if (sid >= 0) close(sid); -#endif - SetLastError(IP_NO_RESOURCES); - return INVALID_HANDLE_VALUE; + + Status = ((PICMPV6_ECHO_REPLY)ReplyBuffer)->Status; + if (Status != IP_SUCCESS) + { + SetLastError(Status); + return 0; } - icp->sid=sid; - icp->default_opts.OptionsSize=IP_OPTS_UNKNOWN; - return (HANDLE)icp; -} + return 1; +} -/*********************************************************************** - * IcmpCloseHandle (IPHLPAPI.@) - */ -BOOL WINAPI IcmpCloseHandle(HANDLE IcmpHandle) +BOOL +WINAPI +IcmpCloseHandle( + _In_ HANDLE IcmpHandle) { - icmp_t* icp=(icmp_t*)IcmpHandle; -#ifdef __REACTOS__ - // REACTOS: Added a check for NULL handle, CORE-10707 - if (IcmpHandle==INVALID_HANDLE_VALUE || IcmpHandle==NULL) { -#else - if (IcmpHandle==INVALID_HANDLE_VALUE) { -#endif - /* FIXME: in fact win98 seems to ignore the handle value !!! */ - SetLastError(ERROR_INVALID_HANDLE); + NTSTATUS Status; + + Status = NtClose(IcmpHandle); + if (!NT_SUCCESS(Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); return FALSE; } -#ifdef __REACTOS__ - shutdown(icp->sid,2); -#else - if (icp->sid >= 0) close(icp->sid); -#endif - HeapFree(GetProcessHeap (), 0, icp); -#ifdef __REACTOS__ - WSACleanup(); -#endif return TRUE; } -#ifndef __REACTOS__ -static DWORD system_icmp( - IPAddr DestinationAddress, - LPVOID RequestData, - WORD RequestSize, - PIP_OPTION_INFORMATION RequestOptions, - LPVOID ReplyBuffer, - DWORD ReplySize, - DWORD Timeout - ) +HANDLE +WINAPI +IcmpCreateFile(void) { -#ifdef HAVE_FORK - ICMP_ECHO_REPLY *reply = ReplyBuffer; - char ntoa_buffer[16]; /* 4*3 digits + 3 '.' + 1 '\0' */ - char size_buffer[6]; /* 5 digits + '\0' */ - char tos_buffer[4]; /* 3 digits + '\0' */ - char ttl_buffer[4]; /* 3 digits + '\0' */ - char time_buffer[11]; /* 10 digits + '\0' */ - int i, pos, res, status, argc; - const char *argv[20]; - struct in_addr addr; - int pipe_out[2]; - pid_t pid, wpid; - char *ptr, *eol; - char buf[127]; - - /* Assemble the ping commandline */ - argc = 0; - argv[argc++] = "ping"; - argv[argc++] = "-c"; /* only send a single ping */ - argv[argc++] = "1"; - argv[argc++] = "-n"; /* numeric output only */ - argv[argc++] = "-s"; /* request size */ - sprintf(size_buffer, "%u", (RequestSize >= 16) ? RequestSize : 16); - argv[argc++] = size_buffer; - argv[argc++] = "-W"; /* timeout */ -#ifdef __linux__ - /* The linux 'ping' utlity expects a time in seconds */ - Timeout = (Timeout + 999) / 1000; -#endif - sprintf(time_buffer, "%u", Timeout); - argv[argc++] = time_buffer; - - if (RequestOptions) + HANDLE IcmpFile; + OBJECT_ATTRIBUTES ObjectAttributes; + IO_STATUS_BLOCK IoStatusBlock; + UNICODE_STRING DeviceName = RTL_CONSTANT_STRING(L"\\Device\\Ip"); + NTSTATUS Status; + + InitializeObjectAttributes( + &ObjectAttributes, + &DeviceName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + + Status = NtCreateFile( + &IcmpFile, + GENERIC_EXECUTE, + &ObjectAttributes, + &IoStatusBlock, + NULL, + FILE_ATTRIBUTE_NORMAL, + FILE_SHARE_READ | FILE_SHARE_WRITE, + FILE_OPEN_IF, + 0, + NULL, + 0); + + if (!NT_SUCCESS(Status)) { - #ifdef __linux__ - argv[argc++] = "-Q"; /* tos option */ - #else - argv[argc++] = "-z"; /* tos option */ - #endif - sprintf(tos_buffer, "%u", RequestOptions->Tos); - argv[argc++] = tos_buffer; - #ifdef __linux__ - /* TTL can only be specified for multicast addresses on FreeBSD/MacOS */ - argv[argc++] = "-t"; /* ttl option */ - sprintf(ttl_buffer, "%u", RequestOptions->Ttl); - argv[argc++] = ttl_buffer; - #endif + SetLastError(RtlNtStatusToDosError(Status)); + return INVALID_HANDLE_VALUE; } - addr.s_addr = DestinationAddress; - if (!(ptr = inet_ntoa(addr))) - { - SetLastError(ERROR_INVALID_PARAMETER); + return IcmpFile; +} + +DWORD +WINAPI +IcmpParseReplies( + _In_ LPVOID ReplyBuffer, + _In_ DWORD ReplySize) +{ + PICMP_ECHO_REPLY pEcho; + DWORD nReplies; + + if (ReplyBuffer == NULL || ReplySize == 0) return 0; - } - strcpy(ntoa_buffer, ptr); - argv[argc++] = ntoa_buffer; - argv[argc] = NULL; - /* Dump commandline for debugging purposes */ - TRACE("Ping commandline: "); - for (i = 0; i < argc; i++) - { - TRACE("%s ", debugstr_a(argv[i])); - } - TRACE("\n"); - - /* Prefill the reply struct with fallback values */ - memset(reply, 0, sizeof(*reply)); - reply->Address = DestinationAddress; - reply->RoundTripTime = 40; - reply->Options.Ttl = 120; - - /* Create communication pipes */ -#ifdef HAVE_PIPE2 - if (pipe2(pipe_out, O_CLOEXEC) < 0) -#endif + // TODO: Handle ReplyBuffer having more than 1 ICMP_ECHO_REPLY. + + pEcho = (PICMP_ECHO_REPLY)ReplyBuffer; + + if (pEcho->Reserved == 0) { - if (pipe(pipe_out) < 0) - { - SetLastError(ERROR_OUTOFMEMORY); - return 0; - } - fcntl(pipe_out[0], F_SETFD, FD_CLOEXEC); - fcntl(pipe_out[1], F_SETFD, FD_CLOEXEC); + SetLastError(pEcho->Status); } - /* Fork child process */ - pid = fork(); - if (pid == -1) + nReplies = pEcho->Reserved; + pEcho->Reserved = 0; + + return nReplies; +} + +DWORD +WINAPI +IcmpSendEcho2( + _In_ HANDLE IcmpHandle, + _In_opt_ HANDLE Event, + _In_opt_ PIO_APC_ROUTINE ApcRoutine, + _In_opt_ PVOID ApcContext, + _In_ IPAddr DestinationAddress, + _In_ LPVOID RequestData, + _In_ WORD RequestSize, + _In_opt_ PIP_OPTION_INFORMATION RequestOptions, + _Out_ LPVOID ReplyBuffer, + _In_ DWORD ReplySize, + _In_ DWORD Timeout) +{ + HANDLE hEvent; + PIO_STATUS_BLOCK IoStatusBlock; + PVOID InputBuffer; + PICMP_ECHO_REQUEST Request; + DWORD nReplies; + NTSTATUS Status; + + if (ReplySize < sizeof(ICMP_ECHO_REPLY) + sizeof(IO_STATUS_BLOCK)) { - close(pipe_out[0]); - close(pipe_out[1]); - SetLastError(ERROR_OUTOFMEMORY); + SetLastError(ERROR_INSUFFICIENT_BUFFER); return 0; } - /* Child process */ - if (pid == 0) + if (ReplySize < RequestSize + sizeof(ICMP_ECHO_REPLY)) { - static char lang_env[] = "LANG=C"; + SetLastError(IP_GENERAL_FAILURE); + return 0; + } - dup2(pipe_out[1], 1); - close(pipe_out[0]); - close(pipe_out[1]); - close(0); - close(2); + // IO_STATUS_BLOCK will be stored inside ReplyBuffer (in the end) + // that's because the function may return before device request ends + IoStatusBlock = (PIO_STATUS_BLOCK)((PUCHAR)ReplyBuffer + ReplySize - sizeof(IO_STATUS_BLOCK)); + ReplySize -= sizeof(IO_STATUS_BLOCK); - putenv(lang_env); - execvp(argv[0], (char **)argv); - _exit(1); + InputBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ReplySize); + if (InputBuffer == NULL) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return 0; } - close(pipe_out[1]); + Request = (PICMP_ECHO_REQUEST)InputBuffer; + Request->Address = DestinationAddress; + Request->Timeout = Timeout; + Request->OptionsOffset = sizeof(ICMP_ECHO_REQUEST); + Request->DataOffset = sizeof(ICMP_ECHO_REQUEST); - /* Wait for child and read output */ - pos = 0; - do + if (RequestOptions != NULL) { - if (pos >= sizeof(buf) - 1) - { - ERR("line too long, dropping buffer\n"); - pos = 0; - } + Request->HasOptions = TRUE; + Request->Ttl = RequestOptions->Ttl; + Request->Tos = RequestOptions->Tos; + Request->Flags = RequestOptions->Flags; - /* read next block */ - do + if (RequestOptions->OptionsSize > 0) { - res = read(pipe_out[0], &buf[pos], (sizeof(buf) - 1) - pos); - } - while (res < 0 && errno == EINTR); - if (res < 0) - { - ERR("read failed: %s\n", strerror(errno)); - break; - } + Request->OptionsSize = RequestOptions->OptionsSize; + Request->DataOffset += Request->OptionsSize; - pos += res; - while (pos) - { - eol = memchr(buf, '\n', pos); - if (!eol) break; - *eol = 0; - - TRACE("Received line: %s\n", debugstr_a(buf)); - - /* Interpret address */ - if ((ptr = strstr(buf, "from "))) - { - int a, b, c, d; - if (sscanf(ptr + 5, "%u.%u.%u.%u", &a, &b, &c, &d) >= 4) - { - reply->Address = a | (b << 8) | (c << 16) | (d << 24); - addr.s_addr = reply->Address; - TRACE("Got address %s\n", inet_ntoa(addr)); - } - } - - /* Interpret ttl */ - if ((ptr = strstr(buf, "ttl="))) - { - int val; - if (sscanf(ptr + 4, "%u", &val) >= 1) - { - reply->Options.Ttl = val; - TRACE("Got ttl %u\n", val); - } - } - - /* Interpret time */ - if ((ptr = strstr(buf, "time="))) - { - float val; - if (sscanf(ptr + 5, "%f", &val) >= 1) - { - reply->RoundTripTime = (unsigned int)(val + 0.5); - TRACE("Got rtt = %u\n", reply->RoundTripTime); - } - } - - memmove(buf, eol + 1, pos - (eol + 1 - buf)); - pos -= (eol + 1 - buf); + CopyMemory( + (PUCHAR)InputBuffer + sizeof(ICMP_ECHO_REQUEST), + RequestOptions->OptionsData, + Request->OptionsSize); } } - while (res > 0); - close(pipe_out[0]); - /* reap the child process */ - do + if (RequestSize > 0) { - wpid = waitpid(pid, &status, 0); + Request->DataSize = RequestSize; + CopyMemory((PUCHAR)InputBuffer + Request->DataOffset, RequestData, RequestSize); } - while (wpid < 0 && errno == EINTR); - /* fill out remaining struct fields */ - if (wpid >= 0 && WIFEXITED(status) && WEXITSTATUS(status) == 0) + if (Event == NULL && ApcRoutine == NULL) { - if (ReplySize < RequestSize + sizeof(*reply)) - { - reply->Status = IP_BUF_TOO_SMALL; - reply->DataSize = 0; - reply->Data = NULL; - } - else - { - reply->Status = 0; - reply->DataSize = RequestSize; - reply->Data = (char *)reply + sizeof(*reply); - memcpy(reply->Data, RequestData, RequestSize); - } - return 1; + hEvent = CreateEventW(NULL, FALSE, FALSE, NULL); } - - SetLastError(IP_REQ_TIMED_OUT); - return 0; -#else - ERR("no fork support on this platform\n"); - SetLastError(ERROR_NOT_SUPPORTED); - return 0; -#endif -} -#else // __REACTOS__ -BOOL -GetIPv4ByIndex( - _In_ DWORD Index, - _Out_ IPAddr * Address -) -{ - PMIB_IPADDRTABLE pIpAddrTable; - ULONG dwSize = 0; - BOOL result = FALSE; - - if (GetIpAddrTable(NULL, &dwSize, FALSE) != ERROR_INSUFFICIENT_BUFFER) + else + { + hEvent = Event; + } + + Status = NtDeviceIoControlFile( + IcmpHandle, + hEvent, + ApcRoutine, + ApcContext, + IoStatusBlock, + IOCTL_ICMP_ECHO_REQUEST, + InputBuffer, + ReplySize, + ReplyBuffer, + ReplySize); // TODO: Determine how Windows calculates OutputBufferLength. + + // If called asynchronously, return for the caller to handle. + if (Event != NULL || ApcRoutine != NULL) { - return result; + SetLastError(RtlNtStatusToDosError(Status)); + HeapFree(GetProcessHeap(), 0, InputBuffer); + return 0; } - pIpAddrTable = HeapAlloc(GetProcessHeap(), 0, dwSize); - if (GetIpAddrTable(pIpAddrTable, &dwSize, FALSE) == NO_ERROR) + // Otherwise handle it like IcmpSendEcho. + if (Status == STATUS_PENDING) { - INT i; + Status = NtWaitForSingleObject(hEvent, FALSE, NULL); - for (i = 0; i < (*pIpAddrTable).dwNumEntries; i++) + if (NT_SUCCESS(Status)) { - if ((*pIpAddrTable).table[i].dwIndex == Index) - { - *Address = (IPAddr)(*pIpAddrTable).table[i].dwAddr; - result = TRUE; - break; - } + Status = IoStatusBlock->Status; } } - HeapFree(GetProcessHeap(), 0, pIpAddrTable); - return result; -} -#endif // __REACTOS__ -/*********************************************************************** - * IcmpSendEcho (IPHLPAPI.@) - */ -DWORD WINAPI IcmpSendEcho( - HANDLE IcmpHandle, - IPAddr DestinationAddress, - LPVOID RequestData, - WORD RequestSize, - PIP_OPTION_INFORMATION RequestOptions, - LPVOID ReplyBuffer, - DWORD ReplySize, - DWORD Timeout - ) -{ - icmp_t* icp=(icmp_t*)IcmpHandle; - unsigned char* reqbuf; - int reqsize; - - struct icmp_echo_reply* ier; - struct ip* ip_header; - struct icmp* icmp_header; - char* endbuf; - int ip_header_len; - int maxlen; -#ifdef __REACTOS__ - fd_set fdr; - struct timeval timeout; -#else - struct pollfd fdr; -#endif - DWORD send_time,recv_time; - struct sockaddr_in addr; - socklen_t addrlen; - unsigned short id,seq,cksum; - int res; - - if (IcmpHandle==INVALID_HANDLE_VALUE) { - /* FIXME: in fact win98 seems to ignore the handle value !!! */ - SetLastError(ERROR_INVALID_HANDLE); - return 0; - } + CloseHandle(hEvent); + HeapFree(GetProcessHeap(), 0, InputBuffer); -#ifdef __REACTOS__ - if (ReplySize<sizeof(ICMP_ECHO_REPLY)) { - SetLastError(ERROR_INVALID_PARAMETER); + if (!NT_SUCCESS(Status)) + { + SetLastError(RtlNtStatusToDosError(Status)); return 0; } - if (ReplySize-RequestSize<sizeof(ICMP_ECHO_REPLY)) { - SetLastError(IP_GENERAL_FAILURE); - return 0; + Status = ((PICMP_ECHO_REPLY)ReplyBuffer)->Status; + if (Status != IP_SUCCESS) + { + SetLastError(Status); } - if (!ReplyBuffer) { - SetLastError(ERROR_INVALID_PARAMETER); - return 0; - } + nReplies = ((PICMP_ECHO_REPLY)ReplyBuffer)->Reserved; + ((PICMP_ECHO_REPLY)ReplyBuffer)->Reserved = 0; - if (Timeout == 0 || Timeout == -1) { + return nReplies; +} + +DWORD +WINAPI +IcmpSendEcho( + _In_ HANDLE IcmpHandle, + _In_ IPAddr DestinationAddress, + _In_ LPVOID RequestData, + _In_ WORD RequestSize, + _In_opt_ PIP_OPTION_INFORMATION RequestOptions, + _Out_ LPVOID ReplyBuffer, + _In_ DWORD ReplySize, + _In_ DWORD Timeout) +{ + HANDLE hEvent; + IO_STATUS_BLOCK IoStatusBlock; + PVOID InputBuffer; + ULONG InputBufferLength; + PICMP_ECHO_REQUEST Request; + DWORD nReplies; + NTSTATUS Status; + + if (Timeout == 0 || Timeout == (DWORD)-1) + { SetLastError(ERROR_INVALID_PARAMETER); -#else - if (ReplySize<sizeof(ICMP_ECHO_REPLY)+ICMP_MINLEN) { - SetLastError(IP_BUF_TOO_SMALL); -#endif return 0; } - /* check the request size against SO_MAX_MSG_SIZE using getsockopt */ - if (!DestinationAddress) { - SetLastError(ERROR_INVALID_NETNAME); + if (ReplySize < sizeof(ICMP_ECHO_REPLY)) + { + SetLastError(ERROR_INSUFFICIENT_BUFFER); return 0; } -#ifndef __REACTOS__ - if (icp->sid < 0) { - WARN("using system ping command since SOCK_RAW was not supported.\n"); - return system_icmp(DestinationAddress, RequestData, RequestSize, - RequestOptions, ReplyBuffer, ReplySize, Timeout); - } -#endif - - /* Prepare the request */ -#ifdef __REACTOS__ - id = GetCurrentProcessId() & 0xFFFF; -#else - id=getpid() & 0xFFFF; -#endif - seq=InterlockedIncrement(&icmp_sequence) & 0xFFFF; - -#ifdef __REACTOS__ - reqsize=ICMP_MINLEN; - if (RequestData && RequestSize > 0) - reqsize += RequestSize; -#else - reqsize=ICMP_MINLEN+RequestSize; -#endif - reqbuf=HeapAlloc(GetProcessHeap(), 0, reqsize); - if (reqbuf==NULL) { - SetLastError(ERROR_OUTOFMEMORY); + if (ReplySize < RequestSize + sizeof(ICMP_ECHO_REPLY)) + { + SetLastError(IP_GENERAL_FAILURE); return 0; } - icmp_header=(struct icmp*)reqbuf; - icmp_header->icmp_type=ICMP_ECHO; - icmp_header->icmp_code=0; - icmp_header->icmp_cksum=0; - icmp_header->icmp_id=id; - icmp_header->icmp_seq=seq; -#ifdef __REACTOS__ - if (RequestData && RequestSize > 0) - memcpy(reqbuf+ICMP_MINLEN, RequestData, RequestSize); -#else - memcpy(reqbuf+ICMP_MINLEN, RequestData, RequestSize); -#endif - icmp_header->icmp_cksum=cksum=in_cksum((u_short*)reqbuf,reqsize); - - addr.sin_family=AF_INET; - addr.sin_addr.s_addr=DestinationAddress; - addr.sin_port=0; - - if (RequestOptions!=NULL) { - int val; - if (icp->default_opts.OptionsSize==IP_OPTS_UNKNOWN) { - socklen_t len; - /* Before we mess with the options, get the default values */ - len=sizeof(val); - getsockopt(icp->sid,IPPROTO_IP,IP_TTL,(char *)&val,&len); - icp->default_opts.Ttl=val; - - len=sizeof(val); - getsockopt(icp->sid,IPPROTO_IP,IP_TOS,(char *)&val,&len); - icp->default_opts.Tos=val; - /* FIXME: missing: handling of IP 'flags', and all the other options */ - } + InputBufferLength = sizeof(ICMP_ECHO_REQUEST) + RequestSize; + if (RequestOptions != NULL) + InputBufferLength += RequestOptions->OptionsSize; - val=RequestOptions->Ttl; - setsockopt(icp->sid,IPPROTO_IP,IP_TTL,(char *)&val,sizeof(val)); - val=RequestOptions->Tos; - setsockopt(icp->sid,IPPROTO_IP,IP_TOS,(char *)&val,sizeof(val)); - /* FIXME: missing: handling of IP 'flags', and all the other options */ + if (InputBufferLength < ReplySize) + InputBufferLength = ReplySize; - icp->default_opts.OptionsSize=IP_OPTS_CUSTOM; - } else if (icp->default_opts.OptionsSize==IP_OPTS_CUSTOM) { - int val; + InputBuffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, InputBufferLength); + if (InputBuffer == NULL) + { + SetLastError(ERROR_NOT_ENOUGH_MEMORY); + return 0; + } - /* Restore the default options */ - val=icp->default_opts.Ttl; - setsockopt(icp->sid,IPPROTO_IP,IP_TTL,(char *)&val,sizeof(val)); - val=icp->default_opts.Tos; - setsockopt(icp->sid,IPPROTO_IP,IP_TOS,(char *)&val,sizeof(val)); - /* FIXME: missing: handling of IP 'flags', and all the other options */ + Request = (PICMP_ECHO_REQUEST)InputBuffer; + Request->Address = DestinationAddress; + Request->Timeout = Timeout; + Request->OptionsOffset = sizeof(ICMP_ECHO_REQUEST); + Request->DataOffset = sizeof(ICMP_ECHO_REQUEST); - icp->default_opts.OptionsSize=IP_OPTS_DEFAULT; - } + if (RequestOptions != NULL) + { + Request->HasOptions = TRUE; + Request->Ttl = RequestOptions->Ttl; + Request->Tos = RequestOptions->Tos; + Request->Flags = RequestOptions->Flags; - /* Get ready for receiving the reply - * Do it before we send the request to minimize the risk of introducing delays - */ -#ifdef __REACTOS__ - FD_ZERO(&fdr); - FD_SET(icp->sid,&fdr); - timeout.tv_sec=Timeout/1000; - timeout.tv_usec=(Timeout % 1000)*1000; -#else - fdr.fd = icp->sid; - fdr.events = POLLIN; -#endif - addrlen=sizeof(addr); - ier=ReplyBuffer; -#ifdef __REACTOS__ - endbuf=((char *) ReplyBuffer)+ReplySize; - maxlen=sizeof(struct ip)+ICMP_MINLEN+RequestSize; -#else - ip_header=(struct ip *) ((char *) ReplyBuffer+sizeof(ICMP_ECHO_REPLY)); - endbuf=(char *) ReplyBuffer+ReplySize; - maxlen=ReplySize-sizeof(ICMP_ECHO_REPLY); -#endif - - /* Send the packet */ - TRACE("Sending %d bytes (RequestSize=%d) to %s\n", reqsize, RequestSize, inet_ntoa(addr.sin_addr)); -#if 0 - if (TRACE_ON(icmp)){ - unsigned char* buf=(unsigned char*)reqbuf; - int i; - printf("Output buffer:\n"); - for (i=0;i<reqsize;i++) - printf("%2x,", buf[i]); - printf("\n"); - } -#endif - - send_time = GetTickCount(); -#ifdef __REACTOS__ - res=sendto(icp->sid, (const char*)reqbuf, reqsize, 0, (struct sockaddr*)&addr, sizeof(addr)); -#else - res=sendto(icp->sid, reqbuf, reqsize, 0, (struct sockaddr*)&addr, sizeof(addr)); -#endif - HeapFree(GetProcessHeap (), 0, reqbuf); - if (res<0) { -#ifdef __REACTOS__ - DWORD dwBestIfIndex; - IPAddr IP4Addr; - - ZeroMemory(&ier->Address, sizeof(ier->Address)); - - if (GetBestInterface(addr.sin_addr.s_addr, &dwBestIfIndex) == NO_ERROR && - GetIPv4ByIndex(dwBestIfIndex, &IP4Addr)) + if (RequestOptions->OptionsSize > 0) { - memcpy(&ier->Address, &IP4Addr, sizeof(IP4Addr)); - } + Request->OptionsSize = RequestOptions->OptionsSize; + Request->DataOffset += Request->OptionsSize; - if (WSAGetLastError()==WSAEMSGSIZE) - ier->Status = IP_PACKET_TOO_BIG; - else { - switch (WSAGetLastError()) { - case WSAENETUNREACH: - ier->Status = IP_DEST_NET_UNREACHABLE; - break; - case WSAEHOSTUNREACH: - ier->Status = IP_DEST_HOST_UNREACHABLE; - break; - default: - TRACE("unknown error: errno=%d\n",WSAGetLastError()); - ier->Status = IP_GENERAL_FAILURE; - ZeroMemory(&ier->Address, sizeof(ier->Address)); - } - } - return 1; -#else - if (errno==EMSGSIZE) - SetLastError(IP_PACKET_TOO_BIG); - else { - switch (errno) { - case ENETUNREACH: - SetLastError(IP_DEST_NET_UNREACHABLE); - break; - case EHOSTUNREACH: - SetLastError(IP_DEST_HOST_UNREACHABLE); - break; - default: - TRACE("unknown error: errno=%d\n",errno); - SetLastError(IP_GENERAL_FAILURE); - } + CopyMemory( + (PUCHAR)InputBuffer + sizeof(ICMP_ECHO_REQUEST), + RequestOptions->OptionsData, + Request->OptionsSize); } - return 0; -#endif } - /* Get the reply */ -#ifdef __REACTOS__ - ip_header=HeapAlloc(GetProcessHeap(), 0, maxlen); -#endif - ip_header_len=0; /* because gcc was complaining */ -#ifdef __REACTOS__ - while ((res=select(icp->sid+1,&fdr,NULL,NULL,&timeout))>0) { -#else - while (poll(&fdr,1,Timeout)>0) { -#endif - recv_time = GetTickCount(); -#ifdef __REACTOS__ - res=recvfrom(icp->sid, (char*)ip_header, maxlen, 0, (struct sockaddr*)&addr,(int*)&addrlen); -#else - res=recvfrom(icp->sid, (char*)ip_header, maxlen, 0, (struct sockaddr*)&addr,&addrlen); -#endif - TRACE("received %d bytes from %s\n",res, inet_ntoa(addr.sin_addr)); - ier->Status=IP_REQ_TIMED_OUT; -#ifdef __REACTOS__ - if (res < 0) - break; -#endif - - /* Check whether we should ignore this packet */ - if ((ip_header->ip_p==IPPROTO_ICMP) && (res>=sizeof(struct ip)+ICMP_MINLEN)) { - ip_header_len=ip_header->ip_hl << 2; - icmp_header=(struct icmp*)(((char*)ip_header)+ip_header_len); - TRACE("received an ICMP packet of type,code=%d,%d\n",icmp_header->icmp_type,icmp_header->icmp_code); - if (icmp_header->icmp_type==ICMP_ECHOREPLY) { - if ((icmp_header->icmp_id==id) && (icmp_header->icmp_seq==seq)) - ier->Status=IP_SUCCESS; - } else { - switch (icmp_header->icmp_type) { - case ICMP_UNREACH: - switch (icmp_header->icmp_code) { - case ICMP_UNREACH_HOST: -#ifdef ICMP_UNREACH_HOST_UNKNOWN - case ICMP_UNREACH_HOST_UNKNOWN: -#endif -#ifdef ICMP_UNREACH_ISOLATED - case ICMP_UNREACH_ISOLATED: -#endif -#ifdef ICMP_UNREACH_HOST_PROHIB - case ICMP_UNREACH_HOST_PROHIB: -#endif -#ifdef ICMP_UNREACH_TOSHOST - case ICMP_UNREACH_TOSHOST: -#endif - ier->Status=IP_DEST_HOST_UNREACHABLE; - break; - case ICMP_UNREACH_PORT: - ier->Status=IP_DEST_PORT_UNREACHABLE; - break; - case ICMP_UNREACH_PROTOCOL: - ier->Status=IP_DEST_PROT_UNREACHABLE; - break; - case ICMP_UNREACH_SRCFAIL: - ier->Status=IP_BAD_ROUTE; - break; - default: - ier->Status=IP_DEST_NET_UNREACHABLE; - } - break; - case ICMP_TIMXCEED: - if (icmp_header->icmp_code==ICMP_TIMXCEED_REASS) - ier->Status=IP_TTL_EXPIRED_REASSEM; - else - ier->Status=IP_TTL_EXPIRED_TRANSIT; - break; - case ICMP_PARAMPROB: - ier->Status=IP_PARAM_PROBLEM; - break; - case ICMP_SOURCEQUENCH: - ier->Status=IP_SOURCE_QUENCH; - break; - } - if (ier->Status!=IP_REQ_TIMED_OUT) { - struct ip* rep_ip_header; - struct icmp* rep_icmp_header; - /* The ICMP header size of all the packets we accept is the same */ - rep_ip_header=(struct ip*)(((char*)icmp_header)+ICMP_MINLEN); - rep_icmp_header=(struct icmp*)(((char*)rep_ip_header)+(rep_ip_header->ip_hl << 2)); - - /* Make sure that this is really a reply to our packet */ - if (ip_header_len+ICMP_MINLEN+(rep_ip_header->ip_hl << 2)+ICMP_MINLEN>ip_header->ip_len) { - ier->Status=IP_REQ_TIMED_OUT; - } else if ((rep_icmp_header->icmp_type!=ICMP_ECHO) || - (rep_icmp_header->icmp_code!=0) || - (rep_icmp_header->icmp_id!=id) || - /* windows doesn't check this checksum, else tracert */ - /* behind a Linux 2.2 masquerading firewall would fail*/ - /* (rep_icmp_header->icmp_cksum!=cksum) || */ - (rep_icmp_header->icmp_seq!=seq)) { - /* This was not a reply to one of our packets after all */ - TRACE("skipping type,code=%d,%d id,seq=%d,%d cksum=%d\n", - rep_icmp_header->icmp_type,rep_icmp_header->icmp_code, - rep_icmp_header->icmp_id,rep_icmp_header->icmp_seq, - rep_icmp_header->icmp_cksum); - TRACE("expected type,code=8,0 id,seq=%d,%d cksum=%d\n", - id,seq, - cksum); - ier->Status=IP_REQ_TIMED_OUT; - } - } - } - } - - if (ier->Status==IP_REQ_TIMED_OUT) { - /* This packet was not for us. - * Decrease the timeout so that we don't enter an endless loop even - * if we get flooded with ICMP packets that are not for us. - */ -#ifdef __REACTOS__ - int t = Timeout - (recv_time - send_time); - if (t < 0) t = 0; - timeout.tv_sec = t / 1000; - timeout.tv_usec = (t % 1000) * 1000; - FD_ZERO(&fdr); - FD_SET(icp->sid, &fdr); -#else - DWORD t = (recv_time - send_time); - if (Timeout > t) Timeout -= t; - else Timeout = 0; -#endif - continue; - } else { - /* This is a reply to our packet */ - memcpy(&ier->Address,&ip_header->ip_src,sizeof(IPAddr)); - /* Status is already set */ - ier->RoundTripTime= recv_time - send_time; - ier->DataSize=res-ip_header_len-ICMP_MINLEN; - ier->Reserved=0; - ier->Data=endbuf-ier->DataSize; - memmove(ier->Data,((char*)ip_header)+ip_header_len+ICMP_MINLEN,ier->DataSize); - ier->Options.Ttl=ip_header->ip_ttl; - ier->Options.Tos=ip_header->ip_tos; - ier->Options.Flags=ip_header->ip_off >> 13; - ier->Options.OptionsSize=ip_header_len-sizeof(struct ip); - if (ier->Options.OptionsSize!=0) { - ier->Options.OptionsData=(unsigned char *) ier->Data-ier->Options.OptionsSize; - /* FIXME: We are supposed to rearrange the option's 'source route' data */ - memmove(ier->Options.OptionsData,((char*)ip_header)+ip_header_len,ier->Options.OptionsSize); - endbuf=(char*)ier->Options.OptionsData; - } else { - ier->Options.OptionsData=NULL; - endbuf=ier->Data; - } - - /* Prepare for the next packet */ - ier++; -#ifndef __REACTOS__ - ip_header=(struct ip*)(((char*)ip_header)+sizeof(ICMP_ECHO_REPLY)); - maxlen=endbuf-(char*)ip_header; -#endif - - /* Check out whether there is more but don't wait this time */ -#ifdef __REACTOS__ - timeout.tv_sec=0; - timeout.tv_usec=0; -#else - Timeout=0; -#endif - } -#ifdef __REACTOS__ - FD_ZERO(&fdr); - FD_SET(icp->sid,&fdr); -#endif - } -#ifdef __REACTOS__ - HeapFree(GetProcessHeap(), 0, ip_header); -#endif - res=ier-(ICMP_ECHO_REPLY*)ReplyBuffer; - if (res==0) -#ifdef __REACTOS__ + if (RequestSize > 0) { - ier->Status = IP_REQ_TIMED_OUT; -#endif - SetLastError(IP_REQ_TIMED_OUT); -#ifdef __REACTOS__ + Request->DataSize = RequestSize; + CopyMemory((PUCHAR)InputBuffer + Request->DataOffset, RequestData, RequestSize); } -#endif - TRACE("received %d replies\n",res); - return res; -} -/*********************************************************************** - * IcmpSendEcho2 (IPHLPAPI.@) - */ -DWORD WINAPI IcmpSendEcho2( - HANDLE IcmpHandle, - HANDLE Event, - PIO_APC_ROUTINE ApcRoutine, - PVOID ApcContext, - IPAddr DestinationAddress, - LPVOID RequestData, - WORD RequestSize, - PIP_OPTION_INFORMATION RequestOptions, - LPVOID ReplyBuffer, - DWORD ReplySize, - DWORD Timeout - ) -{ - TRACE("(%p, %p, %p, %p, %08x, %p, %d, %p, %p, %d, %d): stub\n", IcmpHandle, - Event, ApcRoutine, ApcContext, DestinationAddress, RequestData, - RequestSize, RequestOptions, ReplyBuffer, ReplySize, Timeout); - - if (Event) - { - FIXME("unsupported for events\n"); - return 0; - } - if (ApcRoutine) + hEvent = CreateEventW(NULL, FALSE, FALSE, NULL); + if (hEvent == NULL) { - FIXME("unsupported for APCs\n"); + HeapFree(GetProcessHeap(), 0, InputBuffer); return 0; } - return IcmpSendEcho(IcmpHandle, DestinationAddress, RequestData, - RequestSize, RequestOptions, ReplyBuffer, ReplySize, Timeout); -} -/*********************************************************************** - * IcmpSendEcho2Ex (IPHLPAPI.@) - */ -DWORD WINAPI IcmpSendEcho2Ex( - HANDLE IcmpHandle, - HANDLE Event, - PIO_APC_ROUTINE ApcRoutine, - PVOID ApcContext, - IPAddr SourceAddress, - IPAddr DestinationAddress, - LPVOID RequestData, - WORD RequestSize, - PIP_OPTION_INFORMATION RequestOptions, - LPVOID ReplyBuffer, - DWORD ReplySize, - DWORD Timeout - ) -{ - TRACE("(%p, %p, %p, %p, %08x, %08x, %p, %d, %p, %p, %d, %d): stub\n", IcmpHandle, - Event, ApcRoutine, ApcContext, SourceAddress, DestinationAddress, RequestData, - RequestSize, RequestOptions, ReplyBuffer, ReplySize, Timeout); + Status = NtDeviceIoControlFile( + IcmpHandle, + hEvent, + NULL, + NULL, + &IoStatusBlock, + IOCTL_ICMP_ECHO_REQUEST, + InputBuffer, + InputBufferLength, + ReplyBuffer, + ReplySize); - if (Event) + if (Status == STATUS_PENDING) { - FIXME("unsupported for events\n"); - return 0; + Status = NtWaitForSingleObject(hEvent, FALSE, NULL); + + if (NT_SUCCESS(Status)) + { + Status = IoStatusBlock.Status; + } } - if (ApcRoutine) + + CloseHandle(hEvent); + HeapFree(GetProcessHeap(), 0, InputBuffer); + + if (!NT_SUCCESS(Status)) { - FIXME("unsupported for APCs\n"); + SetLastError(RtlNtStatusToDosError(Status)); return 0; } - if (SourceAddress) + + Status = ((PICMP_ECHO_REPLY)ReplyBuffer)->Status; + if (Status != IP_SUCCESS) { - FIXME("unsupported for source addresses\n"); - return 0; + SetLastError(Status); } - return IcmpSendEcho(IcmpHandle, DestinationAddress, RequestData, - RequestSize, RequestOptions, ReplyBuffer, ReplySize, Timeout); -} + nReplies = ((PICMP_ECHO_REPLY)ReplyBuffer)->Reserved; + ((PICMP_ECHO_REPLY)ReplyBuffer)->Reserved = 0; -/* - * Copyright (c) 1989 The Regents of the University of California. - * All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Mike Muuss. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ + return nReplies; +} diff --git a/dll/win32/iphlpapi/iphlpapi.spec b/dll/win32/iphlpapi/iphlpapi.spec index 6d186f35152..3151b5f40db 100644 --- a/dll/win32/iphlpapi/iphlpapi.spec +++ b/dll/win32/iphlpapi/iphlpapi.spec @@ -80,11 +80,11 @@ @ stub GetUdpTableFromStack @ stdcall GetUniDirectionalAdapterInfo( ptr ptr ) @ stdcall Icmp6CreateFile() -@ stdcall -stub Icmp6ParseReplies(ptr long) +@ stdcall Icmp6ParseReplies(ptr long) @ stdcall Icmp6SendEcho2(ptr ptr ptr ptr ptr ptr ptr long ptr ptr long long) @ stdcall IcmpCloseHandle(ptr) @ stdcall IcmpCreateFile() -@ stdcall -stub IcmpParseReplies(ptr long) +@ stdcall IcmpParseReplies(ptr long) @ stdcall IcmpSendEcho2(ptr ptr ptr ptr long ptr long ptr ptr long long) @ stdcall IcmpSendEcho(ptr long ptr long ptr ptr long long) @ stub InternalCreateIpForwardEntry diff --git a/sdk/include/psdk/ipexport.h b/sdk/include/psdk/ipexport.h index 98cd3a9b82f..82c89a1531d 100644 --- a/sdk/include/psdk/ipexport.h +++ b/sdk/include/psdk/ipexport.h @@ -28,14 +28,14 @@ typedef ULONG IPAddr; typedef ULONG IPMask; typedef ULONG IP_STATUS; -struct ip_option_information +typedef struct ip_option_information { unsigned char Ttl; unsigned char Tos; unsigned char Flags; unsigned char OptionsSize; unsigned char* OptionsData; -}; +} IP_OPTION_INFORMATION, *PIP_OPTION_INFORMATION; #if defined(_WIN64) @@ -64,20 +64,31 @@ struct ip_option_information32 #define MAX_OPT_SIZE 40 -struct icmp_echo_reply +typedef struct icmp_echo_request { - IPAddr Address; - ULONG Status; - ULONG RoundTripTime; - unsigned short DataSize; - unsigned short Reserved; - void* Data; - struct ip_option_information Options; -}; - -typedef struct ip_option_information IP_OPTION_INFORMATION, *PIP_OPTION_INFORMATION; - -typedef struct icmp_echo_reply ICMP_ECHO_REPLY, *PICMP_ECHO_REPLY; + IPAddr Address; + UINT32 Timeout; + UINT16 DataOffset; + UINT16 DataSize; + UINT8 HasOptions; + UINT8 Ttl; + UINT8 Tos; + UINT8 Flags; + UINT16 OptionsOffset; + UINT8 OptionsSize; + UINT8 Padding; +} ICMP_ECHO_REQUEST, *PICMP_ECHO_REQUEST; + +typedef struct icmp_echo_reply +{ + IPAddr Address; + UINT32 Status; + UINT32 RoundTripTime; + UINT16 DataSize; + UINT16 Reserved; + PVOID Data; + IP_OPTION_INFORMATION Options; +} ICMP_ECHO_REPLY, *PICMP_ECHO_REPLY; #ifdef _WIN64 struct icmp_echo_reply32 @@ -164,6 +175,16 @@ typedef struct _IPV6_ADDRESS_EX { } IPV6_ADDRESS_EX, *PIPV6_ADDRESS_EX; #include <poppack.h> +typedef struct _ICMPV6_ECHO_REQUEST +{ + IPV6_ADDRESS_EX DestinationAddress; + IPV6_ADDRESS_EX SourceAddress; + UINT32 Timeout; + UINT16 Unknown1; + UINT16 Ttl; // XXX: These seem unnecessarily large. + UINT32 Flags; // Is something else in the struct? +} ICMPV6_ECHO_REQUEST, *PICMPV6_ECHO_REQUEST; + typedef struct icmpv6_echo_reply_lh { IPV6_ADDRESS_EX Address; ULONG Status; diff --git a/sdk/include/psdk/tcpioctl.h b/sdk/include/psdk/tcpioctl.h index af7389155ca..cb9744bd508 100644 --- a/sdk/include/psdk/tcpioctl.h +++ b/sdk/include/psdk/tcpioctl.h @@ -46,6 +46,9 @@ #define IOCTL_DELETE_IP_ADDRESS \ _TCP_CTL_CODE(16, METHOD_BUFFERED, FILE_WRITE_ACCESS) +#define IOCTL_ICMP_ECHO_REQUEST \ + _TCP_CTL_CODE(0, METHOD_BUFFERED, FILE_ANY_ACCESS) + #define IF_MIB_STATS_ID 1 #define IP_MIB_STATS_ID 1 #define IP_MIB_ARPTABLE_ENTRY_ID 0x101
4 years, 8 months
1
0
0
0
[reactos] 02/06: [SDK][IP] Fix formatting
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=cf3ab9d15a2dc792e0b05…
commit cf3ab9d15a2dc792e0b059892cd3b163ca10cd78 Author: Victor Perevertkin <victor.perevertkin(a)reactos.org> AuthorDate: Fri Nov 22 22:04:56 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Apr 7 05:32:40 2020 +0300 [SDK][IP] Fix formatting --- sdk/lib/drivers/ip/transport/datagram/datagram.c | 224 ++++++++++++----------- 1 file changed, 113 insertions(+), 111 deletions(-) diff --git a/sdk/lib/drivers/ip/transport/datagram/datagram.c b/sdk/lib/drivers/ip/transport/datagram/datagram.c index 7c043997bfe..c910ed6c386 100644 --- a/sdk/lib/drivers/ip/transport/datagram/datagram.c +++ b/sdk/lib/drivers/ip/transport/datagram/datagram.c @@ -49,14 +49,15 @@ BOOLEAN DGRemoveIRP( return Found; } -VOID DGDeliverData( - PADDRESS_FILE AddrFile, - PIP_ADDRESS SrcAddress, - PIP_ADDRESS DstAddress, - USHORT SrcPort, - USHORT DstPort, - PIP_PACKET IPPacket, - UINT DataSize) +VOID +DGDeliverData( + PADDRESS_FILE AddrFile, + PIP_ADDRESS SrcAddress, + PIP_ADDRESS DstAddress, + USHORT SrcPort, + USHORT DstPort, + PIP_PACKET IPPacket, + UINT DataSize) /* * FUNCTION: Delivers datagram data to a user * ARGUMENTS: @@ -72,139 +73,140 @@ VOID DGDeliverData( * handler if it exists, otherwise we drop the packet. */ { - KIRQL OldIrql; - PTDI_IND_RECEIVE_DATAGRAM ReceiveHandler; - PVOID HandlerContext; - LONG AddressLength; - PVOID SourceAddress; - ULONG BytesTaken; - NTSTATUS Status; - PVOID DataBuffer; + KIRQL OldIrql; + PTDI_IND_RECEIVE_DATAGRAM ReceiveHandler; + PVOID HandlerContext; + LONG AddressLength; + PVOID SourceAddress; + ULONG BytesTaken; + NTSTATUS Status; + PVOID DataBuffer; - TI_DbgPrint(MAX_TRACE, ("Called.\n")); + TI_DbgPrint(MIN_TRACE, ("Called.\n")); - LockObject(AddrFile, &OldIrql); + LockObject(AddrFile, &OldIrql); - if (AddrFile->Protocol == IPPROTO_UDP) + if (AddrFile->Protocol == IPPROTO_UDP) { - DataBuffer = IPPacket->Data; + DataBuffer = IPPacket->Data; } - else + else if (AddrFile->HeaderIncl) + { + DataBuffer = IPPacket->Header; + } + else { - if (AddrFile->HeaderIncl) - DataBuffer = IPPacket->Header; - else - { - DataBuffer = IPPacket->Data; - DataSize -= IPPacket->HeaderSize; - } + DataBuffer = IPPacket->Data; + DataSize -= IPPacket->HeaderSize; } - if (!IsListEmpty(&AddrFile->ReceiveQueue)) + if (!IsListEmpty(&AddrFile->ReceiveQueue)) { - PLIST_ENTRY CurrentEntry; - PDATAGRAM_RECEIVE_REQUEST Current = NULL; - PTA_IP_ADDRESS RTAIPAddress; + PLIST_ENTRY CurrentEntry; + PDATAGRAM_RECEIVE_REQUEST Current = NULL; + PTA_IP_ADDRESS RTAIPAddress; - TI_DbgPrint(MAX_TRACE, ("There is a receive request.\n")); + TI_DbgPrint(MAX_TRACE, ("There is a receive request.\n")); - /* Search receive request list to find a match */ - CurrentEntry = AddrFile->ReceiveQueue.Flink; - while(CurrentEntry != &AddrFile->ReceiveQueue) { - Current = CONTAINING_RECORD(CurrentEntry, DATAGRAM_RECEIVE_REQUEST, ListEntry); - CurrentEntry = CurrentEntry->Flink; - if( DstPort == AddrFile->Port && - (AddrIsEqual(DstAddress, &AddrFile->Address) || - AddrIsUnspecified(&AddrFile->Address) || - AddrIsUnspecified(DstAddress))) { + /* Search receive request list to find a match */ + CurrentEntry = AddrFile->ReceiveQueue.Flink; + while (CurrentEntry != &AddrFile->ReceiveQueue) + { + Current = CONTAINING_RECORD(CurrentEntry, DATAGRAM_RECEIVE_REQUEST, ListEntry); + CurrentEntry = CurrentEntry->Flink; + if (DstPort == AddrFile->Port && + (AddrIsEqual(DstAddress, &AddrFile->Address) || + AddrIsUnspecified(&AddrFile->Address) || + AddrIsUnspecified(DstAddress))) + { - /* Remove the request from the queue */ - RemoveEntryList(&Current->ListEntry); + /* Remove the request from the queue */ + RemoveEntryList(&Current->ListEntry); - TI_DbgPrint(MAX_TRACE, ("Suitable receive request found.\n")); + TI_DbgPrint(MAX_TRACE, ("Suitable receive request found.\n")); - TI_DbgPrint(MAX_TRACE, + TI_DbgPrint(MAX_TRACE, ("Target Buffer: %x, Source Buffer: %x, Size %d\n", Current->Buffer, DataBuffer, DataSize)); - /* Copy the data into buffer provided by the user */ - RtlCopyMemory( Current->Buffer, - DataBuffer, - MIN(Current->BufferSize, DataSize) ); - - RTAIPAddress = (PTA_IP_ADDRESS)Current->ReturnInfo->RemoteAddress; - RTAIPAddress->TAAddressCount = 1; - RTAIPAddress->Address->AddressType = TDI_ADDRESS_TYPE_IP; - RTAIPAddress->Address->AddressLength = TDI_ADDRESS_LENGTH_IP; - RTAIPAddress->Address->Address->sin_port = SrcPort; - RTAIPAddress->Address->Address->in_addr = SrcAddress->Address.IPv4Address; - RtlZeroMemory(RTAIPAddress->Address->Address->sin_zero, 8); - - TI_DbgPrint(MAX_TRACE, ("(A: %08x) Addr %08x Port %04x\n", - RTAIPAddress, - SrcAddress->Address.IPv4Address, SrcPort)); - - ReferenceObject(AddrFile); - UnlockObject(AddrFile, OldIrql); - - /* Complete the receive request */ - if (Current->BufferSize < DataSize) - Current->Complete(Current->Context, STATUS_BUFFER_OVERFLOW, Current->BufferSize); - else - Current->Complete(Current->Context, STATUS_SUCCESS, DataSize); - - LockObject(AddrFile, &OldIrql); - DereferenceObject(AddrFile); - } - } - - UnlockObject(AddrFile, OldIrql); + /* Copy the data into buffer provided by the user */ + RtlCopyMemory(Current->Buffer, + DataBuffer, + MIN(Current->BufferSize, DataSize)); + + RTAIPAddress = (PTA_IP_ADDRESS)Current->ReturnInfo->RemoteAddress; + RTAIPAddress->TAAddressCount = 1; + RTAIPAddress->Address->AddressType = TDI_ADDRESS_TYPE_IP; + RTAIPAddress->Address->AddressLength = TDI_ADDRESS_LENGTH_IP; + RTAIPAddress->Address->Address->sin_port = SrcPort; + RTAIPAddress->Address->Address->in_addr = SrcAddress->Address.IPv4Address; + RtlZeroMemory(RTAIPAddress->Address->Address->sin_zero, 8); + + TI_DbgPrint(MAX_TRACE, ("(A: %08x) Addr %08x Port %04x\n", + RTAIPAddress, + SrcAddress->Address.IPv4Address, SrcPort)); + + ReferenceObject(AddrFile); + UnlockObject(AddrFile, OldIrql); + + /* Complete the receive request */ + if (Current->BufferSize < DataSize) + Current->Complete(Current->Context, STATUS_BUFFER_OVERFLOW, Current->BufferSize); + else + Current->Complete(Current->Context, STATUS_SUCCESS, DataSize); + + LockObject(AddrFile, &OldIrql); + DereferenceObject(AddrFile); + } + } + + UnlockObject(AddrFile, OldIrql); } - else if (AddrFile->RegisteredReceiveDatagramHandler) + else if (AddrFile->RegisteredReceiveDatagramHandler) { - TI_DbgPrint(MAX_TRACE, ("Calling receive event handler.\n")); + TI_DbgPrint(MAX_TRACE, ("Calling receive event handler.\n")); - ReceiveHandler = AddrFile->ReceiveDatagramHandler; - HandlerContext = AddrFile->ReceiveDatagramHandlerContext; + ReceiveHandler = AddrFile->ReceiveDatagramHandler; + HandlerContext = AddrFile->ReceiveDatagramHandlerContext; - if (SrcAddress->Type == IP_ADDRESS_V4) + if (SrcAddress->Type == IP_ADDRESS_V4) { - AddressLength = sizeof(IPv4_RAW_ADDRESS); - SourceAddress = &SrcAddress->Address.IPv4Address; + AddressLength = sizeof(IPv4_RAW_ADDRESS); + SourceAddress = &SrcAddress->Address.IPv4Address; } - else /* (Address->Type == IP_ADDRESS_V6) */ + else /* (Address->Type == IP_ADDRESS_V6) */ { - AddressLength = sizeof(IPv6_RAW_ADDRESS); - SourceAddress = SrcAddress->Address.IPv6Address; + AddressLength = sizeof(IPv6_RAW_ADDRESS); + SourceAddress = SrcAddress->Address.IPv6Address; } - ReferenceObject(AddrFile); - UnlockObject(AddrFile, OldIrql); - - Status = (*ReceiveHandler)(HandlerContext, - AddressLength, - SourceAddress, - 0, - NULL, - TDI_RECEIVE_ENTIRE_MESSAGE, - DataSize, - DataSize, - &BytesTaken, - DataBuffer, - NULL); - - if (STATUS_SUCCESS != Status) - TI_DbgPrint(MAX_TRACE, ("receive handler signaled failure with Status 0x%x\n", Status)); - - DereferenceObject(AddrFile); + ReferenceObject(AddrFile); + UnlockObject(AddrFile, OldIrql); + + Status = (*ReceiveHandler)(HandlerContext, + AddressLength, + SourceAddress, + 0, + NULL, + TDI_RECEIVE_ENTIRE_MESSAGE, + DataSize, + DataSize, + &BytesTaken, + DataBuffer, + NULL); + + if (STATUS_SUCCESS != Status) + TI_DbgPrint(MAX_TRACE, ("receive handler signaled failure with Status 0x%x\n", Status)); + + DereferenceObject(AddrFile); } - else + else { - UnlockObject(AddrFile, OldIrql); - TI_DbgPrint(MAX_TRACE, ("Discarding datagram.\n")); + UnlockObject(AddrFile, OldIrql); + TI_DbgPrint(MAX_TRACE, ("Discarding datagram.\n")); } - TI_DbgPrint(MAX_TRACE, ("Leaving.\n")); + TI_DbgPrint(MAX_TRACE, ("Leaving.\n")); }
4 years, 8 months
1
0
0
0
[reactos] 01/06: [TCPIP][FORMATTING] Format TiDispatch function. No functional changes
by Victor Perevertkin
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=792b64ea468179886a421…
commit 792b64ea468179886a42126165d59c79bc8e1bbf Author: Victor Perevertkin <victor.perevertkin(a)reactos.org> AuthorDate: Sun Nov 17 02:29:55 2019 +0300 Commit: Victor Perevertkin <victor(a)perevertkin.ru> CommitDate: Tue Apr 7 05:32:40 2020 +0300 [TCPIP][FORMATTING] Format TiDispatch function. No functional changes --- drivers/network/tcpip/tcpip/main.c | 95 ++++++++++++++++++++------------------ 1 file changed, 51 insertions(+), 44 deletions(-) diff --git a/drivers/network/tcpip/tcpip/main.c b/drivers/network/tcpip/tcpip/main.c index 1b8ab52df22..919d0260221 100644 --- a/drivers/network/tcpip/tcpip/main.c +++ b/drivers/network/tcpip/tcpip/main.c @@ -473,23 +473,26 @@ TiDispatchInternal( } +/** + * @brief Dispatch routine for IRP_MJ_DEVICE_CONTROL requests + * + * @param[in] DeviceObject + * Pointer to a device object for this driver + * @param[in] Irp + * Pointer to a I/O request packet + * + * @return + * Status of the operation + */ NTSTATUS NTAPI TiDispatch( PDEVICE_OBJECT DeviceObject, PIRP Irp) -/* - * FUNCTION: Dispatch routine for IRP_MJ_DEVICE_CONTROL requests - * ARGUMENTS: - * DeviceObject = Pointer to a device object for this driver - * Irp = Pointer to a I/O request packet - * RETURNS: - * Status of the operation - */ { NTSTATUS Status; PIO_STACK_LOCATION IrpSp; - IrpSp = IoGetCurrentIrpStackLocation(Irp); + IrpSp = IoGetCurrentIrpStackLocation(Irp); TI_DbgPrint(DEBUG_IRP, ("[TCPIP, TiDispatch] Called. IRP is at (0x%X).\n", Irp)); @@ -497,51 +500,55 @@ TiDispatch( #if 0 Status = TdiMapUserRequest(DeviceObject, Irp, IrpSp); - if (NT_SUCCESS(Status)) { + if (NT_SUCCESS(Status)) + { TiDispatchInternal(DeviceObject, Irp); Status = STATUS_PENDING; - } else { + } + else + { #else if (TRUE) { #endif - /* See if this request is TCP/IP specific */ - switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) { - case IOCTL_TCP_QUERY_INFORMATION_EX: - TI_DbgPrint(MIN_TRACE, ("TCP_QUERY_INFORMATION_EX\n")); - Status = DispTdiQueryInformationEx(Irp, IrpSp); - break; - - case IOCTL_TCP_SET_INFORMATION_EX: - TI_DbgPrint(MIN_TRACE, ("TCP_SET_INFORMATION_EX\n")); - Status = DispTdiSetInformationEx(Irp, IrpSp); - break; - - case IOCTL_SET_IP_ADDRESS: - TI_DbgPrint(MIN_TRACE, ("SET_IP_ADDRESS\n")); - Status = DispTdiSetIPAddress(Irp, IrpSp); - break; - - case IOCTL_DELETE_IP_ADDRESS: - TI_DbgPrint(MIN_TRACE, ("DELETE_IP_ADDRESS\n")); - Status = DispTdiDeleteIPAddress(Irp, IrpSp); - break; - - case IOCTL_QUERY_IP_HW_ADDRESS: - TI_DbgPrint(MIN_TRACE, ("QUERY_IP_HW_ADDRESS\n")); - Status = DispTdiQueryIpHwAddress(DeviceObject, Irp, IrpSp); - break; - - default: - TI_DbgPrint(MIN_TRACE, ("Unknown IOCTL 0x%X\n", - IrpSp->Parameters.DeviceIoControl.IoControlCode)); - Status = STATUS_NOT_IMPLEMENTED; - break; + /* See if this request is TCP/IP specific */ + switch (IrpSp->Parameters.DeviceIoControl.IoControlCode) + { + case IOCTL_TCP_QUERY_INFORMATION_EX: + TI_DbgPrint(MIN_TRACE, ("TCP_QUERY_INFORMATION_EX\n")); + Status = DispTdiQueryInformationEx(Irp, IrpSp); + break; + + case IOCTL_TCP_SET_INFORMATION_EX: + TI_DbgPrint(MIN_TRACE, ("TCP_SET_INFORMATION_EX\n")); + Status = DispTdiSetInformationEx(Irp, IrpSp); + break; + + case IOCTL_SET_IP_ADDRESS: + TI_DbgPrint(MIN_TRACE, ("SET_IP_ADDRESS\n")); + Status = DispTdiSetIPAddress(Irp, IrpSp); + break; + + case IOCTL_DELETE_IP_ADDRESS: + TI_DbgPrint(MIN_TRACE, ("DELETE_IP_ADDRESS\n")); + Status = DispTdiDeleteIPAddress(Irp, IrpSp); + break; + + case IOCTL_QUERY_IP_HW_ADDRESS: + TI_DbgPrint(MIN_TRACE, ("QUERY_IP_HW_ADDRESS\n")); + Status = DispTdiQueryIpHwAddress(DeviceObject, Irp, IrpSp); + break; + + default: + TI_DbgPrint(MIN_TRACE, ("Unknown IOCTL 0x%X\n", + IrpSp->Parameters.DeviceIoControl.IoControlCode)); + Status = STATUS_NOT_IMPLEMENTED; + break; } } TI_DbgPrint(DEBUG_IRP, ("[TCPIP, TiDispatch] Leaving. Status = (0x%X).\n", Status)); - return IRPFinish( Irp, Status ); + return IRPFinish(Irp, Status); }
4 years, 8 months
1
0
0
0
[reactos] 01/01: [USETUP] de-DE Whitespace nitpicking CORE-16792
by Joachim Henze
https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1fdf06c5632b0d3a19525…
commit 1fdf06c5632b0d3a1952500cb2bfab546e69906e Author: Joachim Henze <Joachim.Henze(a)reactos.org> AuthorDate: Mon Apr 6 21:28:45 2020 +0200 Commit: Joachim Henze <Joachim.Henze(a)reactos.org> CommitDate: Mon Apr 6 21:28:45 2020 +0200 [USETUP] de-DE Whitespace nitpicking CORE-16792 To harmonize it to 3 separator-spaces how it is done historically in other dlgs. --- base/setup/usetup/lang/de-DE.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/base/setup/usetup/lang/de-DE.h b/base/setup/usetup/lang/de-DE.h index cb35979456d..3af245019b2 100644 --- a/base/setup/usetup/lang/de-DE.h +++ b/base/setup/usetup/lang/de-DE.h @@ -81,7 +81,7 @@ static MUI_ENTRY deDELanguagePageEntries[] = { 0, 0, - "EINGABETASTE = Fortsetzen F3 = Installation abbrechen", + "EINGABETASTE = Fortsetzen F3 = Installation abbrechen", TEXT_TYPE_STATUS | TEXT_PADDING_BIG, TEXT_ID_STATIC }, @@ -866,7 +866,7 @@ static MUI_ENTRY deDEDisplayPageEntries[] = { 0, 0, - "EINGABETASTE = Fortsetzen ESC = Zur\201ck F3 = Installation abbrechen", + "EINGABETASTE = Fortsetzen ESC = Zur\201ck F3 = Installation abbrechen", TEXT_TYPE_STATUS | TEXT_PADDING_BIG, TEXT_ID_STATIC },
4 years, 8 months
1
0
0
0
← Newer
1
...
32
33
34
35
36
37
38
39
40
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
Results per page:
10
25
50
100
200