mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-09-25 11:09:17 +02:00
* inet removed
This commit is contained in:
parent
f52d2b2edf
commit
196102e361
@ -221,25 +221,25 @@ endif
|
||||
PACKAGESDIR:=$(wildcard $(FPCDIR) $(FPCDIR)/packages/base $(FPCDIR)/packages/extra)
|
||||
override TARGET_DIRS+=paszlib pasjpeg regexpr netdb md5
|
||||
ifeq ($(OS_TARGET),linux)
|
||||
override TARGET_DIRS+=inet gdbint libasync mysql ibase postgres oracle odbc pthreads sqlite libc
|
||||
override TARGET_DIRS+=gdbint libasync mysql ibase postgres oracle odbc pthreads sqlite libc
|
||||
endif
|
||||
ifeq ($(OS_TARGET),go32v2)
|
||||
override TARGET_DIRS+=gdbint
|
||||
endif
|
||||
ifeq ($(OS_TARGET),win32)
|
||||
override TARGET_DIRS+=inet gdbint mysql ibase odbc sqlite
|
||||
override TARGET_DIRS+=gdbint mysql ibase odbc sqlite
|
||||
endif
|
||||
ifeq ($(OS_TARGET),freebsd)
|
||||
override TARGET_DIRS+=inet gdbint libasync mysql ibase postgres oracle odbc sqlite pthreads
|
||||
override TARGET_DIRS+=gdbint libasync mysql ibase postgres oracle odbc sqlite pthreads
|
||||
endif
|
||||
ifeq ($(OS_TARGET),netbsd)
|
||||
override TARGET_DIRS+=inet gdbint libasync mysql ibase postgres oracle odbc
|
||||
override TARGET_DIRS+=gdbint libasync mysql ibase postgres oracle odbc
|
||||
endif
|
||||
ifeq ($(OS_TARGET),openbsd)
|
||||
override TARGET_DIRS+=inet gdbint libasync mysql ibase postgres oracle odbc
|
||||
override TARGET_DIRS+=gdbint libasync mysql ibase postgres oracle odbc
|
||||
endif
|
||||
ifeq ($(OS_TARGET),darwin)
|
||||
override TARGET_DIRS+=inet libasync mysql ibase postgres oracle odbc sqlite pthreads
|
||||
override TARGET_DIRS+=libasync mysql ibase postgres oracle odbc sqlite pthreads
|
||||
endif
|
||||
override INSTALL_FPCPACKAGE=y
|
||||
override INSTALL_FPCSUBDIR=packages/base
|
||||
@ -1473,7 +1473,6 @@ TARGET_DIRS_REGEXPR=1
|
||||
TARGET_DIRS_NETDB=1
|
||||
TARGET_DIRS_MD5=1
|
||||
ifeq ($(OS_TARGET),linux)
|
||||
TARGET_DIRS_INET=1
|
||||
TARGET_DIRS_GDBINT=1
|
||||
TARGET_DIRS_LIBASYNC=1
|
||||
TARGET_DIRS_MYSQL=1
|
||||
@ -1489,7 +1488,6 @@ ifeq ($(OS_TARGET),go32v2)
|
||||
TARGET_DIRS_GDBINT=1
|
||||
endif
|
||||
ifeq ($(OS_TARGET),win32)
|
||||
TARGET_DIRS_INET=1
|
||||
TARGET_DIRS_GDBINT=1
|
||||
TARGET_DIRS_MYSQL=1
|
||||
TARGET_DIRS_IBASE=1
|
||||
@ -1497,7 +1495,6 @@ TARGET_DIRS_ODBC=1
|
||||
TARGET_DIRS_SQLITE=1
|
||||
endif
|
||||
ifeq ($(OS_TARGET),freebsd)
|
||||
TARGET_DIRS_INET=1
|
||||
TARGET_DIRS_GDBINT=1
|
||||
TARGET_DIRS_LIBASYNC=1
|
||||
TARGET_DIRS_MYSQL=1
|
||||
@ -1509,7 +1506,6 @@ TARGET_DIRS_SQLITE=1
|
||||
TARGET_DIRS_PTHREADS=1
|
||||
endif
|
||||
ifeq ($(OS_TARGET),netbsd)
|
||||
TARGET_DIRS_INET=1
|
||||
TARGET_DIRS_GDBINT=1
|
||||
TARGET_DIRS_LIBASYNC=1
|
||||
TARGET_DIRS_MYSQL=1
|
||||
@ -1519,7 +1515,6 @@ TARGET_DIRS_ORACLE=1
|
||||
TARGET_DIRS_ODBC=1
|
||||
endif
|
||||
ifeq ($(OS_TARGET),openbsd)
|
||||
TARGET_DIRS_INET=1
|
||||
TARGET_DIRS_GDBINT=1
|
||||
TARGET_DIRS_LIBASYNC=1
|
||||
TARGET_DIRS_MYSQL=1
|
||||
@ -1529,7 +1524,6 @@ TARGET_DIRS_ORACLE=1
|
||||
TARGET_DIRS_ODBC=1
|
||||
endif
|
||||
ifeq ($(OS_TARGET),darwin)
|
||||
TARGET_DIRS_INET=1
|
||||
TARGET_DIRS_LIBASYNC=1
|
||||
TARGET_DIRS_MYSQL=1
|
||||
TARGET_DIRS_IBASE=1
|
||||
@ -1764,51 +1758,6 @@ md5:
|
||||
$(MAKE) -C md5 all
|
||||
.PHONY: md5_all md5_debug md5_smart md5_release md5_units md5_examples md5_shared md5_install md5_sourceinstall md5_exampleinstall md5_distinstall md5_zipinstall md5_zipsourceinstall md5_zipexampleinstall md5_zipdistinstall md5_clean md5_distclean md5_cleanall md5_info md5_makefiles md5
|
||||
endif
|
||||
ifdef TARGET_DIRS_INET
|
||||
inet_all:
|
||||
$(MAKE) -C inet all
|
||||
inet_debug:
|
||||
$(MAKE) -C inet debug
|
||||
inet_smart:
|
||||
$(MAKE) -C inet smart
|
||||
inet_release:
|
||||
$(MAKE) -C inet release
|
||||
inet_units:
|
||||
$(MAKE) -C inet units
|
||||
inet_examples:
|
||||
$(MAKE) -C inet examples
|
||||
inet_shared:
|
||||
$(MAKE) -C inet shared
|
||||
inet_install:
|
||||
$(MAKE) -C inet install
|
||||
inet_sourceinstall:
|
||||
$(MAKE) -C inet sourceinstall
|
||||
inet_exampleinstall:
|
||||
$(MAKE) -C inet exampleinstall
|
||||
inet_distinstall:
|
||||
$(MAKE) -C inet distinstall
|
||||
inet_zipinstall:
|
||||
$(MAKE) -C inet zipinstall
|
||||
inet_zipsourceinstall:
|
||||
$(MAKE) -C inet zipsourceinstall
|
||||
inet_zipexampleinstall:
|
||||
$(MAKE) -C inet zipexampleinstall
|
||||
inet_zipdistinstall:
|
||||
$(MAKE) -C inet zipdistinstall
|
||||
inet_clean:
|
||||
$(MAKE) -C inet clean
|
||||
inet_distclean:
|
||||
$(MAKE) -C inet distclean
|
||||
inet_cleanall:
|
||||
$(MAKE) -C inet cleanall
|
||||
inet_info:
|
||||
$(MAKE) -C inet info
|
||||
inet_makefiles:
|
||||
$(MAKE) -C inet makefiles
|
||||
inet:
|
||||
$(MAKE) -C inet all
|
||||
.PHONY: inet_all inet_debug inet_smart inet_release inet_units inet_examples inet_shared inet_install inet_sourceinstall inet_exampleinstall inet_distinstall inet_zipinstall inet_zipsourceinstall inet_zipexampleinstall inet_zipdistinstall inet_clean inet_distclean inet_cleanall inet_info inet_makefiles inet
|
||||
endif
|
||||
ifdef TARGET_DIRS_GDBINT
|
||||
gdbint_all:
|
||||
$(MAKE) -C gdbint all
|
||||
|
@ -4,17 +4,17 @@
|
||||
|
||||
[target]
|
||||
dirs=paszlib pasjpeg regexpr netdb md5
|
||||
dirs_linux=inet gdbint libasync mysql ibase postgres oracle odbc \
|
||||
dirs_linux=gdbint libasync mysql ibase postgres oracle odbc \
|
||||
pthreads sqlite libc
|
||||
dirs_win32=inet gdbint mysql ibase odbc sqlite
|
||||
dirs_win32=gdbint mysql ibase odbc sqlite
|
||||
dirs_go32v2=gdbint
|
||||
dirs_netbsd=inet gdbint libasync \
|
||||
dirs_netbsd=gdbint libasync \
|
||||
mysql ibase postgres oracle odbc
|
||||
dirs_openbsd=inet gdbint libasync \
|
||||
dirs_openbsd=gdbint libasync \
|
||||
mysql ibase postgres oracle odbc
|
||||
dirs_freebsd=inet gdbint libasync \
|
||||
dirs_freebsd=gdbint libasync \
|
||||
mysql ibase postgres oracle odbc sqlite pthreads
|
||||
dirs_darwin=inet libasync \
|
||||
dirs_darwin=libasync \
|
||||
mysql ibase postgres oracle odbc sqlite pthreads
|
||||
|
||||
[install]
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,17 +0,0 @@
|
||||
#
|
||||
# Makefile.fpc for Internet Units
|
||||
#
|
||||
|
||||
[package]
|
||||
name=inet
|
||||
version=1.9.4
|
||||
|
||||
[target]
|
||||
units=inet
|
||||
examples=testinet pfinger
|
||||
|
||||
[install]
|
||||
fpcpackage=y
|
||||
|
||||
[default]
|
||||
fpcdir=../../..
|
@ -1,568 +0,0 @@
|
||||
Unit inet;
|
||||
|
||||
{ --------------------------------------------------------------------
|
||||
Unit for internet domain calls.
|
||||
Copyright (C) 1997 Michael Van Canneyt
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 1, or (at your option)
|
||||
any later version.
|
||||
|
||||
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. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
ChangeLog
|
||||
---------
|
||||
|
||||
Current version is 0.6
|
||||
|
||||
Version Date Remarks
|
||||
------- ---- ----
|
||||
0.1 07/16/97 Unit started. Michael.
|
||||
0.2 07/06/98 Updated for version 0.99.5
|
||||
0.4 08/01/98 Objects for name lookup implemented
|
||||
0.5 09/10/98 Updated calls for 0.99.8.
|
||||
0.6 05/04/99 Added explicit asmmode.
|
||||
|
||||
------------------------------------------------------------------- }
|
||||
|
||||
|
||||
interface
|
||||
|
||||
Uses Initc; // link to libc.
|
||||
|
||||
Const
|
||||
{ Net type }
|
||||
AF_INET = 2;
|
||||
|
||||
{ Error constants. Returned by LastError method of THost, TNet}
|
||||
|
||||
NETDB_INTERNAL= -1; { see errno }
|
||||
NETDB_SUCCESS = 0; { no problem }
|
||||
HOST_NOT_FOUND= 1; { Authoritative Answer Host not found }
|
||||
TRY_AGAIN = 2; { Non-Authoritive Host not found, or SERVERFAIL }
|
||||
NO_RECOVERY = 3; { Non recoverable errors, FORMERR, REFUSED, NOTIMP }
|
||||
NO_DATA = 4; { Valid name, no data record of requested type }
|
||||
NO_ADDRESS = NO_DATA; { no address, look for MX record }
|
||||
|
||||
|
||||
|
||||
|
||||
Type
|
||||
THostAddr = array[1..4] of byte;
|
||||
PHostAddr = ^THostAddr;
|
||||
|
||||
Const
|
||||
NoAddress : THostAddr = (0,0,0,0);
|
||||
|
||||
Type
|
||||
|
||||
{ THostEnt Object }
|
||||
THostEnt = record
|
||||
Name : pchar; { Official name }
|
||||
Aliases : ppchar; { Null-terminated list of aliases}
|
||||
Addrtype : longint; { Host address type }
|
||||
Addrlen : longint; { Length of address }
|
||||
Addrlist : ppchar; { null-terminated list of adresses }
|
||||
end;
|
||||
PHostEnt = ^THostEnt;
|
||||
|
||||
{ TNetEnt object }
|
||||
TNetEnt = record
|
||||
Name : pchar; { Official name }
|
||||
Aliases : ppchar; { Nill-terminated alias list }
|
||||
AddrType : longint; { Net address type }
|
||||
net : Longint; { Network number }
|
||||
end;
|
||||
PNetEnt = ^TNetEnt;
|
||||
|
||||
TServEnt = record
|
||||
name : pchar; { Service name }
|
||||
aliases : ppchar; { Null-terminated alias list }
|
||||
port : longint; { Port number }
|
||||
proto : pchar; { Protocol to use }
|
||||
end;
|
||||
PServEnt = ^TServEnt;
|
||||
|
||||
{ Pascal Wrapper objects }
|
||||
|
||||
TSelectType = (stFirst,stNext,stPrevious);
|
||||
|
||||
THost = Object
|
||||
FHostEntry : PHostEnt;
|
||||
FAlias,FAddr,FError : Longint;
|
||||
Constructor NameLookup (HostName : String);
|
||||
Constructor AddressLookup (Const Address : THostAddr);
|
||||
Destructor Done;
|
||||
Function Name : String;
|
||||
Function GetAddress (Select : TSelectType) : String;
|
||||
Function GetAlias (Select : TSelectType) : String;
|
||||
Function IPAddress : THostAddr;
|
||||
Function IPString : String;
|
||||
Function LastError : Longint;
|
||||
end;
|
||||
|
||||
TNet = Object
|
||||
FNetEntry : PNetEnt;
|
||||
FAlias,FError : Longint;
|
||||
Constructor NameLookup (NetName : String);
|
||||
Constructor AddressLookup (Const Address : Longint);
|
||||
Destructor Done;
|
||||
Function Name : String;
|
||||
Function GetAlias (Select : TSelectType) : String;
|
||||
Function IPAddress : Longint;
|
||||
Function IPString : String;
|
||||
Function LastError : Longint;
|
||||
end;
|
||||
|
||||
TService = Object
|
||||
FServiceEntry : PServEnt;
|
||||
FAlias,FError : Longint;
|
||||
Constructor NameLookup (ServiceName,Proto : String);
|
||||
Constructor PortLookup (APort : Longint; Proto: string);
|
||||
Destructor Done;
|
||||
Function Name : String;
|
||||
Function Protocol : String;
|
||||
Function GetAlias (Select : TSelectType) : String;
|
||||
Function Port : Longint;
|
||||
Function LastError : Longint;
|
||||
end;
|
||||
|
||||
|
||||
|
||||
{ Pascal style calls }
|
||||
|
||||
function HostAddrToStr (Entry : THostAddr) : String;
|
||||
function StrToHostAddr (IP : String) : THostAddr;
|
||||
function NetAddrToStr (Entry : Longint) : String;
|
||||
function StrToNetAddr (IP : String) : Longint;
|
||||
Function HostToNet (Host : Longint) : Longint;
|
||||
Function NetToHost (Net : Longint) : Longint;
|
||||
Function ShortHostToNet (Host : Word) : Word;
|
||||
Function ShortNetToHost (Net : Word) : Word;
|
||||
|
||||
{ C style calls, linked in from Libc }
|
||||
|
||||
function gethostent : PHostEnt; cdecl; external;
|
||||
function gethostbyname ( Name : Pchar) : PHostEnt; cdecl; external;
|
||||
function gethostbyaddr ( Addr : PHostAddr; Len : Longint; HType : Longint) : PHostent ; cdecl; external;
|
||||
procedure sethostent (stayopen : longint); cdecl; external;
|
||||
procedure endhostent; cdecl; external;
|
||||
|
||||
function getnetent : PNetEnt; cdecl; external;
|
||||
function getnetbyname ( Name : pchar) : PNetEnt; cdecl; external;
|
||||
function getnetbyaddr ( Net : Longint; nettype : Longint) : PNetEnt; cdecl; external;
|
||||
procedure setnetent ( Stayopen : Longint); cdecl; external;
|
||||
procedure endnetent; cdecl; external;
|
||||
|
||||
function getservent : PServEnt; cdecl; external;
|
||||
function getservbyname (name : pchar ; protocol : pchar) : PServEnt; cdecl; external;
|
||||
function getservbyport (port : longint; protocol : pchar) : PServEnt; cdecl; external;
|
||||
procedure setservent (StayOpen : longint); cdecl; external;
|
||||
procedure endservent; cdecl; external;
|
||||
|
||||
Function GetDNSError : libcint;
|
||||
|
||||
implementation
|
||||
|
||||
Uses strings;
|
||||
|
||||
Function GetDNSError:libcint;
|
||||
|
||||
begin
|
||||
GetDNSError:=fpGetCErrno;
|
||||
end;
|
||||
|
||||
function HostAddrToStr (Entry : THostAddr) : String;
|
||||
|
||||
Var Dummy : String[4];
|
||||
I : Longint;
|
||||
|
||||
begin
|
||||
HostAddrToStr:='';
|
||||
For I:=1 to 4 do
|
||||
begin
|
||||
Str(Entry[I],Dummy);
|
||||
HostAddrToStr:=HostAddrToStr+Dummy;
|
||||
If I<4 Then HostAddrToStr:=HostAddrToStr+'.';
|
||||
end;
|
||||
end;
|
||||
|
||||
function StrToHostAddr(IP : String) : THostAddr ;
|
||||
|
||||
Var Dummy : String[4];
|
||||
I : Longint;
|
||||
J : Integer;
|
||||
Temp : THostAddr;
|
||||
|
||||
begin
|
||||
StrToHostAddr:=NoAddress;
|
||||
For I:=1 to 4 do
|
||||
begin
|
||||
If I<4 Then
|
||||
begin
|
||||
J:=Pos('.',IP);
|
||||
If J=0 then exit;
|
||||
Dummy:=Copy(IP,1,J-1);
|
||||
Delete (IP,1,J);
|
||||
end
|
||||
else
|
||||
Dummy:=IP;
|
||||
Val (Dummy,Temp[I],J);
|
||||
If J<>0 then Exit;
|
||||
end;
|
||||
StrToHostAddr:=Temp;
|
||||
end;
|
||||
|
||||
function NetAddrToStr (Entry : longint) : String;
|
||||
|
||||
Var Dummy : String[4];
|
||||
I : Longint;
|
||||
|
||||
begin
|
||||
NetAddrToStr:='';
|
||||
For I:=4 downto 1 do
|
||||
begin
|
||||
Str(THostAddr(Entry)[I],Dummy);
|
||||
NetAddrToStr:=NetAddrToStr+Dummy;
|
||||
If I>1 Then NetAddrToStr:=NetAddrToStr+'.';
|
||||
end;
|
||||
end;
|
||||
|
||||
function StrToNetAddr(IP : String) : Longint;
|
||||
|
||||
begin
|
||||
StrToNetAddr:=Longint(StrToHostAddr(IP));
|
||||
end;
|
||||
|
||||
|
||||
Constructor THost.NameLookup (HostName : String);
|
||||
|
||||
begin
|
||||
HostName:=HostName+#0;
|
||||
FHostEntry:=GetHostByName(pchar(@HostName[1]));
|
||||
If FHostEntry=Nil then
|
||||
FError:=GetDNSError
|
||||
else
|
||||
begin
|
||||
FAlias:=0;
|
||||
FAddr:=0;
|
||||
Ferror:=0;
|
||||
end;
|
||||
end;
|
||||
|
||||
Constructor THost.AddressLookup (Const Address: THostAddr);
|
||||
|
||||
begin
|
||||
FHostEntry:=GetHostByAddr(PHostAddr(@Address),SizeOf(Address),AF_INET);
|
||||
If FHostEntry=Nil then
|
||||
FError:=GetDNSError
|
||||
else
|
||||
begin
|
||||
FAlias:=0;
|
||||
FAddr:=0;
|
||||
FError:=0;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
Function THost.Name : String;
|
||||
|
||||
begin
|
||||
Name:='';
|
||||
If (FHostEntry=Nil) or (FError<>0) then exit;
|
||||
Name:=StrPas(FHostEntry^.Name);
|
||||
end;
|
||||
|
||||
Function THost.GetAlias (Select : TSelectType) : String;
|
||||
|
||||
begin
|
||||
GetAlias:='';
|
||||
If (FHostEntry=Nil) or (FError<>0) then exit;
|
||||
Case Select of
|
||||
stFirst : FAlias:=0;
|
||||
stnext : If FHostEntry^.Aliases[FAlias]<>Nil then
|
||||
Falias:=Falias+1;
|
||||
stprevious : If FAlias=0 Then Exit else FAlias:=FAlias-1;
|
||||
end;
|
||||
If FHostEntry^.Aliases[FAlias]<>Nil then
|
||||
GetAlias:=StrPas(FHostEntry^.Aliases[FAlias]);
|
||||
end;
|
||||
|
||||
Function THost.GetAddress (Select : TSelectType) : String;
|
||||
|
||||
begin
|
||||
GetAddress:='';
|
||||
If (FHostEntry=Nil) or (FError<>0) then exit;
|
||||
Case Select of
|
||||
stFirst : FAddr:=0;
|
||||
stnext : If FHostEntry^.AddrList[FAddr]<>Nil then
|
||||
FAddr:=FAddr+1;
|
||||
stprevious : If FAddr=0 Then Exit else FAddr:=FAddr-1;
|
||||
end;
|
||||
If FHostEntry^.AddrList[FAddr]<>Nil then
|
||||
GetAddress:=HostAddrToStr(PHostAddr(FHostEntry^.AddrList[FAddr])^);
|
||||
end;
|
||||
|
||||
Function THost.IPstring : String;
|
||||
|
||||
begin
|
||||
IPString:='';
|
||||
If (FHostEntry=Nil) or (FError<>0) then exit;
|
||||
If FHostEntry^.AddrList[0]<>Nil then
|
||||
IPString:=HostAddrToStr(PHostAddr(FHostEntry^.AddrList[0])^);
|
||||
end;
|
||||
|
||||
Function THost.IPaddress : THostAddr;
|
||||
|
||||
begin
|
||||
IPAddress:=NoAddress;
|
||||
If (FHostEntry=Nil) or (FError<>0) then exit;
|
||||
IPAddress:=PHostAddr(FHostEntry^.AddrList[0])^;
|
||||
end;
|
||||
|
||||
Destructor THost.Done;
|
||||
|
||||
begin
|
||||
end;
|
||||
|
||||
Function THost.LastError : Longint;
|
||||
|
||||
begin
|
||||
LastError:=FError;
|
||||
end;
|
||||
|
||||
Constructor TNet.NameLookup (NetName : String);
|
||||
|
||||
begin
|
||||
NetName:=NetName+#0;
|
||||
FNetEntry:=GetNetByName(pchar(@NetName[1]));
|
||||
If FNetEntry=Nil then
|
||||
FError:=GetDNSError
|
||||
else
|
||||
begin
|
||||
FAlias:=0;
|
||||
Ferror:=0;
|
||||
end;
|
||||
end;
|
||||
|
||||
Constructor TNet.AddressLookup (Const Address: Longint);
|
||||
|
||||
begin
|
||||
FNetEntry:=GetNetByAddr(Address,AF_INET);
|
||||
If FNetEntry=Nil then
|
||||
FError:=GetDNSError
|
||||
else
|
||||
begin
|
||||
FAlias:=0;
|
||||
FError:=0;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
Function TNet.Name : String;
|
||||
|
||||
begin
|
||||
Name:='';
|
||||
If (FNetEntry=Nil) or (FError<>0) then exit;
|
||||
Name:=StrPas(FNetEntry^.Name);
|
||||
end;
|
||||
|
||||
Function TNet.GetAlias (Select : TSelectType) : String;
|
||||
|
||||
begin
|
||||
GetAlias:='';
|
||||
If (FNetEntry=Nil) or (FError<>0) then exit;
|
||||
Case Select of
|
||||
stFirst : FAlias:=0;
|
||||
stnext : If FNetEntry^.Aliases[FAlias]<>Nil then
|
||||
Falias:=Falias+1;
|
||||
stprevious : If FAlias=0 Then Exit else FAlias:=FAlias-1;
|
||||
end;
|
||||
If FNetEntry^.Aliases[FAlias]<>Nil then
|
||||
GetAlias:=StrPas(FNetEntry^.Aliases[FAlias]);
|
||||
end;
|
||||
|
||||
Function TNet.IPstring : String;
|
||||
|
||||
begin
|
||||
IPString:='';
|
||||
If (FNetEntry=Nil) or (FError<>0) then exit;
|
||||
IPString:=NetAddrToStr(FNetEntry^.Net);
|
||||
end;
|
||||
|
||||
Function TNet.IPaddress : Longint;
|
||||
|
||||
begin
|
||||
IPAddress:=0;
|
||||
If (FNetEntry=Nil) or (FError<>0) then exit;
|
||||
IPAddress:=FNetEntry^.Net;
|
||||
end;
|
||||
|
||||
Destructor TNet.Done;
|
||||
|
||||
begin
|
||||
end;
|
||||
|
||||
Function TNet.LastError : Longint;
|
||||
|
||||
begin
|
||||
LastError:=FError;
|
||||
end;
|
||||
|
||||
Constructor TService.NameLookup (ServiceName,Proto : String);
|
||||
|
||||
begin
|
||||
ServiceName:=ServiceName+#0;
|
||||
Proto:=Proto+#0;
|
||||
FServiceEntry:=GetServByName(pchar(@ServiceName[1]),pchar(@Proto[1]));
|
||||
If FServiceEntry=Nil then
|
||||
FError:=GetDNSError
|
||||
else
|
||||
begin
|
||||
FAlias:=0;
|
||||
Ferror:=0;
|
||||
end;
|
||||
end;
|
||||
|
||||
Constructor TService.PortLookup (APort: Longint; Proto : String);
|
||||
|
||||
begin
|
||||
Proto:=proto+#0;
|
||||
FServiceEntry:=GetServByPort(APort,pchar(@proto[1]));
|
||||
If FServiceEntry=Nil then
|
||||
FError:=GetDNSError
|
||||
else
|
||||
begin
|
||||
FAlias:=0;
|
||||
FError:=0;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
Function TService.Name : String;
|
||||
|
||||
begin
|
||||
Name:='';
|
||||
If (FServiceEntry=Nil) or (FError<>0) then exit;
|
||||
Name:=StrPas(FServiceEntry^.Name);
|
||||
end;
|
||||
|
||||
Function TService.GetAlias (Select : TSelectType) : String;
|
||||
|
||||
begin
|
||||
GetAlias:='';
|
||||
If (FServiceEntry=Nil) or (FError<>0) then exit;
|
||||
Case Select of
|
||||
stFirst : FAlias:=0;
|
||||
stnext : If FServiceEntry^.Aliases[FAlias]<>Nil then
|
||||
Falias:=Falias+1;
|
||||
stprevious : If FAlias=0 Then Exit else FAlias:=FAlias-1;
|
||||
end;
|
||||
If FServiceEntry^.Aliases[FAlias]<>Nil then
|
||||
GetAlias:=StrPas(FServiceEntry^.Aliases[FAlias]);
|
||||
end;
|
||||
|
||||
Function TService.Protocol : String;
|
||||
|
||||
begin
|
||||
Protocol:='';
|
||||
If (FServiceEntry=Nil) or (FError<>0) then exit;
|
||||
Protocol:=Strpas(FServiceEntry^.proto);
|
||||
end;
|
||||
|
||||
Function TService.Port : Longint;
|
||||
|
||||
begin
|
||||
Port:=0;
|
||||
If (FServiceEntry=Nil) or (FError<>0) then exit;
|
||||
Port:=FServiceEntry^.Port;
|
||||
end;
|
||||
|
||||
Destructor TService.Done;
|
||||
|
||||
begin
|
||||
end;
|
||||
|
||||
Function TService.LastError : Longint;
|
||||
|
||||
begin
|
||||
LastError:=FError;
|
||||
end;
|
||||
|
||||
Function HostToNet (Host : Longint) : Longint;
|
||||
|
||||
begin
|
||||
{$ifdef FPC_BIG_ENDIAN}
|
||||
hosttonet:=host;
|
||||
{$else}
|
||||
HostToNet:=THostAddr(host)[4];
|
||||
HostToNEt:=HostTONet or ( (THostAddr(host)[3]) shl 8);
|
||||
HostToNEt:=HostToNet or ( (THostAddr(host)[2]) shl 16);
|
||||
HostToNEt:=HostToNet or ( (THostAddr(host)[1]) shl 24);
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
Function NetToHost (Net : Longint) : Longint;
|
||||
|
||||
begin
|
||||
{$ifdef FPC_BIG_ENDIAN}
|
||||
nettohost:=net;
|
||||
{$else}
|
||||
NetToHost:=THostAddr(Net)[4];
|
||||
NetToHost:=NetToHost or ( (THostAddr(Net)[3]) shl 8);
|
||||
NetToHost:=NetToHost or ( (THostAddr(Net)[2]) shl 16);
|
||||
NetToHost:=NetToHost or ( (THostAddr(Net)[1]) shl 24);
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
Function ShortHostToNet (Host : Word) : Word;
|
||||
|
||||
begin
|
||||
{$IFDEF FPC_BIG_ENDIAN}
|
||||
shorthosttonet:=host;
|
||||
{$else}
|
||||
ShortHostToNet:=lo(host)*256+Hi(Host);
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
Function ShortNetToHost (Net : Word) : Word;
|
||||
|
||||
begin
|
||||
{$IFDEF FPC_BIG_ENDIAN}
|
||||
shortnettohost:=net;
|
||||
{$else}
|
||||
ShortNetToHost:=lo(Net)*256+Hi(Net);
|
||||
{$endif}
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
||||
$Log$
|
||||
Revision 1.6 2004-11-01 21:01:29 marco
|
||||
* more endian fixes
|
||||
|
||||
Revision 1.5 2004/04/13 09:04:55 marco
|
||||
* small typo fix from Mischi
|
||||
|
||||
Revision 1.4 2004/04/10 15:37:57 marco
|
||||
* bug/endianfix to hosttonet nettohost
|
||||
|
||||
Revision 1.3 2003/12/10 12:16:14 marco
|
||||
* now uses initc
|
||||
|
||||
Revision 1.2 2002/09/07 15:42:52 peter
|
||||
* old logs removed and tabs fixed
|
||||
|
||||
Revision 1.1 2002/01/29 17:54:53 peter
|
||||
* splitted to base and extra
|
||||
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
program pfinger;
|
||||
|
||||
uses sockets,errors,inet;
|
||||
|
||||
Var Addr : TInetSockAddr;
|
||||
S : Longint;
|
||||
Sin,Sout : Text;
|
||||
Line : string;
|
||||
hostname,username : string;
|
||||
host : THost;
|
||||
|
||||
begin
|
||||
if paramcount<>1 then
|
||||
begin
|
||||
writeln ('Usage : pfinger username@hostname');
|
||||
end;
|
||||
HostName:=Paramstr(1);
|
||||
If pos('@',HostName)<>0 then
|
||||
begin
|
||||
username:=copy(HostName,1,pos('@',hostname)-1);
|
||||
hostname:=copy(HostName,pos('@',HostName)+1,255);
|
||||
end
|
||||
else
|
||||
username:='';
|
||||
Host.NameLookup(HostName);
|
||||
If Host.LastError<>0 then
|
||||
begin
|
||||
writeln ('Unknown host : ',host.name);
|
||||
halt(1);
|
||||
end;
|
||||
Addr.family:=AF_INET;
|
||||
{ port 78 in network order }
|
||||
Addr.port:=ShortHostToNet(79);
|
||||
{ localhost : 127.0.0.1 in network order }
|
||||
Addr.addr:=HostTonet(Longint(Host.IPAddress));
|
||||
S:=Socket(AF_INET,SOCK_STREAM,0);
|
||||
If Not Connect (S,ADDR,SIN,SOUT) Then
|
||||
begin
|
||||
Writeln ('Couldn''t connect to localhost');
|
||||
Writeln ('Socket error : ',strerror(SocketError));
|
||||
halt(1);
|
||||
end;
|
||||
rewrite (sout);
|
||||
reset(sin);
|
||||
writeln (sout,username);
|
||||
flush(sout);
|
||||
while not eof(sin) do
|
||||
begin
|
||||
readln (Sin,line);
|
||||
writeln (line);
|
||||
end;
|
||||
close (sin);
|
||||
close (sout);
|
||||
end.
|
||||
$Log$
|
||||
Revision 1.2 2002-09-07 15:42:52 peter
|
||||
* old logs removed and tabs fixed
|
||||
|
||||
Revision 1.1 2002/01/29 17:54:53 peter
|
||||
* splitted to base and extra
|
||||
|
||||
}
|
@ -1,256 +0,0 @@
|
||||
program testinet;
|
||||
|
||||
{
|
||||
Program to test the inet unit.
|
||||
(C) 1997,1998 by Michael Van Canneyt
|
||||
}
|
||||
|
||||
uses inet;
|
||||
|
||||
var p : PHostEnt;
|
||||
ph : Phostaddr;
|
||||
pn : PNetEnt;
|
||||
ps : PServEnt;
|
||||
pp : ppchar;
|
||||
host : THost;
|
||||
Net : TNet;
|
||||
service : TService;
|
||||
S : String;
|
||||
TheAddr : THostAddr;
|
||||
|
||||
const
|
||||
{ Lily is my machine. This may not work of you're on a
|
||||
standalone machine. In that case, replace the address by
|
||||
an address known to your machine, or, as a last resort, 127.0.0.1 }
|
||||
|
||||
lily : THostAddr = (134,58,81,164);
|
||||
{lily : THostAddr = (127,0,0,1);}
|
||||
|
||||
begin
|
||||
p:=gethostbyname ('LocalHost');
|
||||
if p=nil then
|
||||
begin
|
||||
Writeln ('GetHostByname : No entry');
|
||||
end
|
||||
else
|
||||
begin
|
||||
Writeln ('Data for localhost : ');
|
||||
with p^ do
|
||||
begin
|
||||
writeln ('Name : ',name);
|
||||
writeln ('Length : ',Addrlen);
|
||||
pp:=aliases;
|
||||
while pp^<>nil do
|
||||
begin
|
||||
writeln ('Alias : ',pp^);
|
||||
inc(longint(pp),4);
|
||||
end;
|
||||
ph:=PHostAddr(addrlist^);
|
||||
writeln ('Addres : ',ph^[1],'.',ph^[2],'.',ph^[3],'.',ph^[4]);
|
||||
end;
|
||||
end;
|
||||
p:=gethostbyaddr (@lily,4,2);
|
||||
if p=nil then
|
||||
begin
|
||||
Writeln ('Gethostbyaddr : No entry');
|
||||
end
|
||||
else
|
||||
begin
|
||||
Writeln ('Data for ',lily[1],'.',lily[2],'.',lily[3],'.',lily[4] );
|
||||
with p^ do
|
||||
begin
|
||||
writeln ('Name : ',name);
|
||||
writeln ('Length : ',Addrlen);
|
||||
pp:=aliases;
|
||||
while pp^<>nil do
|
||||
begin
|
||||
writeln ('Alias : ',pp^);
|
||||
inc(longint(pp),4);
|
||||
end;
|
||||
ph:=PHostAddr(addrlist^);
|
||||
writeln ('Addres : ',ph^[1],'.',ph^[2],'.',ph^[3],'.',ph^[4]);
|
||||
end;
|
||||
end;
|
||||
pn:=GetNetByName ('loopback');
|
||||
if pn=nil then
|
||||
begin
|
||||
writeln ('GetNetByName : No entry');
|
||||
end
|
||||
else
|
||||
begin
|
||||
Writeln ('Data for loopback : ');
|
||||
with pn^ do
|
||||
begin
|
||||
writeln ('Name : ',name);
|
||||
writeln ('Type : ',AddrType);
|
||||
pp:=aliases;
|
||||
while pp^<>nil do
|
||||
begin
|
||||
writeln ('Alias : ',pp^);
|
||||
inc(longint(pp),4);
|
||||
end;
|
||||
ph:=PHostAddr(@net);
|
||||
writeln ('Addres : ',ph^[4],'.',ph^[3],'.',ph^[2],'.',ph^[1]);
|
||||
end;
|
||||
end;
|
||||
pn:=GetNetByAddr ((127 shl 24),2);
|
||||
if pn=nil then
|
||||
begin
|
||||
writeln ('GetNetByAddr : No entry');
|
||||
end
|
||||
else
|
||||
begin
|
||||
Writeln ('Data for 127.0.0.0 : ');
|
||||
with pn^ do
|
||||
begin
|
||||
writeln ('Name : ',name);
|
||||
writeln ('Type : ',AddrType);
|
||||
pp:=aliases;
|
||||
while pp^<>nil do
|
||||
begin
|
||||
writeln ('Alias : ',pp^);
|
||||
inc(longint(pp),4);
|
||||
end;
|
||||
ph:=PHostAddr(@net);
|
||||
writeln ('Addres : ',ph^[4],'.',ph^[3],'.',ph^[2],'.',ph^[1]);
|
||||
end;
|
||||
end;
|
||||
ps:=GetServByName ('telnet','tcp');
|
||||
if ps=nil then
|
||||
begin
|
||||
writeln ('GetServByName : No entry ');
|
||||
end
|
||||
else
|
||||
with ps^ do
|
||||
begin
|
||||
writeln ('Name : ',name);
|
||||
writeln ('Protocol : ',proto);
|
||||
writeln ('Port ',port shr 8);
|
||||
pp:=aliases;
|
||||
while pp^<>nil do
|
||||
begin
|
||||
writeln ('Alias : ',pp^);
|
||||
inc(longint(pp),4);
|
||||
end;
|
||||
end;
|
||||
ps:=GetServByPort (23 shl 8 ,'tcp');
|
||||
if ps=nil then
|
||||
begin
|
||||
writeln ('GetServByPort : No entry ');
|
||||
end
|
||||
else
|
||||
with ps^ do
|
||||
begin
|
||||
writeln ('Name : ',name);
|
||||
writeln ('Protocol : ',proto);
|
||||
writeln ('Port ',port shr 8);
|
||||
pp:=aliases;
|
||||
while pp^<>nil do
|
||||
begin
|
||||
writeln ('Alias : ',pp^);
|
||||
inc(longint(pp),4);
|
||||
end;
|
||||
end;
|
||||
Writeln ('Creating Host Object with namelookup(tflily)');
|
||||
Host.NameLookup ('tflily');
|
||||
If Host.LastError=0 then
|
||||
begin
|
||||
Writeln ('Name : ',host.name);
|
||||
S:=Host.GetAlias (stfirst);
|
||||
While S<>'' do
|
||||
begin
|
||||
Writeln ('Host alias : ',S);
|
||||
S:=Host.GetAlias(stnext);
|
||||
end;
|
||||
S:=Host.GetAddress (stfirst);
|
||||
While S<>'' do
|
||||
begin
|
||||
Writeln ('Host address : ',S);
|
||||
S:=Host.GetAddress(stnext);
|
||||
end;
|
||||
end;
|
||||
Writeln ('Creating Host Object with Addresslookup(''tflily'')');
|
||||
Host.AddressLookup (lily);
|
||||
If Host.LastError=0 then
|
||||
begin
|
||||
Writeln ('Name : ',host.name);
|
||||
Writeln ('IP Address : ',host.IPstring);
|
||||
S:=Host.GetAlias (stfirst);
|
||||
While S<>'' do
|
||||
begin
|
||||
Writeln ('Host alias : ',S);
|
||||
S:=Host.GetAlias(stnext);
|
||||
end;
|
||||
S:=Host.GetAddress (stfirst);
|
||||
While S<>'' do
|
||||
begin
|
||||
Writeln ('Host address : ',S);
|
||||
S:=Host.GetAddress(stnext);
|
||||
end;
|
||||
end;
|
||||
Writeln ('Creating net Object with namelookup(''loopback'')');
|
||||
net.NameLookup ('loopback');
|
||||
If net.LastError=0 then
|
||||
begin
|
||||
Writeln ('Name : ',net.name);
|
||||
Writeln ('IP address : ',net.IPstring);
|
||||
S:=net.GetAlias (stfirst);
|
||||
While S<>'' do
|
||||
begin
|
||||
Writeln ('net alias : ',S);
|
||||
S:=net.GetAlias(stnext);
|
||||
end;
|
||||
end;
|
||||
Writeln ('Creating net Object with Addrlookup((127 shl 24))');
|
||||
net.AddressLookup ((127 shl 24));
|
||||
If net.LastError=0 then
|
||||
begin
|
||||
Writeln ('Name : ',net.name);
|
||||
Writeln ('IP address : ',net.IPstring);
|
||||
S:=net.GetAlias (stfirst);
|
||||
While S<>'' do
|
||||
begin
|
||||
Writeln ('net alias : ',S);
|
||||
S:=net.GetAlias(stnext);
|
||||
end;
|
||||
end;
|
||||
S:='134.58.81.164';
|
||||
TheAddr:=StrToHostAddr (S);
|
||||
Writeln (S,' = ',TheAddr[1],'.',theaddr[2],'.',theaddr[3],'.',theaddr[4]);
|
||||
Writeln ('Creating Service Object with Namelookup(''telnet'',''tcp'')');
|
||||
Service.Namelookup('telnet','tcp');
|
||||
If Service.LastError=0 then
|
||||
begin
|
||||
Writeln ('Name : ',Service.name);
|
||||
Writeln ('Protocol : ',service.protocol);
|
||||
Writeln ('Port : ',ShortNetToHost(service.port));
|
||||
S:=service.GetAlias (stfirst);
|
||||
While S<>'' do
|
||||
begin
|
||||
Writeln ('service alias : ',S);
|
||||
S:=service.GetAlias(stnext);
|
||||
end;
|
||||
end;
|
||||
Writeln ('Creating Service Object with Portlookup(23 shl 8 ,''tcp'')');
|
||||
Service.Portlookup(23 shl 8,'tcp');
|
||||
If Service.LastError=0 then
|
||||
begin
|
||||
Writeln ('Name : ',Service.name);
|
||||
Writeln ('Protocol : ',service.protocol);
|
||||
Writeln ('Port : ',ShortNetToHost(service.port));
|
||||
S:=service.GetAlias (stfirst);
|
||||
While S<>'' do
|
||||
begin
|
||||
Writeln ('service alias : ',S);
|
||||
S:=service.GetAlias(stnext);
|
||||
end;
|
||||
end;
|
||||
|
||||
end. $Log$
|
||||
end. Revision 1.2 2002-09-07 15:42:52 peter
|
||||
end. * old logs removed and tabs fixed
|
||||
end.
|
||||
end. Revision 1.1 2002/01/29 17:54:53 peter
|
||||
end. * splitted to base and extra
|
||||
end.
|
||||
}
|
Loading…
Reference in New Issue
Block a user