mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-16 19:19:19 +02:00
Amiga, AROS, MorphOS: Prevent crash when access socket without TCP/IP Stack running
git-svn-id: trunk@48805 -
This commit is contained in:
parent
cfa3f4fa8c
commit
53d847f268
@ -48,7 +48,7 @@ Type
|
|||||||
|
|
||||||
{ remember, classic style calls are also used on MorphOS, so don't test for AMIGA68K }
|
{ remember, classic style calls are also used on MorphOS, so don't test for AMIGA68K }
|
||||||
{$ifndef AMIGAOS4}
|
{$ifndef AMIGAOS4}
|
||||||
function gethostbyname(Name: PChar location 'a0'): PHostEntry; syscall SocketBase 210;
|
function fpgethostbyname(Name: PChar location 'a0'): PHostEntry; syscall SocketBase 210;
|
||||||
function getnetbyname(Name: PChar location 'a0'): PNetEntry; syscall SocketBase 222;
|
function getnetbyname(Name: PChar location 'a0'): PNetEntry; syscall SocketBase 222;
|
||||||
function getnetbyaddr(Net: Longint location 'd0'; NetType: Longint location 'd1'): PNetEntry; syscall SocketBase 228;
|
function getnetbyaddr(Net: Longint location 'd0'; NetType: Longint location 'd1'): PNetEntry; syscall SocketBase 228;
|
||||||
function getservbyname(Name: PChar location 'a0'; Protocol: PChar location 'a1'): PServEntry; syscall SocketBase 234;
|
function getservbyname(Name: PChar location 'a0'; Protocol: PChar location 'a1'): PServEntry; syscall SocketBase 234;
|
||||||
@ -63,7 +63,7 @@ function getservent: PServEntry; syscall SocketBase 564;
|
|||||||
|
|
||||||
{$else AMIGAOS4}
|
{$else AMIGAOS4}
|
||||||
|
|
||||||
function gethostbyname(const Name: PChar): PHostEntry; syscall ISocket 196;
|
function fpgethostbyname(const Name: PChar): PHostEntry; syscall ISocket 196;
|
||||||
function getnetbyname(Name: PChar): PNetEntry; syscall ISocket 204;
|
function getnetbyname(Name: PChar): PNetEntry; syscall ISocket 204;
|
||||||
function getnetbyaddr(Net: Longint; NetType: Longint): PNetEntry; syscall ISocket 208;
|
function getnetbyaddr(Net: Longint; NetType: Longint): PNetEntry; syscall ISocket 208;
|
||||||
function getservbyname(Name: PChar; Protocol: PChar): PServEntry; syscall ISocket 212;
|
function getservbyname(Name: PChar; Protocol: PChar): PServEntry; syscall ISocket 212;
|
||||||
@ -77,12 +77,24 @@ procedure endservent; syscall ISocket 484;
|
|||||||
function getservent: PServEntry; syscall ISocket 488;
|
function getservent: PServEntry; syscall ISocket 488;
|
||||||
{$endif AMIGAOS4}
|
{$endif AMIGAOS4}
|
||||||
|
|
||||||
|
function gethostbyname(Name: PChar): PHostEntry;
|
||||||
|
begin
|
||||||
|
if Assigned(SocketBase) then
|
||||||
|
gethostbyname := fpgethostbyname(Name)
|
||||||
|
else
|
||||||
|
gethostbyname := nil;
|
||||||
|
end;
|
||||||
|
|
||||||
function gethostbyaddr(Addr: PChar; Len: Longint; HType: Longint): PHostentry;
|
function gethostbyaddr(Addr: PChar; Len: Longint; HType: Longint): PHostentry;
|
||||||
var
|
var
|
||||||
addr1,
|
addr1,
|
||||||
addr2: in_addr;
|
addr2: in_addr;
|
||||||
IP: PPLongInt;
|
IP: PPLongInt;
|
||||||
begin
|
begin
|
||||||
|
gethostbyaddr := nil;
|
||||||
|
if not Assigned(SocketBase) then
|
||||||
|
Exit;
|
||||||
|
//
|
||||||
Addr1 := in_addr(PHostAddr(Addr)^);
|
Addr1 := in_addr(PHostAddr(Addr)^);
|
||||||
Addr2.s_addr := htonl(Addr1.s_addr);
|
Addr2.s_addr := htonl(Addr1.s_addr);
|
||||||
gethostbyaddr := Pointer(bsd_GetHostByAddr(Pointer(@Addr2.s_addr), Len, HType));
|
gethostbyaddr := Pointer(bsd_GetHostByAddr(Pointer(@Addr2.s_addr), Len, HType));
|
||||||
@ -101,12 +113,14 @@ end;
|
|||||||
|
|
||||||
function GetDNSError: integer;
|
function GetDNSError: integer;
|
||||||
begin
|
begin
|
||||||
GetDNSError:=bsd_Errno;
|
GetDNSError := 0;
|
||||||
|
if assigned(SocketBase) then
|
||||||
|
GetDNSError:=bsd_Errno;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function InitResolve : Boolean;
|
Function InitResolve : Boolean;
|
||||||
begin
|
begin
|
||||||
Result:=True;
|
Result:=Assigned(SocketBase);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function FinalResolve : Boolean;
|
Function FinalResolve : Boolean;
|
||||||
|
@ -48,7 +48,7 @@ Type
|
|||||||
|
|
||||||
{ C style calls, linked in from Libc }
|
{ C style calls, linked in from Libc }
|
||||||
|
|
||||||
function gethostbyname(Name: PChar): PHostEntry; syscall SocketBase 35;
|
function fpgethostbyname(Name: PChar): PHostEntry; syscall SocketBase 35;
|
||||||
function getnetbyname(Name: PChar): PNetEntry; syscall SocketBase 37;
|
function getnetbyname(Name: PChar): PNetEntry; syscall SocketBase 37;
|
||||||
function getnetbyaddr(Net: Longint; NetType: Longint): PNetEntry; syscall SocketBase 38;
|
function getnetbyaddr(Net: Longint; NetType: Longint): PNetEntry; syscall SocketBase 38;
|
||||||
function getservbyname(Name: PChar; Protocol: PChar): PServEntry; syscall SocketBase 39;
|
function getservbyname(Name: PChar; Protocol: PChar): PServEntry; syscall SocketBase 39;
|
||||||
@ -61,12 +61,25 @@ procedure setservent(StayOpen: longint); syscall SocketBase 92;
|
|||||||
procedure endservent; syscall SocketBase 93;
|
procedure endservent; syscall SocketBase 93;
|
||||||
function getservent: PServEntry; syscall SocketBase 94;
|
function getservent: PServEntry; syscall SocketBase 94;
|
||||||
|
|
||||||
|
|
||||||
|
function gethostbyname(Name: PChar): PHostEntry;
|
||||||
|
begin
|
||||||
|
if Assigned(SocketBase) then
|
||||||
|
gethostbyname := fpgethostbyname(Name)
|
||||||
|
else
|
||||||
|
gethostbyname := nil;
|
||||||
|
end;
|
||||||
|
|
||||||
function gethostbyaddr(Addr: PChar; Len: Longint; HType: Longint): PHostentry;
|
function gethostbyaddr(Addr: PChar; Len: Longint; HType: Longint): PHostentry;
|
||||||
var
|
var
|
||||||
addr1,
|
addr1,
|
||||||
addr2: in_addr;
|
addr2: in_addr;
|
||||||
IP: PPLongInt;
|
IP: PPLongInt;
|
||||||
begin
|
begin
|
||||||
|
gethostbyaddr := nil;
|
||||||
|
if not Assigned(SocketBase) then
|
||||||
|
Exit;
|
||||||
|
//
|
||||||
Addr1 := in_addr(PHostAddr(Addr)^);
|
Addr1 := in_addr(PHostAddr(Addr)^);
|
||||||
Addr2.s_addr := htonl(Addr1.s_addr);
|
Addr2.s_addr := htonl(Addr1.s_addr);
|
||||||
gethostbyaddr := Pointer(bsd_GetHostByAddr(Pointer(@Addr2.s_addr), Len, HType));
|
gethostbyaddr := Pointer(bsd_GetHostByAddr(Pointer(@Addr2.s_addr), Len, HType));
|
||||||
@ -78,19 +91,21 @@ begin
|
|||||||
repeat
|
repeat
|
||||||
ip^^ := ntohl(ip^^);
|
ip^^ := ntohl(ip^^);
|
||||||
Inc(IP);
|
Inc(IP);
|
||||||
until ip^ = nil;
|
until ip^ = nil;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function GetDNSError: integer;
|
function GetDNSError: integer;
|
||||||
begin
|
begin
|
||||||
GetDNSError:=bsd_Errno;
|
GetDNSError := 0;
|
||||||
|
if assigned(SocketBase) then
|
||||||
|
GetDNSError := bsd_Errno;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function InitResolve : Boolean;
|
Function InitResolve : Boolean;
|
||||||
begin
|
begin
|
||||||
Result:=True;
|
Result := Assigned(SocketBase);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function FinalResolve : Boolean;
|
Function FinalResolve : Boolean;
|
||||||
|
@ -201,12 +201,18 @@ end;
|
|||||||
|
|
||||||
function fpgeterrno: longint; inline;
|
function fpgeterrno: longint; inline;
|
||||||
begin
|
begin
|
||||||
fpgeterrno := bsd_Errno;
|
if Assigned(SocketBase) then
|
||||||
|
fpgeterrno := bsd_Errno
|
||||||
|
else
|
||||||
|
fpgeterrno := 0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function fpClose(d: LongInt): LongInt; inline;
|
function fpClose(d: LongInt): LongInt; inline;
|
||||||
begin
|
begin
|
||||||
fpClose := bsd_CloseSocket(d);
|
if Assigned(SocketBase) then
|
||||||
|
fpClose := bsd_CloseSocket(d)
|
||||||
|
else
|
||||||
|
fpClose := -1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function fpaccept(s: cint; addrx: PSockaddr; Addrlen: PSocklen): cint;
|
function fpaccept(s: cint; addrx: PSockaddr; Addrlen: PSocklen): cint;
|
||||||
@ -289,8 +295,16 @@ end;
|
|||||||
|
|
||||||
function fpsocket(domain: cint; xtype: cint; protocol: cint): cint;
|
function fpsocket(domain: cint; xtype: cint; protocol: cint): cint;
|
||||||
begin
|
begin
|
||||||
fpsocket := bsd_socket(domain, xtype, protocol);
|
if Assigned(SocketBase) then
|
||||||
internal_socketerror := fpgeterrno;
|
begin
|
||||||
|
fpsocket := bsd_socket(domain, xtype, protocol);
|
||||||
|
internal_socketerror := fpgeterrno;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
fpsocket := -1;
|
||||||
|
internal_socketerror := ESockEPROTONOSUPPORT;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ const
|
|||||||
SOL_SOCKET = $FFFF;
|
SOL_SOCKET = $FFFF;
|
||||||
|
|
||||||
const
|
const
|
||||||
EsockEINTR = 4; // EsysEINTR;
|
EsockEINTR = 4; // EsysEINTR;
|
||||||
EsockEBADF = 9; // EsysEBADF;
|
EsockEBADF = 9; // EsysEBADF;
|
||||||
EsockEFAULT = 14; // EsysEFAULT;
|
EsockEFAULT = 14; // EsysEFAULT;
|
||||||
EsockEINVAL = 22; //EsysEINVAL;
|
EsockEINVAL = 22; //EsysEINVAL;
|
||||||
@ -155,18 +155,24 @@ end;
|
|||||||
|
|
||||||
function fpgeterrno: longint; inline;
|
function fpgeterrno: longint; inline;
|
||||||
begin
|
begin
|
||||||
fpgeterrno := bsd_Errno;
|
if Assigned(SocketBase) then
|
||||||
|
fpgeterrno := bsd_Errno
|
||||||
|
else
|
||||||
|
fpgeterrno := 0;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function fpClose(d: LongInt): LongInt; inline;
|
function fpClose(d: LongInt): LongInt; inline;
|
||||||
begin
|
begin
|
||||||
fpClose := bsd_CloseSocket(d);
|
if Assigned(SocketBase) then
|
||||||
|
fpClose := bsd_CloseSocket(d)
|
||||||
|
else
|
||||||
|
fpClose := -1;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function fpaccept(s: cint; addrx: PSockaddr; Addrlen: PSocklen): cint;
|
function fpaccept(s: cint; addrx: PSockaddr; Addrlen: PSocklen): cint;
|
||||||
begin
|
begin
|
||||||
fpaccept := bsd_accept(s,addrx,addrlen);
|
fpaccept := bsd_accept(s,addrx,addrlen);
|
||||||
internal_socketerror := fpgeterrno;
|
internal_socketerror := fpgeterrno;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function fpbind(s:cint; addrx: psockaddr; addrlen: tsocklen): cint;
|
function fpbind(s:cint; addrx: psockaddr; addrlen: tsocklen): cint;
|
||||||
@ -177,8 +183,16 @@ end;
|
|||||||
|
|
||||||
function fpconnect(s:cint; name: psockaddr; namelen: tsocklen): cint;
|
function fpconnect(s:cint; name: psockaddr; namelen: tsocklen): cint;
|
||||||
begin
|
begin
|
||||||
fpconnect := bsd_connect(s, name, namelen);
|
if Assigned(SocketBase) then
|
||||||
internal_socketerror := fpgeterrno;
|
begin
|
||||||
|
fpconnect := bsd_connect(s, name, namelen);
|
||||||
|
internal_socketerror := fpgeterrno;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
fpconnect := -1;
|
||||||
|
internal_socketerror := ESockEPROTONOSUPPORT;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function fpgetpeername (s:cint; name : psockaddr; namelen : psocklen):cint;
|
function fpgetpeername (s:cint; name : psockaddr; namelen : psocklen):cint;
|
||||||
@ -243,8 +257,16 @@ end;
|
|||||||
|
|
||||||
function fpsocket(domain: cint; xtype: cint; protocol: cint): cint;
|
function fpsocket(domain: cint; xtype: cint; protocol: cint): cint;
|
||||||
begin
|
begin
|
||||||
fpsocket := bsd_socket(domain, xtype, protocol);
|
if Assigned(SocketBase) then
|
||||||
internal_socketerror := fpgeterrno;
|
begin
|
||||||
|
fpsocket := bsd_socket(domain, xtype, protocol);
|
||||||
|
internal_socketerror := fpgeterrno;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
internal_socketerror := ESockEPROTONOSUPPORT;
|
||||||
|
fpsocket := -1;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user