@@ -13,6 +13,7 @@ module;
1313#pragma warning (disable : 4005)
1414#include " targetver.h"
1515#include " WinMTRRoutePolicy.h"
16+ #include " WinMTRProbeParameters.h"
1617#define WIN32_LEAN_AND_MEAN
1718#define VC_EXTRALEAN
1819#define NOMCX
@@ -167,27 +168,6 @@ struct parsed_reply final {
167168 return reply_header + sizeof (IO_STATUS_BLOCK ) + request_size + 8u ;
168169}
169170
170- [[nodiscard]] std::vector<std::byte> make_payload (const WinMTRTraceOptions& options,
171- std::uint64_t & random_state)
172- {
173- std::vector<std::byte> payload (options.packet_size );
174- if (options.payload_pattern >= 0 ) {
175- std::fill (payload.begin (), payload.end (),
176- static_cast <std::byte>(options.payload_pattern ));
177- return payload;
178- }
179-
180- // Small xorshift generator: no runtime dependency and random mode changes
181- // every byte without claiming cryptographic randomness.
182- for (auto & value : payload) {
183- random_state ^= random_state << 13u ;
184- random_state ^= random_state >> 7u ;
185- random_state ^= random_state << 17u ;
186- value = static_cast <std::byte>(random_state & 0xffu );
187- }
188- return payload;
189- }
190-
191171[[nodiscard]] unique_icmp_handle create_icmp_handle (ADDRESS_FAMILY family) noexcept
192172{
193173 if (family == AF_INET ) {
@@ -209,11 +189,12 @@ void issue_probe(pending_probe& probe, HANDLE icmp_handle,
209189 }
210190
211191 probe.reply_buffer .resize (reply_buffer_size (destination.si_family , payload.size ()));
212- probe.ip_options .Ttl = static_cast <UCHAR >(probe.ttl );
213- probe.ip_options .Tos = static_cast <UCHAR >(options.tos );
214- probe.ip_options .Flags = destination.si_family == AF_INET && options.dont_fragment
215- ? IP_FLAG_DF
216- : 0 ;
192+ const auto wire_options = winmtr::probe_parameters::make_wire_options (
193+ probe.ttl , options.tos , options.dont_fragment ,
194+ destination.si_family == AF_INET );
195+ probe.ip_options .Ttl = wire_options.ttl ;
196+ probe.ip_options .Tos = wire_options.tos ;
197+ probe.ip_options .Flags = wire_options.dont_fragment ? IP_FLAG_DF : 0 ;
217198
218199 DWORD result = 0 ;
219200 SetLastError (ERROR_SUCCESS );
@@ -321,7 +302,8 @@ void issue_probe(pending_probe& probe, HANDLE icmp_handle,
321302 probe.ttl = 1 ;
322303 std::uint64_t random_state = GetTickCount64 ()
323304 ^ static_cast <std::uint64_t >(candidate.si_family );
324- const auto payload = make_payload (options, random_state);
305+ const auto payload = winmtr::probe_parameters::make_payload (
306+ options.packet_size , options.payload_pattern , random_state);
325307 issue_probe (probe, handle.get (), candidate, options, payload, timeout_ms);
326308 if (stop_token.stop_requested ()) return false ;
327309 const auto parsed = parse_reply (probe, candidate.si_family );
@@ -845,7 +827,8 @@ WinMTRTraceResult WinMTRNet::DoTrace(std::stop_token stop_token, SOCKADDR_INET a
845827 request->icmp_handle = create_icmp_handle (address.si_family );
846828 request->destination = address;
847829 request->options = trace_options;
848- request->payload = make_payload (trace_options, random_state);
830+ request->payload = winmtr::probe_parameters::make_payload (
831+ trace_options.packet_size , trace_options.payload_pattern , random_state);
849832 request->timeout_ms = trace_options.timeout_ms ;
850833 request->completions = &completions;
851834 if (!request->icmp_handle ) {
0 commit comments