コード例 #1
0
        public async Task SendPingAsyncWithHostAndTtlAndFragmentPingOptions(bool fragment)
        {
            IPAddress[] localIpAddresses = await TestSettings.GetLocalIPAddressesAsync();

            byte[] buffer = TestSettings.PayloadAsBytes;

            PingOptions options = new PingOptions();

            options.Ttl          = 32;
            options.DontFragment = fragment;

            await SendBatchPingAsync(
                (ping) => ping.SendPingAsync(TestSettings.LocalHost, TestSettings.PingTimeout, buffer, options),
                (pingReply) =>
            {
                PingResultValidator(pingReply, localIpAddresses);
            });
        }
コード例 #2
0
        public async Task SendPingAsyncWithHostAndTimeoutAndBufferAndPingOptions_Unix()
        {
            IPAddress[] localIpAddresses = await TestSettings.GetLocalIPAddressesAsync();

            byte[] buffer = TestSettings.PayloadAsBytes;
            await SendBatchPingAsync(
                (ping) => ping.SendPingAsync(TestSettings.LocalHost, TestSettings.PingTimeout, buffer, new PingOptions()),
                (pingReply) =>
            {
                PingResultValidator(pingReply, localIpAddresses);

                // Non-root pings cannot send arbitrary data in the buffer, and do not receive it back in the PingReply.
                if (Capability.CanUseRawSockets(pingReply.Address.AddressFamily))
                {
                    Assert.Equal(buffer, pingReply.Buffer);
                }
                else
                {
                    Assert.Equal(Array.Empty <byte>(), pingReply.Buffer);
                }
            });
        }