-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add better logging of network devices when sending WOL
- Loading branch information
Showing
25 changed files
with
1,915 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.ComponentModel; | ||
using System.Net.NetworkInformation; | ||
using System.Threading.Tasks; | ||
|
||
namespace System.Net | ||
{ | ||
/// <summary>Stellt Methoden für das Senden von Anfragen über das ARP-Protokoll bereit.</summary> | ||
public static class ArpRequest | ||
{ | ||
/// <summary> | ||
/// Sendet eine Anfrage über das ARP-Protokoll, um eine IP-Adresse in die Physikalische Adresse aufzulösen. Falls sich die physikalische Adresse bereits im Cache des Hosts befindet, wird diese zurückgegeben. | ||
/// </summary> | ||
/// <param name="destination">Destination <see cref="IPAddress"/>.</param> | ||
/// <returns>Eine <see cref="T:System.Net.ArpRequestResult">ArpRequestResult</see>-Instanz, welche die Ergebnisse der Anfrage enthält.</returns> | ||
public static ArpRequestResult Send(IPAddress destination) | ||
{ | ||
if (destination == null) | ||
throw new ArgumentNullException(nameof(destination)); | ||
|
||
int destIp = BitConverter.ToInt32(destination.GetAddressBytes(), 0); | ||
|
||
var addr = new byte[6]; | ||
var len = addr.Length; | ||
|
||
var res = NativeMethods.SendARP(destIp, 0, addr, ref len); | ||
|
||
if (res == 0) | ||
return new ArpRequestResult(new PhysicalAddress(addr)); | ||
return new ArpRequestResult(new Win32Exception(res)); | ||
} | ||
|
||
/// <summary> | ||
/// Sendet eine Anfrage über das ARP-Protokoll, um eine IP-Adresse in die Physikalische Adresse aufzulösen. Falls sich die physikalische Adresse bereits im Cache des Hosts befindet, wird diese zurückgegeben. | ||
/// </summary> | ||
/// <param name="destination">Destination <see cref="IPAddress"/>.</param> | ||
/// <returns>Ein asynchroner Task, welcher einen ARP-Request sendet.</returns> | ||
public static Task<ArpRequestResult> SendAsync(IPAddress destination) => Task.Run(() => Send(destination)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System.Net.NetworkInformation; | ||
using System.Text; | ||
|
||
namespace System.Net | ||
{ | ||
// TODO: rethink the whole exception thing | ||
|
||
/// <summary> | ||
/// Enthält die Rückgabewerte der ArpRequest.Send-Funktion. | ||
/// </summary> | ||
public class ArpRequestResult | ||
{ | ||
/// <summary>Falls Fehler bei der Protokollanfrage auftreten, werden diese in dieser Eigenschaft abgelegt. Andernfalls null.</summary> | ||
public Exception Exception { get; } | ||
|
||
/// <summary>Die aufgelöste physikalische Adresse.</summary> | ||
public PhysicalAddress Address { get; } | ||
|
||
/// <summary>Erstellt eine neue ArpRequestResult-Instanz</summary> | ||
/// <param name="address">Die physikalische Adresse</param> | ||
public ArpRequestResult(PhysicalAddress address) | ||
{ | ||
this.Exception = null; | ||
Address = address; | ||
} | ||
|
||
/// <summary>Erstellt eine neue ArpRequestResult-Instanz</summary> | ||
/// <param name="exception">Der aufgetretene Fehler</param> | ||
public ArpRequestResult(Exception exception) | ||
{ | ||
this.Exception = exception; | ||
Address = null; | ||
} | ||
|
||
/// <summary>Konvertiert ARP-Rückgabewerte in eine Zeichenfolge.</summary> | ||
public override string ToString() | ||
{ | ||
var sb = new StringBuilder(); | ||
if (Address == null) | ||
sb.Append("no address"); | ||
else | ||
{ | ||
sb.Append("address: "); | ||
sb.Append(Address); | ||
} | ||
sb.Append(", "); | ||
if (Exception == null) | ||
sb.Append("no exception"); | ||
else | ||
{ | ||
sb.Append("exception: "); | ||
sb.Append(Exception.Message); | ||
} | ||
return sb.ToString(); | ||
} | ||
} | ||
} |
Oops, something went wrong.