From 34282c6cf9d02e5c676cfedbe0ba05c2c5345664 Mon Sep 17 00:00:00 2001 From: marco Date: Mon, 1 Nov 2004 16:23:15 +0000 Subject: [PATCH] * htons etc --- rtl/inc/sockets.inc | 54 +++++++++++++++++++++++++++++++++++++++++++- rtl/inc/socketsh.inc | 10 +++++++- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/rtl/inc/sockets.inc b/rtl/inc/sockets.inc index b28437f541..62dacfa1dc 100644 --- a/rtl/inc/sockets.inc +++ b/rtl/inc/sockets.inc @@ -170,9 +170,61 @@ begin else Accept:=false; end; + +type thostaddr= packed array[1..4] of byte; + +function htonl( host : longint):longint; {$ifndef VER1_0} inline; {$ENDIF} + +begin +{$ifdef FPC_BIG_ENDIAN} + htonl:=host; +{$else} + htonl:=THostAddr(host)[4]; + htonl:=htonl or ( (THostAddr(host)[3]) shl 8); + htonl:=htonl or ( (THostAddr(host)[2]) shl 16); + htonl:=htonl or ( (THostAddr(host)[1]) shl 24); +{$endif} +end; + +Function NToHl (Net : Longint) : Longint; {$ifndef VER1_0} inline; {$ENDIF} + +begin +{$ifdef FPC_BIG_ENDIAN} + ntohl:=net; +{$else} + ntohl:=THostAddr(Net)[4]; + ntohl:=ntohl or ( (THostAddr(Net)[3]) shl 8); + ntohl:=ntohl or ( (THostAddr(Net)[2]) shl 16); + ntohl:=ntohl or ( (THostAddr(Net)[1]) shl 24); +{$endif} +end; + +function htons( host : word):word; {$ifndef VER1_0} inline; {$ENDIF} + +begin +{$ifdef FPC_BIG_ENDIAN} + htonl:=host; +{$else} + htons:=swap(host); +{$endif} +end; + +Function NToHs (Net : word):word;{$ifndef VER1_0} inline; {$ENDIF} + +begin +{$ifdef FPC_BIG_ENDIAN} + ntohs:=net; +{$else} + ntohs:=swap(net); +{$endif} +end; + { $Log$ - Revision 1.11 2003-11-23 10:57:15 michael + Revision 1.12 2004-11-01 16:23:15 marco + * htons etc + + Revision 1.11 2003/11/23 10:57:15 michael + Changed mode to output for file sockets Revision 1.10 2003/11/22 21:58:09 marco diff --git a/rtl/inc/socketsh.inc b/rtl/inc/socketsh.inc index 0d8ad3dd62..15fd580938 100644 --- a/rtl/inc/socketsh.inc +++ b/rtl/inc/socketsh.inc @@ -184,9 +184,17 @@ Function Accept(Sock:longint;var addr:TInetSockAddr;var SockIn,SockOut:text):Boo Function Connect(Sock:longint;const addr:TInetSockAddr;var SockIn,SockOut:text):Boolean; Function Connect(Sock:longint;const addr:TInetSockAddr;var SockIn,SockOut:file):Boolean; +function htonl( host : longint):longint; {$ifndef ver1_0} inline; {$endif} +Function NToHl (Net : Longint) : Longint; {$ifndef ver1_0} inline; {$endif} +function htons( host : word):word; {$ifndef ver1_0} inline; {$endif} +Function NToHs (Net : word):word; {$ifndef ver1_0} inline; {$endif} + { $Log$ - Revision 1.14 2004-03-16 19:15:57 marco + Revision 1.15 2004-11-01 16:23:15 marco + * htons etc + + Revision 1.14 2004/03/16 19:15:57 marco * sockaddr is now a union between the old and new struct as grace period Revision 1.13 2004/03/16 18:03:37 marco