-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
System.Net.NetworkInformation.Ping needs sudo to ping an endpoint in .NET 7 preview 2 #66746
Comments
Tagging subscribers to this area: @dotnet/ncl Issue DetailsDescriptionPowerShell uses the System.Net.NetworkInformation.Ping API for Test-Connection cmdlet for pinging. Since .NET 7 Preview 2 we see that sudo is needed for using the cmdlet. It works fine on macOS. This is a regression from .NET 6. Output from test app: PS /home/aditya/PingTest> /home/aditya/PingTest/bin/Debug/net6.0/linux-x64/publish/PingTest www.google.com PS /home/aditya/PingTest> /home/aditya/PingTest/bin/Debug/net7.0/linux-x64/publish/PingTest www.google.com PS /home/aditya/PingTest> sudo /home/aditya/PingTest/bin/Debug/net7.0/linux-x64/publish/PingTest www.google.com Reproduction Stepsdotnet new console -b PingTest Contents for Program.cs // See https://aka.ms/new-console-template for more information
using System;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;
Console.WriteLine("Hello");
Ping pingSender = new Ping();
PingOptions options = new PingOptions();
// Use the default Ttl value which is 128,
// but change the fragmentation behavior.
//options.DontFragment = true;
// Create a buffer of 32 bytes of data to be transmitted.
string data = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
byte[] buffer = Encoding.ASCII.GetBytes(data);
int timeout = 120;
PingReply reply = pingSender.Send(args[0], timeout, buffer, options);
if (reply.Status == IPStatus.Success)
{
Console.WriteLine("Address: {0}", reply.Address.ToString());
Console.WriteLine("RoundTrip time: {0}", reply.RoundtripTime);
} dotnet run www.google.com Expected behaviorHello Actual behaviorHello Regression?Yes, from .NET 6. Same project when targeted for .NET 6 works fine. Known WorkaroundsNo response ConfigurationUbuntu 20.04 with .NET 7 preview 2. Other informationNo response
|
This is caused by #64625 and it was an intentional change. Sending custom payloads was never supported when running through the |
As filipnavara mentioned, this was an intentional change. If the provided custom payload is not important for your use case, using overload which does not accept it (or using an empty array) should work fine. I see we did not document this breaking change, in case we want to keep this behavior, we need to document it. |
Triage: We need to document it as breaking change in 7.0. |
Task for changing docs created: dotnet/docs#28720 |
Description
PowerShell uses the System.Net.NetworkInformation.Ping API for Test-Connection cmdlet for pinging. Since .NET 7 Preview 2 we see that sudo is needed for using the cmdlet. It works fine on macOS.
This is a regression from .NET 6.
Output from test app:
PS /home/aditya/PingTest> /home/aditya/PingTest/bin/Debug/net6.0/linux-x64/publish/PingTest www.google.com
Hello
Address: 142.250.217.100
RoundTrip time: 12
PS /home/aditya/PingTest> /home/aditya/PingTest/bin/Debug/net7.0/linux-x64/publish/PingTest www.google.com
$(String[] args) in /home/aditya/PingTest/Program.cs:line 20Hello
Unhandled exception. System.PlatformNotSupportedException: Unable to send custom ping payload. Run program under privileged user account or grant cap_net_raw capability using setcap(8).
at System.Net.NetworkInformation.Ping.GetPingProcess(IPAddress address, Byte[] buffer, Int32 timeout, PingOptions options)
at System.Net.NetworkInformation.Ping.SendWithPingUtility(IPAddress address, Byte[] buffer, Int32 timeout, PingOptions options)
at System.Net.NetworkInformation.Ping.SendPingCore(IPAddress address, Byte[] buffer, Int32 timeout, PingOptions options)
at System.Net.NetworkInformation.Ping.GetAddressAndSend(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options)
at System.Net.NetworkInformation.Ping.Send(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options)
at Program.
PS /home/aditya/PingTest> sudo /home/aditya/PingTest/bin/Debug/net7.0/linux-x64/publish/PingTest www.google.com
Hello
Address: 142.250.217.100
RoundTrip time: 13
Reproduction Steps
dotnet new console -b PingTest
Contents for Program.cs
dotnet run www.google.com
Expected behavior
Hello
Address: 204.79.197.200
RoundTrip time: 24
Time to live: 128
Don't fragment: False
Buffer size: 32
Actual behavior
Hello
$(String[] args) in /home/aditya/PingTest/Program.cs:line 20Unhandled exception. System.PlatformNotSupportedException: Unable to send custom ping payload. Run program under privileged user account or grant cap_net_raw capability using setcap(8).
at System.Net.NetworkInformation.Ping.GetPingProcess(IPAddress address, Byte[] buffer, Int32 timeout, PingOptions options)
at System.Net.NetworkInformation.Ping.SendWithPingUtility(IPAddress address, Byte[] buffer, Int32 timeout, PingOptions options)
at System.Net.NetworkInformation.Ping.SendPingCore(IPAddress address, Byte[] buffer, Int32 timeout, PingOptions options)
at System.Net.NetworkInformation.Ping.GetAddressAndSend(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options)
at System.Net.NetworkInformation.Ping.Send(String hostNameOrAddress, Int32 timeout, Byte[] buffer, PingOptions options)
at Program.
Regression?
Yes, from .NET 6. Same project when targeted for .NET 6 works fine.
Known Workarounds
No response
Configuration
Ubuntu 20.04 with .NET 7 preview 2.
Other information
No response
The text was updated successfully, but these errors were encountered: