Skip to content

Commit

Permalink
Add unicast discovery
Browse files Browse the repository at this point in the history
  • Loading branch information
Rans4ckeR committed Jan 4, 2025
1 parent f8d3661 commit 2a4d752
Show file tree
Hide file tree
Showing 21 changed files with 114 additions and 103 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Console.WriteLine($"Session: {webUiSessionInfo.Sid}");

// Capture live network traffic from router to file
ICaptureControlService captureControlService = serviceScope.ServiceProvider.GetRequiredService<ICaptureControlService>();
IEnumerable<CaptureInterfaceGroup>? interfaceGroups = await captureControlService.GetInterfacesAsync(device);
IEnumerable<CaptureInterfaceGroup> interfaceGroups = await captureControlService.GetInterfacesAsync(device);
CaptureInterface captureInterface = interfaceGroups.First().CaptureInterfaces.First();
var fileInfo = new FileInfo(FormattableString.Invariant($@"c:\temp\{captureInterface.Name}_{DateTime.Now.ToString("s").Replace(":", string.Empty)}.eth"));

Expand Down
2 changes: 1 addition & 1 deletion RS.Fritz.Manager.API.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

// Capture live network traffic from router to file
ICaptureControlService captureControlService = serviceScope.ServiceProvider.GetRequiredService<ICaptureControlService>();
IEnumerable<CaptureInterfaceGroup>? interfaceGroups = await captureControlService.GetInterfacesAsync(device);
IEnumerable<CaptureInterfaceGroup> interfaceGroups = await captureControlService.GetInterfacesAsync(device);
CaptureInterface captureInterface = interfaceGroups.First().CaptureInterfaces.First();
var fileInfo = new FileInfo(FormattableString.Invariant($@"c:\temp\{captureInterface.Name}_{DateTime.Now.ToString("s").Replace(":", string.Empty)}.eth"));

Expand Down
4 changes: 2 additions & 2 deletions RS.Fritz.Manager.API/Entities/InternetGatewayDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed record InternetGatewayDevice(
string? Nls,
int? BootId,
int? ConfigId,
ushort? SearchPort,
ushort? UnicastSearchPort,
IEnumerable<Uri?>? SecureLocations,
UPnPDescription? UPnPDescription,
Uri? PreferredLocation,
Expand All @@ -35,7 +35,7 @@ public sealed record InternetGatewayDevice(
public bool IsAvm => SearchTarget?.StartsWith(UPnPConstants.InternetGatewayDeviceAvmNamespace, StringComparison.OrdinalIgnoreCase) ?? false;

public IEnumerable<ServiceListItem> Services
=> services ??= UPnPDescription?.Device?.GetServices().ToArray() ?? [];
=> services ??= [.. UPnPDescription?.Device?.GetServices() ?? []];

public async ValueTask InitializeAsync()
{
Expand Down
2 changes: 1 addition & 1 deletion RS.Fritz.Manager.API/Extensions/DeviceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public static IEnumerable<ServiceListItem> GetServices(this Device device)

foreach (Device deviceListItem in device.DeviceList ?? [])
{
serviceListItems = serviceListItems.Concat(GetServices(deviceListItem));
serviceListItems = [.. serviceListItems, .. GetServices(deviceListItem)];
}

return serviceListItems;
Expand Down
8 changes: 4 additions & 4 deletions RS.Fritz.Manager.API/Extensions/LoggerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public static void ExceptionThrown(this ILogger logger, Exception exception)
}
}

[LoggerMessage(Level = LogLevel.Trace, EventId = (int)LoggingEvents.SoapRequest, Message = "{Request}")]
internal static partial void SoapRequest(this ILogger logger, string request);
[LoggerMessage(Level = LogLevel.Trace, EventId = (int)LoggingEvents.SoapRequest, Message = "Version: {Version}, IsFault: {IsFault}, IsEmpty: {IsEmpty}, Body:\r\n{Body}")]
internal static partial void SoapRequest(this ILogger logger, string version, bool isFault, bool isEmpty, string body);

[LoggerMessage(Level = LogLevel.Trace, EventId = (int)LoggingEvents.SoapReply, Message = "{Reply}")]
internal static partial void SoapReply(this ILogger logger, string reply);
[LoggerMessage(Level = LogLevel.Trace, EventId = (int)LoggingEvents.SoapReply, Message = "Version: {Version}, IsFault: {IsFault}, IsEmpty: {IsEmpty}, Body:\r\n{Body}")]
internal static partial void SoapReply(this ILogger logger, string version, bool isFault, bool isEmpty, string body);

[LoggerMessage(Level = LogLevel.Trace, EventId = (int)LoggingEvents.DiscoverRequest, Message = "{LocalIpEndPoint} -> {RemoteIpEndPoint}\r\n{Request}")]
internal static partial void DiscoverRequest(this ILogger logger, IPEndPoint localIpEndPoint, IPEndPoint remoteIpEndPoint, string request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async ValueTask<IEnumerable<CaptureInterfaceGroup>> GetInterfacesAsync(In
});
using HttpResponseMessage httpResponseMessage = await httpClient.PostAsync(captureUri, content, cancellationToken).ConfigureAwait(false);
string responseContent = await httpResponseMessage.EnsureSuccessStatusCode().Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
var captureInterfaceGroups = new List<CaptureInterfaceGroup>();
List<CaptureInterfaceGroup> captureInterfaceGroups = [];
int groupNameBeginPosition = -1;

while ((groupNameBeginPosition = responseContent.IndexOf("<h3>", groupNameBeginPosition + 1, StringComparison.OrdinalIgnoreCase)) is not -1)
Expand All @@ -30,7 +30,7 @@ public async ValueTask<IEnumerable<CaptureInterfaceGroup>> GetInterfacesAsync(In
string groupName = responseContent[(groupNameBeginPosition + "<h3>".Length)..groupNameEndPosition];
int interfaceNameBeginPosition = groupNameEndPosition;
int nextGroupNameBeginPosition = responseContent.IndexOf("<h3>", groupNameBeginPosition + 1, StringComparison.OrdinalIgnoreCase);
var captureInterfaces = new List<CaptureInterface>();
List<CaptureInterface> captureInterfaces = [];

while ((interfaceNameBeginPosition = responseContent.IndexOf("<th>", interfaceNameBeginPosition + 1, StringComparison.OrdinalIgnoreCase)) is not -1 && interfaceNameBeginPosition < nextGroupNameBeginPosition)
{
Expand Down
Loading

0 comments on commit 2a4d752

Please sign in to comment.