|
@@ -4,7 +4,6 @@ using SharpPcap;
|
|
|
using SharpPcap.LibPcap;
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
-using System.Configuration;
|
|
|
using System.Linq;
|
|
|
using System.Net;
|
|
|
using System.Net.Sockets;
|
|
@@ -75,11 +74,11 @@ namespace DhcpServer
|
|
|
var socket = new Socket(_listenOn.AddressFamily, SocketType.Dgram, ProtocolType.Udp)
|
|
|
{
|
|
|
EnableBroadcast = true,
|
|
|
- SendBufferSize = 65536,
|
|
|
- ReceiveBufferSize = 65536
|
|
|
+ SendBufferSize = 1500,
|
|
|
+ ReceiveBufferSize = 1500
|
|
|
};
|
|
|
socket.Bind(_listenOn);
|
|
|
- var buffer = new byte[65536];
|
|
|
+ var buffer = new byte[1500];
|
|
|
EndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 68);
|
|
|
var polling = DateTime.Now;
|
|
|
|
|
@@ -115,7 +114,7 @@ namespace DhcpServer
|
|
|
bytes = reply.WriteToBuffer(buffer);
|
|
|
var to = new IPEndPoint(IPAddress.Broadcast, 68);
|
|
|
Console.WriteLine($"Send {bytes} bytes to {to} {reply.MessageType} by {reply.ClientMacAddressHex}");
|
|
|
- socket.SendTo(buffer, 0, bytes, SocketFlags.None, to);
|
|
|
+ var sent = socket.SendTo(buffer, 0, bytes, SocketFlags.None, to);
|
|
|
}
|
|
|
}
|
|
|
catch (Exception e)
|
|
@@ -135,7 +134,7 @@ namespace DhcpServer
|
|
|
|
|
|
var clientMac = packet.ClientMacAddressHex;
|
|
|
Console.WriteLine($" {packet.MessageType} by {clientMac}");
|
|
|
- Console.WriteLine($" {packet.Vendor ?? "Unknown Vendor"} / {packet.UserClass ?? "Unknown Class"}");
|
|
|
+ Console.WriteLine($" {packet.Vendor ?? "Unknown Vendor"} / {packet.UserClass ?? "Unknown Class"} / {packet.HostName ?? "Unknown HostName"}");
|
|
|
|
|
|
DhcpMessageType reply;
|
|
|
switch (packet.MessageType)
|
|
@@ -160,17 +159,10 @@ namespace DhcpServer
|
|
|
else
|
|
|
{
|
|
|
// extract params
|
|
|
- var requestParameters = packet.Options[DhcpOption.ParameterRequestList];
|
|
|
var hostName = packet.HostName;
|
|
|
var userClass = packet.UserClass;
|
|
|
var vendor = packet.Vendor;
|
|
|
|
|
|
- //byte arch = 0;
|
|
|
- //if (packet.Options.TryGetValue(DhcpOption.ClientIdentifier, out var bufArch))
|
|
|
- //{
|
|
|
- // arch = bufArch?.FirstOrDefault() ?? 0;
|
|
|
- //}
|
|
|
-
|
|
|
// Allocate ip address
|
|
|
|
|
|
PoolSlot allocateSlot = null;
|
|
@@ -304,7 +296,7 @@ namespace DhcpServer
|
|
|
private static void InitConfig()
|
|
|
{
|
|
|
_nic = LibPcapLiveDeviceList.Instance.FirstOrDefault(p => p.Addresses.Any(q => Equals(q.Addr.ipAddress, _listenOn.Address)));
|
|
|
- if (null == _nic) throw new ConfigurationErrorsException("Device not found");
|
|
|
+ //if (null == _nic) throw new ConfigurationErrorsException("Device not found");
|
|
|
|
|
|
var slots = new PoolSlot[_poolSize];
|
|
|
slots[0] = new PoolSlot(_poolStart);
|