Skip to content
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

Annotate System.Net.Ping for nullable reference types #32131

Merged
merged 1 commit into from
Feb 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System;
using System.Net.NetworkInformation;
using System.Runtime.InteropServices;
Expand All @@ -22,7 +23,7 @@ internal struct IPOptions
internal byte optionsSize;
internal IntPtr optionsData;

internal IPOptions(PingOptions options)
internal IPOptions(PingOptions? options)
{
ttl = 128;
tos = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
Expand All @@ -16,14 +17,14 @@ internal static class UnixCommandLinePing
private const string s_ipv4PingFile = "ping";
private const string s_ipv6PingFile = "ping6";

private static readonly string s_discoveredPing4UtilityPath = GetPingUtilityPath(ipv4: true);
private static readonly string s_discoveredPing6UtilityPath = GetPingUtilityPath(ipv4: false);
private static readonly string? s_discoveredPing4UtilityPath = GetPingUtilityPath(ipv4: true);
private static readonly string? s_discoveredPing6UtilityPath = GetPingUtilityPath(ipv4: false);
private static readonly bool s_isBSD = RuntimeInformation.IsOSPlatform(OSPlatform.OSX) || RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD"));
private static readonly Lazy<bool> s_isBusybox = new Lazy<bool>(() => IsBusyboxPing(s_discoveredPing4UtilityPath));

// We don't want to pick up an arbitrary or malicious ping
// command, so that's why we do the path probing ourselves.
private static string GetPingUtilityPath(bool ipv4)
private static string? GetPingUtilityPath(bool ipv4)
{
string fileName = ipv4 ? s_ipv4PingFile : s_ipv6PingFile;
foreach (string folder in s_binFolders)
Expand All @@ -39,14 +40,17 @@ private static string GetPingUtilityPath(bool ipv4)
}

// Check if found ping is symlink to busybox like alpine /bin/ping -> /bin/busybox
private static unsafe bool IsBusyboxPing(string pingBinary)
private static unsafe bool IsBusyboxPing(string? pingBinary)
{
string linkedName = Interop.Sys.ReadLink(pingBinary);

// If pingBinary is not link linkedName will be null
if (linkedName != null && linkedName.EndsWith("busybox", StringComparison.Ordinal))
if (pingBinary != null)
{
return true;
string? linkedName = Interop.Sys.ReadLink(pingBinary);

// If pingBinary is not link linkedName will be null
if (linkedName != null && linkedName.EndsWith("busybox", StringComparison.Ordinal))
{
return true;
}
}

return false;
Expand All @@ -57,12 +61,12 @@ public enum PingFragmentOptions { Default, Do, Dont };
/// <summary>
/// The location of the IPv4 ping utility on the current machine.
/// </summary>
public static string Ping4UtilityPath { get { return s_discoveredPing4UtilityPath; } }
public static string? Ping4UtilityPath { get { return s_discoveredPing4UtilityPath; } }

/// <summary>
/// The location of the IPv6 ping utility on the current machine.
/// </summary>
public static string Ping6UtilityPath { get { return s_discoveredPing6UtilityPath; } }
public static string? Ping6UtilityPath { get { return s_discoveredPing6UtilityPath; } }

/// <summary>
/// Constructs command line arguments appropriate for the ping or ping6 utility.
Expand Down
5 changes: 3 additions & 2 deletions src/libraries/Common/src/System/Net/SocketAddress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable
using System.Diagnostics;
using System.Globalization;
using System.Net.Sockets;
Expand Down Expand Up @@ -179,9 +180,9 @@ internal int GetAddressSizeOffset()
return Buffer.Length - IntPtr.Size;
}

public override bool Equals(object comparand)
public override bool Equals(object? comparand)
{
SocketAddress castedComparand = comparand as SocketAddress;
SocketAddress? castedComparand = comparand as SocketAddress;
if (castedComparand == null || this.Size != castedComparand.Size)
{
return false;
Expand Down
32 changes: 16 additions & 16 deletions src/libraries/System.Net.Ping/ref/System.Net.Ping.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,34 @@ public enum IPStatus
public partial class Ping : System.ComponentModel.Component
{
public Ping() { }
public event System.Net.NetworkInformation.PingCompletedEventHandler PingCompleted { add { } remove { } }
public event System.Net.NetworkInformation.PingCompletedEventHandler? PingCompleted { add { } remove { } }
protected override void Dispose(bool disposing) { }
protected void OnPingCompleted(System.Net.NetworkInformation.PingCompletedEventArgs e) { }
public System.Net.NetworkInformation.PingReply Send(System.Net.IPAddress address) { throw null; }
public System.Net.NetworkInformation.PingReply Send(System.Net.IPAddress address, int timeout) { throw null; }
public System.Net.NetworkInformation.PingReply Send(System.Net.IPAddress address, int timeout, byte[] buffer) { throw null; }
public System.Net.NetworkInformation.PingReply Send(System.Net.IPAddress address, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions options) { throw null; }
public System.Net.NetworkInformation.PingReply Send(System.Net.IPAddress address, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions? options) { throw null; }
public System.Net.NetworkInformation.PingReply Send(string hostNameOrAddress) { throw null; }
public System.Net.NetworkInformation.PingReply Send(string hostNameOrAddress, int timeout) { throw null; }
public System.Net.NetworkInformation.PingReply Send(string hostNameOrAddress, int timeout, byte[] buffer) { throw null; }
public System.Net.NetworkInformation.PingReply Send(string hostNameOrAddress, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions options) { throw null; }
public void SendAsync(System.Net.IPAddress address, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions options, object userToken) { }
public void SendAsync(System.Net.IPAddress address, int timeout, byte[] buffer, object userToken) { }
public void SendAsync(System.Net.IPAddress address, int timeout, object userToken) { }
public void SendAsync(System.Net.IPAddress address, object userToken) { }
public void SendAsync(string hostNameOrAddress, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions options, object userToken) { }
public void SendAsync(string hostNameOrAddress, int timeout, byte[] buffer, object userToken) { }
public void SendAsync(string hostNameOrAddress, int timeout, object userToken) { }
public void SendAsync(string hostNameOrAddress, object userToken) { }
public System.Net.NetworkInformation.PingReply Send(string hostNameOrAddress, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions? options) { throw null; }
public void SendAsync(System.Net.IPAddress address, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions? options, object? userToken) { }
public void SendAsync(System.Net.IPAddress address, int timeout, byte[] buffer, object? userToken) { }
public void SendAsync(System.Net.IPAddress address, int timeout, object? userToken) { }
public void SendAsync(System.Net.IPAddress address, object? userToken) { }
public void SendAsync(string hostNameOrAddress, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions? options, object? userToken) { }
public void SendAsync(string hostNameOrAddress, int timeout, byte[] buffer, object? userToken) { }
public void SendAsync(string hostNameOrAddress, int timeout, object? userToken) { }
public void SendAsync(string hostNameOrAddress, object? userToken) { }
public void SendAsyncCancel() { }
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync(System.Net.IPAddress address) { throw null; }
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync(System.Net.IPAddress address, int timeout) { throw null; }
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync(System.Net.IPAddress address, int timeout, byte[] buffer) { throw null; }
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync(System.Net.IPAddress address, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions options) { throw null; }
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync(System.Net.IPAddress address, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions? options) { throw null; }
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync(string hostNameOrAddress) { throw null; }
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync(string hostNameOrAddress, int timeout) { throw null; }
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync(string hostNameOrAddress, int timeout, byte[] buffer) { throw null; }
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync(string hostNameOrAddress, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions options) { throw null; }
public System.Threading.Tasks.Task<System.Net.NetworkInformation.PingReply> SendPingAsync(string hostNameOrAddress, int timeout, byte[] buffer, System.Net.NetworkInformation.PingOptions? options) { throw null; }
}
public partial class PingCompletedEventArgs : System.ComponentModel.AsyncCompletedEventArgs
{
Expand All @@ -75,8 +75,8 @@ public partial class PingCompletedEventArgs : System.ComponentModel.AsyncComplet
public partial class PingException : System.InvalidOperationException
{
protected PingException(System.Runtime.Serialization.SerializationInfo serializationInfo, System.Runtime.Serialization.StreamingContext streamingContext) { }
public PingException(string message) { }
public PingException(string message, System.Exception innerException) { }
public PingException(string? message) { }
public PingException(string? message, System.Exception? innerException) { }
}
public partial class PingOptions
{
Expand All @@ -90,7 +90,7 @@ public partial class PingReply
internal PingReply() { }
public System.Net.IPAddress Address { get { throw null; } }
public byte[] Buffer { get { throw null; } }
public System.Net.NetworkInformation.PingOptions Options { get { throw null; } }
public System.Net.NetworkInformation.PingOptions? Options { get { throw null; } }
public long RoundtripTime { get { throw null; } }
public System.Net.NetworkInformation.IPStatus Status { get { throw null; } }
}
Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Net.Ping/ref/System.Net.Ping.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>$(NetCoreAppCurrent)</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="System.Net.Ping.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/libraries/System.Net.Ping/src/System.Net.Ping.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);CS1573</NoWarn>
<TargetFrameworks>$(NetCoreAppCurrent)-Windows_NT;$(NetCoreAppCurrent)-Unix</TargetFrameworks>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Compile Include="System\Net\NetworkInformation\IPStatus.cs" />
Expand Down
Loading