예제 #1
0
        public void SendPingWithIPAddressAndTimeoutAndBufferAndPingOptions_Unix(AddressFamily addressFamily)
        {
            IPAddress localIpAddress = TestSettings.GetLocalIPAddress(addressFamily);

            if (localIpAddress == null)
            {
                // No local address for given address family.
                return;
            }

            byte[] buffer = TestSettings.PayloadAsBytes;
            SendBatchPing(
                (ping) => ping.Send(localIpAddress, TestSettings.PingTimeout, buffer, new PingOptions()),
                (pingReply) =>
            {
                PingResultValidator(pingReply, localIpAddress);

                // Non-root pings cannot send arbitrary data in the buffer, and do not receive it back in the PingReply.
                if (Capability.CanUseRawSockets(localIpAddress.AddressFamily) || PlatformDetection.IsOSXLike)
                {
                    Assert.Equal(buffer, pingReply.Buffer);
                }
                else
                {
                    Assert.Equal(Array.Empty <byte>(), pingReply.Buffer);
                }
            });
        }
예제 #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);
                }
            });
        }
예제 #3
0
        public void SendPingWithIPAddressAndTimeoutAndBuffer_Unix()
        {
            byte[]    buffer         = TestSettings.PayloadAsBytes;
            IPAddress localIpAddress = TestSettings.GetLocalIPAddress();

            SendBatchPing(
                (ping) => ping.Send(localIpAddress, TestSettings.PingTimeout, buffer),
                (pingReply) =>
            {
                PingResultValidator(pingReply, localIpAddress);

                // Non-root pings cannot send arbitrary data in the buffer, and do not receive it back in the PingReply.
                if (Capability.CanUseRawSockets(localIpAddress.AddressFamily))
                {
                    Assert.Equal(buffer, pingReply.Buffer);
                }
                else
                {
                    Assert.Equal(Array.Empty <byte>(), pingReply.Buffer);
                }
            });
        }
예제 #4
0
        public void SendPingWithHostAndTimeoutAndBuffer_Unix()
        {
            IPAddress[] localIpAddresses = TestSettings.GetLocalIPAddresses();

            byte[] buffer = TestSettings.PayloadAsBytes;
            SendBatchPing(
                (ping) => ping.Send(TestSettings.LocalHost, TestSettings.PingTimeout, buffer),
                (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) || PlatformDetection.IsOSXLike)
                {
                    Assert.Equal(buffer, pingReply.Buffer);
                }
                else
                {
                    Assert.Equal(Array.Empty <byte>(), pingReply.Buffer);
                }
            });
        }
예제 #5
0
        public async Task SendPingAsyncWithIPAddressAndTimeoutAndBuffer_Unix()
        {
            byte[]    buffer         = TestSettings.PayloadAsBytes;
            IPAddress localIpAddress = await TestSettings.GetLocalIPAddressAsync();

            await SendBatchPingAsync(
                (ping) => ping.SendPingAsync(localIpAddress, TestSettings.PingTimeout, buffer),
                (pingReply) =>
            {
                PingResultValidator(pingReply, localIpAddress);

                // Non-root pings cannot send arbitrary data in the buffer, and do not receive it back in the PingReply.
                if (Capability.CanUseRawSockets(localIpAddress.AddressFamily) || PlatformDetection.IsOSXLike)
                {
                    Assert.Equal(buffer, pingReply.Buffer);
                }
                else
                {
                    Assert.Equal(Array.Empty <byte>(), pingReply.Buffer);
                }
            });
        }
예제 #6
0
        public async Task SendPingAsyncWithHostAndTimeoutAndBuffer_Unix()
        {
            IPAddress localIpAddress = await TestSettings.GetLocalIPAddress();

            byte[] buffer = TestSettings.PayloadAsBytes;
            await SendBatchPingAsync(
                (ping) => ping.SendPingAsync(TestSettings.LocalHost, TestSettings.PingTimeout, buffer),
                (pingReply) =>
            {
                Assert.Equal(IPStatus.Success, pingReply.Status);
                Assert.True(pingReply.Address.Equals(localIpAddress));

                // Non-root pings cannot send arbitrary data in the buffer, and do not receive it back in the PingReply.
                if (Capability.CanUseRawSockets())
                {
                    Assert.Equal(buffer, pingReply.Buffer);
                }
                else
                {
                    Assert.Equal(Array.Empty <byte>(), pingReply.Buffer);
                }
            });
        }
예제 #7
0
 private static byte[] GetPingPayload(AddressFamily addressFamily)
 // On Unix, Non-root processes cannot send arbitrary data in the ping packet payload
 => Capability.CanUseRawSockets(addressFamily) || PlatformDetection.IsOSXLike
         ? TestSettings.PayloadAsBytes
         : Array.Empty <byte>();