DEADSOFTWARE

added libsocket and updated watt32, but network still not work
[d2df-sdl.git] / src / lib / socket / socket.pas
1 // TCP/IP stack for winDOS
2 // ftp://ftp.delorie.com/pub/djgpp/current/v2tk/ls080b.zip
3 // ftp://ftp.delorie.com/pub/djgpp/current/v2tk/ls080d.zip
4 // ftp://ftp.delorie.com/pub/djgpp/current/v2tk/ls080s.zip
6 {$MODE OBJFPC}
7 {$PACKRECORDS C}
9 {$MODESWITCH OUT}
10 {$LONGSTRINGS ON}
11 {$MACRO ON}
13 {$LINKLIB libsocket.a}
14 {$LINKLIB libc.a}
15 {$DEFINE LibraryLibSockDecl := cdecl}
16 {$DEFINE LibraryLibSockImp := cdecl; external}
17 {$DEFINE LibraryLibSockVar := cvar; external}
19 unit socket;
21 interface
23 uses ctypes;
25 (* Start-up & shutdown *)
26 function __lsck_init: cint; LibraryLibSockImp;
27 procedure __lsck_uninit; LibraryLibSockImp;
29 (* Configuration *)
30 function __lsck_config_getdir: PChar; LibraryLibSockImp;
31 function __lsck_config_setdir (newdir: PChar): PChar; LibraryLibSockImp;
32 function __lsck_config_getfile: PChar; LibraryLibSockImp;
33 function __lsck_config_setfile (newfile: PChar): PChar; LibraryLibSockImp;
35 (* DNS address(es) *)
36 function __lsck_getdnsaddr: PChar; LibraryLibSockImp;
37 function __lsck_getdnsaddrs: PPChar; LibraryLibSockImp;
39 (* Error fudging *)
40 //function lsck_strerror (errnum: cint): PChar; LibraryLibSockImp;
41 function lsck_strerror (errnum: cint): PChar; LibraryLibSockImp name 'strerror';
43 (* File descriptor tests *)
44 function __fd_is_socket (fd: cint): cint; LibraryLibSockImp;
45 function __fd_is_valid (fd: cint): cint; LibraryLibSockImp;
47 (* Debugging *)
48 const
49 LSCK_DEBUG_OFF = 0;
50 LSCK_DEBUG_NORMAL = 1;
51 LSCK_DEBUG_VERBOSE = 2;
52 LSCK_DEBUG_ON = LSCK_DEBUG_NORMAL;
54 procedure __lsck_debug_setlevel (level: cint); LibraryLibSockImp;
55 function __lsck_debug_getlevel: cint; LibraryLibSockImp;
56 procedure __lsck_debug_enable; LibraryLibSockImp;
57 procedure __lsck_debug_disable; LibraryLibSockImp;
58 function __lsck_debug_enabled: cint; LibraryLibSockImp;
60 (* lsck/copyrite.h *)
61 function __lsck_get_version: PChar; LibraryLibSockImp;
62 function __lsck_get_copyright: PChar; LibraryLibSockImp;
64 (* lsck/domname.h *)
65 function getdomainname (name: PChar; len: csize_t): cint; LibraryLibSockImp;
66 function setdomainname (const name: PChar; len: csize_t): cint; LibraryLibSockImp;
68 (* lsck/hostname.h *)
69 function gethostname (buf: PChar; size: cint): cint; LibraryLibSockImp;
70 function sethostname (buf: PChar; size: cint): cint; LibraryLibSockImp;
72 (* lsck/if.h *)
73 {...}
77 function htonl (_val: culong): culong; LibraryLibSockImp;
78 function ntohl (_val: culong): culong; LibraryLibSockImp;
79 function htons (_val: cushort): cushort; LibraryLibSockImp;
80 function ntohs (_val: cushort): cushort; LibraryLibSockImp;
84 (* MACRO *)
85 const
86 FD_MAXFDSET = 256; (* FD_SETSIZE *)
88 type
89 (* djgpp sys-include -> sys/wtypes.h -> fd_set *)
90 TFDSet = record
91 fd_bits: array [0..(FD_MAXFDSET + 7) DIV 8] of cuchar;
92 end;
94 function fpFD_SET (fdno: cint; var nset: TFDSet): cint;
95 function fpFD_CLR (fdno: cint; var nset: TFDSet): cint;
96 function fpFD_ZERO (out nset: TFDSet): cint;
97 function fpFD_ISSET (fdno: cint; const nset: TFDSet): cint;
99 implementation
101 function fpFD_SET (fdno: cint; var nset: TFDSet): cint;
102 begin
103 if (fdno < 0) or (fdno > FD_MAXFDSET) then
104 exit(-1);
105 nset.fd_bits[fdno div 8] := nset.fd_bits[fdno div 8] OR (culong(1) shl (fdno and 7));
106 fpFD_SET := 0
107 end;
109 function fpFD_CLR (fdno: cint; var nset: TFDSet): cint;
110 begin
111 if (fdno < 0) or (fdno > FD_MAXFDSET) Then
112 exit(-1);
113 nset.fd_bits[fdno div 8] := nset.fd_bits[fdno div 8] AND Cardinal(NOT (culong(1) shl (fdno and 7)));
114 fpFD_CLR := 0
115 end;
117 function fpFD_ZERO (out nset: TFDSet): cint;
118 var i: longint;
119 begin
120 for i := 0 to (FD_MAXFDSET + 7) div 8 DO
121 nset.fd_bits[i] := 0;
122 fpFD_ZERO := 0
123 end;
125 function fpFD_ISSET (fdno: cint; const nset: TFDSet): cint;
126 begin
127 if (fdno < 0) or (fdno > FD_MAXFDSET) Then
128 exit(-1);
129 if ((nset.fd_bits[fdno div 8]) and (culong(1) shl (fdno and 7))) > 0 then
130 fpFD_ISSET := 1
131 else
132 fpFD_ISSET := 0
133 end;
135 end.