|
| 1 | +--- |
| 2 | +title: "Breaking change: Custom ping payloads on Linux" |
| 3 | +description: Learn about the .NET 7 breaking change in networking where an exception is thrown on non-privileged Linux processes when a custom payload is passed to the Ping method. |
| 4 | +ms.date: 03/23/2022 |
| 5 | +--- |
| 6 | +# Custom ping payloads on Linux |
| 7 | + |
| 8 | +On Linux, non-privileged processes can't send raw IP packets. <xref:System.Net.NetworkInformation.Ping> functionality is implemented by interfacing with the `ping` utility. However, this utility doesn't support specifying a custom payload for the Internet Control Message Protocol (ICMP) ping packets. NET 7 adds a check for such cases and throws an exception if a custom payload is specified. |
| 9 | + |
| 10 | +## Previous behavior |
| 11 | + |
| 12 | +In previous versions, the ping packet payload was silently ignored (that is, it wasn't sent) on non-privileged Linux processes. |
| 13 | + |
| 14 | +## New behavior |
| 15 | + |
| 16 | +Starting in .NET 7, a <xref:System.PlatformNotSupportedException> is thrown if you attempt to send a custom ping packet payload when running in non-privileged Linux process. |
| 17 | + |
| 18 | +## Version introduced |
| 19 | + |
| 20 | +.NET 7 Preview 2 |
| 21 | + |
| 22 | +## Type of breaking change |
| 23 | + |
| 24 | +This change can affect [binary compatibility](../../categories.md#binary-compatibility). |
| 25 | + |
| 26 | +## Reason for change |
| 27 | + |
| 28 | +It's better to signal to the user that the operation cannot be performed instead of silently dropping the payload. |
| 29 | + |
| 30 | +## Recommended action |
| 31 | + |
| 32 | +If a ping payload is necessary, run the application as `root`, or grant the `cap_net_raw` capability using the `setcap` utility. |
| 33 | + |
| 34 | +Otherwise, use an overload of <xref:System.Net.NetworkInformation.Ping.SendPingAsync%2A?displayProperty=nameWithType> that does not accept a custom payload, or pass in an empty array. |
| 35 | + |
| 36 | +## Affected APIs |
| 37 | + |
| 38 | +- <xref:System.Net.NetworkInformation.Ping.Send(System.Net.IPAddress,System.Int32,System.Byte[],System.Net.NetworkInformation.PingOptions)?displayProperty=fullName> |
| 39 | +- <xref:System.Net.NetworkInformation.Ping.Send(System.Net.IPAddress,System.Int32,System.Byte[])?displayProperty=fullName> |
| 40 | +- <xref:System.Net.NetworkInformation.Ping.Send(System.String,System.Int32,System.Byte[],System.Net.NetworkInformation.PingOptions)?displayProperty=fullName> |
| 41 | +- <xref:System.Net.NetworkInformation.Ping.Send(System.String,System.Int32,System.Byte[])?displayProperty=fullName> |
| 42 | +- <xref:System.Net.NetworkInformation.Ping.SendAsync(System.Net.IPAddress,System.Int32,System.Byte[],System.Net.NetworkInformation.PingOptions,System.Object)?displayProperty=fullName> |
| 43 | +- <xref:System.Net.NetworkInformation.Ping.SendAsync(System.Net.IPAddress,System.Int32,System.Byte[],System.Object)?displayProperty=fullName> |
| 44 | +- <xref:System.Net.NetworkInformation.Ping.SendAsync(System.String,System.Int32,System.Byte[],System.Net.NetworkInformation.PingOptions,System.Object)?displayProperty=fullName> |
| 45 | +- <xref:System.Net.NetworkInformation.Ping.SendAsync(System.String,System.Int32,System.Byte[],System.Object)?displayProperty=fullName> |
| 46 | +- <xref:System.Net.NetworkInformation.Ping.SendPingAsync(System.Net.IPAddress,System.Int32,System.Byte[],System.Net.NetworkInformation.PingOptions)?displayProperty=fullName> |
| 47 | +- <xref:System.Net.NetworkInformation.Ping.SendPingAsync(System.Net.IPAddress,System.Int32,System.Byte[])?displayProperty=fullName> |
| 48 | +- <xref:System.Net.NetworkInformation.Ping.SendPingAsync(System.String,System.Int32,System.Byte[],System.Net.NetworkInformation.PingOptions)?displayProperty=fullName> |
| 49 | +- <xref:System.Net.NetworkInformation.Ping.SendPingAsync(System.String,System.Int32,System.Byte[])?displayProperty=fullName> |
0 commit comments