1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
{
This file is part of the Free Pascal run time library.
(c) 2004 by Marco van de Voort
member of the Free Pascal development team.
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
socket call implementations for Linux
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY;without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
}
{$ifndef cpux86_64}
{$define NEED_SOCKETCALL}
{$endif}
{******************************************************************************
Basic Socket Functions
******************************************************************************}
{$ifdef NEED_SOCKETCALL}
Const
{
Arguments to the Linux Kernel system call for sockets. All
Socket Connected calls go through the same system call,
with an extra argument to determine what action to take.
}
Socket_Sys_SOCKET = 1;
Socket_Sys_BIND = 2;
Socket_Sys_CONNECT = 3;
Socket_Sys_LISTEN = 4;
Socket_Sys_ACCEPT = 5;
Socket_Sys_GETSOCKNAME = 6;
Socket_Sys_GETPEERNAME = 7;
Socket_Sys_SOCKETPAIR = 8;
Socket_Sys_SEND = 9;
Socket_Sys_RECV = 10;
Socket_Sys_SENDTO = 11;
Socket_Sys_RECVFROM = 12;
Socket_Sys_SHUTDOWN = 13;
Socket_Sys_SETSOCKOPT = 14;
Socket_Sys_GETSOCKOPT = 15;
Socket_Sys_SENDMSG = 16;
Socket_Sys_RECVMSG = 17;
Function SocketCall(SockCallNr,a1,a2,a3,a4,a5,a6:longint):longint;
var
Args:array[1..6] of longint;
begin
args[1]:=a1;
args[2]:=a2;
args[3]:=a3;
args[4]:=a4;
args[5]:=a5;
args[6]:=a6;
SocketCall:=do_Syscall(syscall_nr_socketcall,sockcallnr,longint(@args));
If SocketCall<0 then
SocketError:=fpgetErrno
else
SocketError:=0;
end;
function SocketCall(SockCallNr,a1,a2,a3:longint):longint;
begin
SocketCall:=SocketCall(SockCallNr,a1,a2,a3,0,0,0);
end;
function fpsocket (domain:cint; xtype:cint; protocol: cint):cint;
begin
fpSocket:=SocketCall(Socket_Sys_socket,Domain,xtype,Protocol);
end;
function fpsend (s:cint; msg:pointer; len:size_t; flags:cint):ssize_t;
begin
fpSend:=SocketCall(Socket_Sys_sendto,S,TSysParam(msg),Len,Flags,0,0);
end;
function fpsendto (s:cint; msg:pointer; len:size_t; flags:cint; tox :psockaddr; tolen: tsocklen):ssize_t;
begin
fpSendto:=SocketCall(Socket_Sys_sendto,S,TSysParam(msg),Len,Flags,TSysParam(tox),tolen);
end;
function fprecv (s:cint; buf: pointer; len: size_t; flags:cint):ssize_t;
begin
fpRecv:=SocketCall(Socket_Sys_Recvfrom,S,tsysparam(buf),len,flags,0,0);
end;
function fprecvfrom (s:cint; buf: pointer; len: size_t; flags: cint; from : psockaddr; fromlen : psocklen):ssize_t;
begin
fpRecvFrom:=SocketCall(Socket_Sys_Recvfrom,S,TSysParam(buf),len,flags,TSysParam(from),TSysParam(fromlen));
end;
function fpbind (s:cint; addrx : psockaddr; addrlen : tsocklen):cint;
begin
fpBind:=SocketCall(Socket_Sys_Bind,S,TSysParam(addrx),addrlen);
end;
function fplisten (s:cint; backlog : cint):cint;
begin
fpListen:=SocketCall(Socket_Sys_Listen,S,backlog,0);
end;
function fpaccept (s:cint; addrx : psockaddr; addrlen : psocklen):cint;
begin
fpAccept:=SocketCall(Socket_Sys_accept,S,TSysParam(addrx),TSysParam(addrlen));
end;
function fpconnect (s:cint; name : psockaddr; namelen : tsocklen):cint;
begin
fpConnect:=SocketCall(Socket_Sys_connect,S,TSysParam(name),namelen);
end;
function fpshutdown (s:cint; how:cint):cint;
begin
fpShutDown:=SocketCall(Socket_Sys_shutdown,S,how,0);
end;
function fpgetsockname (s:cint; name : psockaddr; namelen : psocklen):cint;
begin
fpGetSockName:=SocketCall(Socket_Sys_GetSockName,S,TSysParam(name),TSysParam(namelen));
end;
function fpgetpeername (s:cint; name : psockaddr; namelen : psocklen):cint;
begin
fpGetPeerName:=SocketCall(Socket_Sys_GetPeerName,S,TSysParam(name),TSysParam(namelen));
end;
function fpsetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen : tsocklen):cint;
begin
fpSetSockOpt:=SocketCall(Socket_Sys_SetSockOpt,S,level,optname,TSysParam(optval),optlen,0);
end;
function fpgetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen : psocklen):cint;
begin
fpGetSockOpt:=SocketCall(Socket_Sys_GetSockOpt,S,level,TSysParam(optname),TSysParam(optval),TSysParam(optlen),0);
end;
function fpsocketpair (d:cint; xtype:cint; protocol:cint; sv:pcint):cint;
begin
fpSocketPair:=SocketCall(Socket_Sys_SocketPair,d,xtype,protocol,TSysParam(sv),0,0);
end;
{$else NEED_SOCKETCALL}
function fpsocket (domain:cint; xtype:cint; protocol: cint):cint;
begin
fpSocket:=do_syscall(syscall_nr_socket,Domain,xtype,Protocol);
end;
function fpsend (s:cint; msg:pointer; len:size_t; flags:cint):ssize_t;
begin
fpSend:=do_syscall(syscall_nr_sendto,S,TSysParam(msg),Len,Flags);
end;
function fpsendto (s:cint; msg:pointer; len:size_t; flags:cint; tox :psockaddr; tolen: tsocklen):ssize_t;
begin
fpSendto:=do_syscall(syscall_nr_sendto,S,TSysParam(msg),Len,Flags,TSysParam(tox),tolen);
end;
function fprecv (s:cint; buf: pointer; len: size_t; flags:cint):ssize_t;
begin
fpRecv:=do_syscall(syscall_nr_Recvfrom,S,tsysparam(buf),len,flags);
end;
function fprecvfrom (s:cint; buf: pointer; len: size_t; flags: cint; from : psockaddr; fromlen : psocklen):ssize_t;
begin
fpRecvFrom:=do_syscall(syscall_nr_Recvfrom,S,TSysParam(buf),len,flags,TSysParam(from),TSysParam(fromlen));
end;
function fpbind (s:cint; addrx : psockaddr; addrlen : tsocklen):cint;
begin
fpBind:=do_syscall(syscall_nr_Bind,S,TSysParam(addrx),addrlen);
end;
function fplisten (s:cint; backlog : cint):cint;
begin
fpListen:=do_syscall(syscall_nr_Listen,S,backlog);
end;
function fpaccept (s:cint; addrx : psockaddr; addrlen : psocklen):cint;
begin
fpAccept:=do_syscall(syscall_nr_accept,S,TSysParam(addrx),TSysParam(addrlen));
end;
function fpconnect (s:cint; name : psockaddr; namelen : tsocklen):cint;
begin
fpConnect:=do_syscall(syscall_nr_connect,S,TSysParam(name),namelen);
end;
function fpshutdown (s:cint; how:cint):cint;
begin
fpShutDown:=do_syscall(syscall_nr_shutdown,S,how);
end;
function fpgetsockname (s:cint; name : psockaddr; namelen : psocklen):cint;
begin
fpGetSockName:=do_syscall(syscall_nr_GetSockName,S,TSysParam(name),TSysParam(namelen));
end;
function fpgetpeername (s:cint; name : psockaddr; namelen : psocklen):cint;
begin
fpGetPeerName:=do_syscall(syscall_nr_GetPeerName,S,TSysParam(name),TSysParam(namelen));
end;
function fpsetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen : tsocklen):cint;
begin
fpSetSockOpt:=do_syscall(syscall_nr_SetSockOpt,S,level,optname,TSysParam(optval),optlen);
end;
function fpgetsockopt (s:cint; level:cint; optname:cint; optval:pointer; optlen : psocklen):cint;
begin
fpGetSockOpt:=do_syscall(syscall_nr_GetSockOpt,S,level,TSysParam(optname),TSysParam(optval),TSysParam(optlen));
end;
function fpsocketpair (d:cint; xtype:cint; protocol:cint; sv:pcint):cint;
begin
fpSocketPair:=do_syscall(syscall_nr_SocketPair,d,xtype,protocol,TSysParam(sv));
end;
{$endif NEED_do_syscall}
{
$Log: unixsock.inc,v $
Revision 1.14 2005/02/14 17:13:30 peter
* truncate log
}
|