Skip to content

Commit

Permalink
static link
Browse files Browse the repository at this point in the history
  • Loading branch information
hez2010 committed Mar 18, 2024
1 parent 6774296 commit 182cf43
Show file tree
Hide file tree
Showing 115 changed files with 9,033 additions and 277 deletions.
66 changes: 12 additions & 54 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches: [ master ]

env:
DOTNET_SDK_VERSION: '6.0.x'
DOTNET_SDK_VERSION: '8.0.x'

jobs:
build:
Expand All @@ -18,7 +18,6 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_SDK_VERSION }}
include-prerelease: true
- name: Build
run: dotnet build

Expand All @@ -32,10 +31,9 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_SDK_VERSION }}
include-prerelease: true
- name: Publish Windows x64 Release
run: |
dotnet publish -c Release -r win-x64 -o WindowsBuildx64 /p:NativeBuild=true
dotnet publish SysuSurf/SysuSurf.csproj -c Release -r win-x64 -o WindowsBuildx64 /p:PublishAot=true
del WindowsBuildx64\*.pdb
del WindowsBuildx64\*.json
copy config.json WindowsBuildx64\config.json
Expand All @@ -46,7 +44,7 @@ jobs:
path: WindowsBuildx64
- name: Publish Windows Arm64 Release
run: |
dotnet publish -c Release -r win-arm64 -o WindowsBuildArm64 /p:NativeBuild=true /p:CrossCompileWindowsArm64=true
dotnet publish SysuSurf/SysuSurf.csproj -c Release -r win-arm64 -o WindowsBuildArm64 /p:PublishAot=true /p:CrossCompileWindowsArm64=true
del WindowsBuildArm64\*.pdb
del WindowsBuildArm64\*.json
copy config.json WindowsBuildArm64\config.json
Expand All @@ -56,79 +54,40 @@ jobs:
name: Windows_Arm64
path: WindowsBuildArm64

publish-other-linux:
publish-linux-x64:
runs-on: ubuntu-latest
needs: build
container:
image: mcr.microsoft.com/dotnet/sdk:8.0-alpine

steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_SDK_VERSION }}
include-prerelease: true
- name: Install Kerberos 5 library
run: |
sudo apt update
sudo apt install -y libkrb5-dev
- name: Publish Linux x64 Release
run: |
dotnet publish -c Release -r linux-x64 -o LinuxBuildx64 /p:NativeBuild=true
rm -f LinuxBuildx64/*.pdb LinuxBuildx64/*.json
strip LinuxBuildx64/SysuSurf
apk --no-cache add clang clang-dev musl-dev git gcc krb5-dev zlib-dev libexecinfo lldb binutils build-base zlib-static
dotnet publish SysuSurf/SysuSurf.csproj -c Release -r linux-x64 -o LinuxBuildx64 /p:PublishAot=true
rm LinuxBuildx64/*.pdb LinuxBuildx64/*.json
cp config.json LinuxBuildx64/config.json
- name: Upload Linux x64 artifact
uses: actions/upload-artifact@v1.0.0
with:
name: Linux_x64
path: LinuxBuildx64
- name: Publish Linux musl Arm64 Release
run: |
dotnet publish -c Release -r linux-musl-arm64 -o LinuxBuildMuslArm64 /p:NativeBuild=false /p:PublishSingleFile=true /p:PublishTrimmed=true
rm -f LinuxBuildMuslArm64/*.pdb LinuxBuildMuslArm64/*.json
cp config.json LinuxBuildMuslArm64/config.json
- name: Upload Linux musl Arm64 artifact
uses: actions/upload-artifact@v1.0.0
with:
name: Linux_Musl_Arm64
path: LinuxBuildMuslArm64

publish-linux-musl-x64:
runs-on: ubuntu-latest
needs: build
container:
image: mcr.microsoft.com/dotnet/sdk:6.0-alpine

steps:
- uses: actions/checkout@v2
- name: Publish Linux Musl x64 Release
run: |
apk --no-cache add clang clang-dev musl-dev git gcc krb5-dev zlib-dev libexecinfo lldb binutils build-base zlib-static
dotnet publish -c Release -r linux-musl-x64 -o LinuxBuildMuslx64 /p:NativeBuild=true
rm LinuxBuildMuslx64/*.pdb LinuxBuildMuslx64/*.json
strip LinuxBuildMuslx64/SysuSurf
cp config.json LinuxBuildMuslx64/config.json
- name: Upload Linux Musl x64 artifact
uses: actions/upload-artifact@v1.0.0
with:
name: Linux_Musl_x64
path: LinuxBuildMuslx64

publish-linux-arm64:
runs-on: ubuntu-latest
needs: build
container: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-16.04-cross-arm64-20201022204150-b2c2436
container: mcr.microsoft.com/dotnet-buildtools/prereqs:ubuntu-22.04-cross-arm64-alpine

steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_SDK_VERSION }}
include-prerelease: true
- name: Publish Native Linux ARM64 Release
run: |
dotnet publish -c Release -r linux-arm64 -o LinuxBuildArm64 /p:NativeBuild=true /p:CrossCompileLinuxArm64=true /p:CppCompilerAndLinker=clang-9 /p:SysRoot=/crossrootfs/arm64
dotnet publish SysuSurf/SysuSurf.csproj -c Release -r linux-arm64 -o LinuxBuildArm64 /p:PublishAot=true /p:CrossCompileLinuxArm64=true /p:CppCompilerAndLinker=clang-14 /p:SysRoot=/crossrootfs/arm64
rm LinuxBuildArm64/*.pdb LinuxBuildArm64/*.json
aarch64-linux-gnu-strip LinuxBuildArm64/SysuSurf
cp config.json LinuxBuildArm64/config.json
Expand All @@ -148,10 +107,9 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_SDK_VERSION }}
include-prerelease: true
- name: Publish macOS x64 Release
run: |
dotnet publish -c Release -r osx-x64 -o macOSBuildx64
dotnet publish SysuSurf/SysuSurf.csproj -c Release -r osx-x64 -o macOSBuildx64
rm -f macOSBuildx64/*.pdb macOSBuildx64/*.json
strip macOSBuildx64/SysuSurf
cp config.json macOSBuildx64/config.json
Expand Down
199 changes: 199 additions & 0 deletions SharpPcap/ARP.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
// Copyright 2005 Tamir Gal <tamir@tamirgal.com>
// Copyright 2008-2009 Chris Morgan <chmorgan@gmail.com>
//
// SPDX-License-Identifier: MIT

using SharpPcap.LibPcap;
using System;
using System.Net.NetworkInformation;

namespace SharpPcap
{
/// <summary>
/// Resolves MAC addresses from IP addresses using the Address Resolution Protocol (ARP)
/// </summary>
public class ARP
{
private readonly PcapInterface pcapInterface;

/// <summary>
/// Constructs a new ARP Resolver
/// </summary>
/// <param name="device">The network device on which this resolver sends its ARP packets</param>
public ARP(LibPcapLiveDevice device)
{
pcapInterface = device.Interface;
}

/// <summary>
/// Timeout for a given call to Resolve()
/// </summary>
public TimeSpan Timeout { get; set; } = new TimeSpan(0, 0, 1);

/// <summary>
/// Resolves the MAC address of the specified IP address. The 'DeviceName' propery must be set
/// prior to using this method.
/// </summary>
/// <param name="destIP">The IP address to resolve</param>
/// <returns>The MAC address that matches to the given IP address or
/// null if there was a timeout</returns>
public PhysicalAddress Resolve(System.Net.IPAddress destIP)
{
return Resolve(destIP, null, null);
}

/// <summary>
/// Resolves the MAC address of the specified IP address
/// </summary>
/// <param name="destIP">The IP address to resolve</param>
/// <param name="localIP">The local IP address from which to send the ARP request, if null the local address will be discovered</param>
/// <param name="localMAC">The localMAC address to use, if null the local mac will be discovered</param>
/// <returns>The MAC address that matches to the given IP address or
/// null if there was a timeout</returns>
public PhysicalAddress Resolve(System.Net.IPAddress destIP,
System.Net.IPAddress localIP,
PhysicalAddress localMAC)
{
// if no local ip address is specified attempt to find one from the adapter
if (localIP == null)
{
// attempt to find an ipv4 address.
// ARP is ipv4, NDP is used for ipv6
foreach (var address in pcapInterface.Addresses)
{
if (address.Addr.type == Sockaddr.AddressTypes.AF_INET_AF_INET6)
{
// make sure the address is ipv4
if (address.Addr.ipAddress.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
{
localIP = address.Addr.ipAddress;
break; // break out of the foreach
}
}
}

// if we can't find either an ipv6 or an ipv4 address use the localhost address
if (localIP == null)
{
localIP = System.Net.IPAddress.Parse("127.0.0.1");
}
}

// if no local mac address is specified attempt to find one from the device
if (localMAC == null)
{
foreach (var address in pcapInterface.Addresses)
{
if (address.Addr.type == Sockaddr.AddressTypes.HARDWARE)
{
localMAC = address.Addr.hardwareAddress;
}
}
}

if (localMAC == null)
{
throw new InvalidOperationException("Unable to find local mac address");
}
using (var device = new LibPcapLiveDevice(pcapInterface))
{
//open the device with 20ms timeout
device.Open(mode: DeviceModes.Promiscuous, read_timeout: 20);
return Resolve(device, destIP, localIP, localMAC, Timeout);
}
}

internal static PhysicalAddress Resolve(
ILiveDevice device,
System.Net.IPAddress destIP,
System.Net.IPAddress localIP,
PhysicalAddress localMAC,
TimeSpan timeout)
{
//Build a new ARP request packet
var request = BuildRequest(destIP, localMAC, localIP);

//create a "tcpdump" filter for allowing only arp replies to be read
String arpFilter = "arp and ether dst " + localMAC.ToString();

//set the filter
device.Filter = arpFilter;

// set a last request time that will trigger sending the
// arp request immediately
var lastRequestTime = DateTime.FromBinary(0);

var requestInterval = new TimeSpan(0, 0, 1);

PacketDotNet.ArpPacket arpPacket = null;

// attempt to resolve the address with the current timeout
var timeoutDateTime = DateTime.Now + timeout;
while (DateTime.Now < timeoutDateTime)
{
if (requestInterval < (DateTime.Now - lastRequestTime))
{
// inject the packet to the wire
device.SendPacket(request);
lastRequestTime = DateTime.Now;
}

//read the next packet from the network
var retval = device.GetNextPacket(out PacketCapture e);
if (retval != GetPacketStatus.PacketRead)
{
continue;
}
var reply = e.GetPacket();

// parse the packet
var packet = PacketDotNet.Packet.ParsePacket(reply.LinkLayerType, reply.Data);

// is this an arp packet?
arpPacket = packet.Extract<PacketDotNet.ArpPacket>();
if (arpPacket == null)
{
continue;
}

//if this is the reply we're looking for, stop
if (arpPacket.SenderProtocolAddress.Equals(destIP))
{
break;
}
}

// the timeout happened
if (DateTime.Now >= timeoutDateTime)
{
return null;
}
else
{
//return the resolved MAC address
return arpPacket.SenderHardwareAddress;
}
}


private static PacketDotNet.Packet BuildRequest(System.Net.IPAddress destinationIP,
PhysicalAddress localMac,
System.Net.IPAddress localIP)
{
// an arp packet is inside of an ethernet packet
var ethernetPacket = new PacketDotNet.EthernetPacket(localMac,
PhysicalAddress.Parse("FF-FF-FF-FF-FF-FF"),
PacketDotNet.EthernetType.Arp);
var arpPacket = new PacketDotNet.ArpPacket(PacketDotNet.ArpOperation.Request,
PhysicalAddress.Parse("00-00-00-00-00-00"),
destinationIP,
localMac,
localIP);

// the arp packet is the payload of the ethernet packet
ethernetPacket.PayloadPacket = arpPacket;

return ethernetPacket;
}
}
}
23 changes: 23 additions & 0 deletions SharpPcap/AuthenticationTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright 2010-2011 Chris Morgan <chmorgan@gmail.com>
//
// SPDX-License-Identifier: MIT

namespace SharpPcap
{
/// <summary>
/// Types of authentication
/// </summary>
public enum AuthenticationTypes
{
/// <summary>
/// Null authentication
/// </summary>
Null = 0,

/// <summary>
/// Username/password authentication
/// </summary>
Password = 1
}
}

Loading

0 comments on commit 182cf43

Please sign in to comment.