mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-13 10:59:18 +02:00
Add unsigned versions of ntohl and htonl
All systems i know of define ntohl and htonl to use unsigned 32bit types. To keep backward compatibility for now I've added overloaded versions so the impact on existing code is a small as possible. But I've marked the signed versions as deprecated. The code will now also use SwapEndian which is available as optimized versions on some platforms. git-svn-id: trunk@22994 -
This commit is contained in:
parent
02bccda89e
commit
e370303fda
@ -235,29 +235,39 @@ end;
|
|||||||
|
|
||||||
type thostaddr= packed array[1..4] of byte;
|
type thostaddr= packed array[1..4] of byte;
|
||||||
|
|
||||||
function htonl( host : longint):longint; inline;
|
function htonl( host : longint):longint; inline;overload;deprecated;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
{$ifdef FPC_BIG_ENDIAN}
|
{$ifdef FPC_BIG_ENDIAN}
|
||||||
htonl:=host;
|
htonl:=host;
|
||||||
{$else}
|
{$else}
|
||||||
htonl:=THostAddr(host)[4];
|
htonl:=SwapEndian(host);
|
||||||
htonl:=htonl or longint( (THostAddr(host)[3]) shl 8);
|
|
||||||
htonl:=htonl or longint( (THostAddr(host)[2]) shl 16);
|
|
||||||
htonl:=htonl or longint( (THostAddr(host)[1]) shl 24);
|
|
||||||
{$endif}
|
{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function NToHl (Net : Longint) : Longint; inline;
|
function htonl( host : cardinal):cardinal; inline;overload;
|
||||||
|
begin
|
||||||
|
{$ifdef FPC_BIG_ENDIAN}
|
||||||
|
htonl:=host;
|
||||||
|
{$else}
|
||||||
|
htonl:=SwapEndian(host);
|
||||||
|
{$endif}
|
||||||
|
end;
|
||||||
|
|
||||||
|
Function NToHl (Net : longint) : longint; inline;overload;deprecated;
|
||||||
begin
|
begin
|
||||||
{$ifdef FPC_BIG_ENDIAN}
|
{$ifdef FPC_BIG_ENDIAN}
|
||||||
ntohl:=net;
|
ntohl:=net;
|
||||||
{$else}
|
{$else}
|
||||||
ntohl:=THostAddr(Net)[4];
|
ntohl:=SwapEndian(net);
|
||||||
ntohl:=ntohl or longint( (THostAddr(Net)[3]) shl 8);
|
{$endif}
|
||||||
ntohl:=ntohl or longint( (THostAddr(Net)[2]) shl 16);
|
end;
|
||||||
ntohl:=ntohl or longint( (THostAddr(Net)[1]) shl 24);
|
|
||||||
|
Function NToHl (Net : cardinal) : cardinal; inline;overload;
|
||||||
|
begin
|
||||||
|
{$ifdef FPC_BIG_ENDIAN}
|
||||||
|
ntohl:=net;
|
||||||
|
{$else}
|
||||||
|
ntohl:=SwapEndian(net);
|
||||||
{$endif}
|
{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -267,7 +277,7 @@ begin
|
|||||||
{$ifdef FPC_BIG_ENDIAN}
|
{$ifdef FPC_BIG_ENDIAN}
|
||||||
htons:=host;
|
htons:=host;
|
||||||
{$else}
|
{$else}
|
||||||
htons:=swap(host);
|
htons:=SwapEndian(host);
|
||||||
{$endif}
|
{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -277,7 +287,7 @@ begin
|
|||||||
{$ifdef FPC_BIG_ENDIAN}
|
{$ifdef FPC_BIG_ENDIAN}
|
||||||
ntohs:=net;
|
ntohs:=net;
|
||||||
{$else}
|
{$else}
|
||||||
ntohs:=swap(net);
|
ntohs:=SwapEndian(net);
|
||||||
{$endif}
|
{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -205,8 +205,10 @@ Function Connect(Sock:longint;const addr:TInetSockAddr;var SockIn,SockOut:file):
|
|||||||
Procedure Sock2File(Sock:Longint;Var SockIn,SockOut:File);deprecated;
|
Procedure Sock2File(Sock:Longint;Var SockIn,SockOut:File);deprecated;
|
||||||
|
|
||||||
{ Utility routines}
|
{ Utility routines}
|
||||||
function htonl( host : longint):longint; inline;
|
function htonl( host : longint):longint; inline; overload;deprecated;
|
||||||
Function NToHl( Net : Longint) : Longint; inline;
|
Function NToHl( Net : longint):longint; inline; overload;deprecated;
|
||||||
|
function htonl( host : cardinal):cardinal; inline; overload;
|
||||||
|
Function NToHl( Net : cardinal):cardinal; inline; overload;
|
||||||
function htons( host : word):word; inline;
|
function htons( host : word):word; inline;
|
||||||
Function NToHs( Net : word):word; inline;
|
Function NToHs( Net : word):word; inline;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user