Restructure.
git-svn-id: https://spexeah.com:8443/svn/Asuro@471 6dbc8c32-bb84-406f-8558-d1cf31a0ab0c
This commit is contained in:
65
src/driver/net/include/nettypes.pas
Normal file
65
src/driver/net/include/nettypes.pas
Normal file
@ -0,0 +1,65 @@
|
||||
unit nettypes;
|
||||
|
||||
interface
|
||||
|
||||
type
|
||||
TNetSendCallback = function(p_data : void; p_len : uint16) : sint32;
|
||||
TRecvCallback = procedure(p_data : void; p_len : uint16);
|
||||
|
||||
PEthernetHeader = ^TEthernetHeader;
|
||||
TEthernetHeader = bitpacked record
|
||||
dst : array[0..5] of uint8;
|
||||
src : array[0..5] of uint8;
|
||||
EthTypeHi : uint8;
|
||||
EthTypeLo : uint8;
|
||||
end;
|
||||
|
||||
PIPV4Header = ^TIPV4Header;
|
||||
TIPV4Header = bitpacked record
|
||||
version : ubit4;
|
||||
header_len : ubit4;
|
||||
ToS : uint8;
|
||||
total_len_Hi : uint8;
|
||||
total_len_Lo : uint8;
|
||||
identifier_Hi : uint8;
|
||||
identifier_Lo : uint8;
|
||||
Flags : ubit3;
|
||||
Fragment_Off : ubit13;
|
||||
TTL : uint8;
|
||||
Protocol : uint8;
|
||||
HDR_CHK_Hi : uint8;
|
||||
HDR_CHK_Lo : uint8;
|
||||
Src : Array[0..3] of uint8;
|
||||
Dst : Array[0..3] of uint8;
|
||||
Options : ubit24;
|
||||
Padding : uint8;
|
||||
end;
|
||||
|
||||
TTCPFlags = record
|
||||
RS : Boolean;
|
||||
DF : Boolean;
|
||||
MF : Boolean;
|
||||
end;
|
||||
|
||||
TIPV4AbstractHeader = record
|
||||
version : uint8;
|
||||
header_len : uint8;
|
||||
ToS : uint8;
|
||||
total_len : uint16;
|
||||
identifier : uint16;
|
||||
Flags : TTCPFlags;
|
||||
Fragment_Off : uint16;
|
||||
TTL : uint8;
|
||||
Protocol : uint8;
|
||||
HDR_CHK : uint16;
|
||||
Src : Array[0..3] of uint8;
|
||||
Dst : Array[0..3] of uint8;
|
||||
Options : uint32;
|
||||
end;
|
||||
|
||||
const
|
||||
BROADCAST_MAC : Array[0..5] of uint8 = ($FF, $FF, $FF, $FF, $FF, $FF);
|
||||
|
||||
implementation
|
||||
|
||||
end.
|
54
src/driver/net/include/netutils.pas
Normal file
54
src/driver/net/include/netutils.pas
Normal file
@ -0,0 +1,54 @@
|
||||
unit netutils;
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
nettypes, console;
|
||||
|
||||
procedure writeMACAddress(mac : puint8);
|
||||
procedure writeIPv4Address(ip : puint8);
|
||||
function MACEqual(mac1 : puint8; mac2 : puint8) : boolean;
|
||||
|
||||
implementation
|
||||
|
||||
function MACEqual(mac1 : puint8; mac2 : puint8) : boolean;
|
||||
var
|
||||
i : uint8;
|
||||
|
||||
begin
|
||||
MACEqual:= true;
|
||||
for i:=0 to 5 do begin
|
||||
if mac1[i] <> mac2[i] then begin
|
||||
MACEqual:= false;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure writeIPv4Address(ip : puint8);
|
||||
var
|
||||
i : integer;
|
||||
|
||||
begin
|
||||
console.writeint(ip[0]);
|
||||
for i:=1 to 3 do begin
|
||||
console.writestring('.');
|
||||
console.writeint(ip[i]);
|
||||
end;
|
||||
console.writestringln(' ');
|
||||
end;
|
||||
|
||||
procedure writeMACAddress(mac : puint8);
|
||||
var
|
||||
i : integer;
|
||||
|
||||
begin
|
||||
console.writehexpair(mac[0]);
|
||||
for i:=1 to 5 do begin
|
||||
console.writestring(':');
|
||||
console.writehexpair(mac[i]);
|
||||
end;
|
||||
console.writestringln(' ');
|
||||
end;
|
||||
|
||||
end.
|
Reference in New Issue
Block a user