git-svn-id: https://spexeah.com:8443/svn/Asuro@481 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
@ -3,8 +3,62 @@ unit nettypes;
|
||||
interface
|
||||
|
||||
type
|
||||
TNetSendCallback = function(p_data : void; p_len : uint16) : sint32;
|
||||
TRecvCallback = procedure(p_data : void; p_len : uint16);
|
||||
|
||||
|
||||
TMACAddress = Array[0..5] of uint8;
|
||||
TIPv4Address = Array[0..3] of uint8;
|
||||
|
||||
TMACPair = record
|
||||
Source : TMACAddress;
|
||||
Destination : TMACAddress;
|
||||
end;
|
||||
|
||||
TIPv4Pair = record
|
||||
Source : TIPv4Address;
|
||||
Destination : TIPv4Address;
|
||||
end;
|
||||
|
||||
PPacketContext = ^TPacketContext;
|
||||
TPacketContext = record
|
||||
MAC : TMACPair;
|
||||
IP : TIPv4Pair;
|
||||
end;
|
||||
|
||||
PIPv4Configuration = ^TIPv4Configuration;
|
||||
TIPv4Configuration = record
|
||||
Address : array[0..3] of uint8;
|
||||
Gateway : array[0..3] of uint8;
|
||||
Netmask : array[0..3] of uint8;
|
||||
UP : Boolean;
|
||||
end;
|
||||
|
||||
TARPAbstractHeader = record
|
||||
Hardware_Type : uint16;
|
||||
Protocol_Type : uint16;
|
||||
Hardware_Address_Length : uint8;
|
||||
Protocol_Address_Length : uint8;
|
||||
Operation : uint16;
|
||||
Source_Hardware : TMACAddress;
|
||||
Source_Protocol : TIPv4Address;
|
||||
Destination_Hardware : TMACAddress;
|
||||
Destination_Protocol : TIPv4Address;
|
||||
end;
|
||||
|
||||
PARPHeader = ^TARPHeader;
|
||||
TARPHeader = bitpacked record
|
||||
Hardware_Type_Hi : uint8;
|
||||
Hardware_Type_Lo : uint8;
|
||||
Protocol_Type_Hi : uint8;
|
||||
Protocol_Type_Lo : uint8;
|
||||
Hardware_Address_Length : uint8;
|
||||
Protocol_Address_Length : uint8;
|
||||
Operation_Hi : uint8;
|
||||
Operation_Lo : uint8;
|
||||
Source_Hardware : TMACAddress;
|
||||
Source_Protocol : TIPv4Address;
|
||||
Destination_Hardware : TMACAddress;
|
||||
Destination_Protocol : TIPv4Address;
|
||||
end;
|
||||
|
||||
PEthernetHeader = ^TEthernetHeader;
|
||||
TEthernetHeader = bitpacked record
|
||||
@ -57,6 +111,9 @@ type
|
||||
Options : uint32;
|
||||
end;
|
||||
|
||||
TNetSendCallback = function(p_data : void; p_len : uint16) : sint32;
|
||||
TRecvCallback = procedure(p_data : void; p_len : uint16; p_context : PPacketContext);
|
||||
|
||||
const
|
||||
BROADCAST_MAC : Array[0..5] of uint8 = ($FF, $FF, $FF, $FF, $FF, $FF);
|
||||
|
||||
|
@ -3,14 +3,33 @@ unit netutils;
|
||||
interface
|
||||
|
||||
uses
|
||||
nettypes, console;
|
||||
util, nettypes, console, lmemorymanager;
|
||||
|
||||
procedure copyMAC(src : puint8; dst : puint8);
|
||||
procedure copyIPv4(src : puint8; dst : puint8);
|
||||
procedure writeMACAddress(mac : puint8);
|
||||
procedure writeIPv4Address(ip : puint8);
|
||||
function MACEqual(mac1 : puint8; mac2 : puint8) : boolean;
|
||||
function IPEqual(ip1 : puint8; ip2 : puint8) : boolean;
|
||||
function newPacketContext : PPacketContext;
|
||||
procedure freePacketContext(p_context : PPacketContext);
|
||||
|
||||
implementation
|
||||
|
||||
function IPEqual(ip1 : puint8; ip2 : puint8) : boolean;
|
||||
var
|
||||
i : uint8;
|
||||
|
||||
begin
|
||||
IPEqual:= true;
|
||||
for i:=0 to 3 do begin
|
||||
if ip1[i] <> ip2[i] then begin
|
||||
IPEqual:= false;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
function MACEqual(mac1 : puint8; mac2 : puint8) : boolean;
|
||||
var
|
||||
i : uint8;
|
||||
@ -51,4 +70,35 @@ begin
|
||||
console.writestringln(' ');
|
||||
end;
|
||||
|
||||
function newPacketContext : PPacketContext;
|
||||
begin
|
||||
newPacketContext:= PPacketContext(kalloc(sizeof(TPacketContext)));
|
||||
memset(uint32(newPacketContext), 0, sizeof(TPacketContext));
|
||||
end;
|
||||
|
||||
procedure freePacketContext(p_context : PPacketContext);
|
||||
begin
|
||||
kfree(void(p_context));
|
||||
end;
|
||||
|
||||
procedure copyMAC(src : puint8; dst : puint8);
|
||||
var
|
||||
i : uint8;
|
||||
|
||||
begin
|
||||
for i:=0 to 5 do begin
|
||||
dst[i]:= src[i];
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure copyIPv4(src : puint8; dst : puint8);
|
||||
var
|
||||
i : uint8;
|
||||
|
||||
begin
|
||||
for i:=0 to 3 do begin
|
||||
dst[i]:= src[i];
|
||||
end;
|
||||
end;
|
||||
|
||||
end.
|
Reference in New Issue
Block a user