[fpc-pascal] Why in {$mode delphi} it works and in {$mode objfpc} it doesn't?
Mattias Gaertner
nc-gaertnma at netcologne.de
Mon Jan 16 22:23:31 CET 2023
On Mon, 16 Jan 2023 22:12:52 +0100
Mattias Gaertner via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
> On Mon, 16 Jan 2023 19:50:34 +0100
> Giuliano Colla via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>
> > I stumbled into a problem I don't understand.
> >
> > I'm developing a little program for an ftp client. In order to
> > connect to the site I need the site address from the site name, and
> > the libc gethostbyname() provides the required information.
> >
> > gethostbyname returns a PHostEnt type which is declared as:
Btw, gethostbyname is obsolete. Applications should use getaddrinfo,
getnameinfo, and gai_strerror instead.
> > > THostEnt = packed record
> > > h_name: PChar; { Official name of host. }
> > > h_aliases: PPChar; { Alias list. }
> > > h_addrtype: Integer; { Host address type. }
> > > h_length: socklen_t; { Length of address. }
> > > case Byte of
> > > 0: (h_addr_list: PPChar); { List of addresses from name
> > > server. }
> > > 1: (h_addr: PPChar); { Address, for backward
> > > compatibility. }
> > > end;
> > > PHostEnt = ^THostEnt;
> > Actually the chars h_addr points to are /hlength/ bytes to be
> > interpreted as an /in_addr/
> [...]
Ah, I just saw gethostbyname returns a PHostEnt and Addr is Pin_addr.
Then for the first address:
Addr := Pin_addr(HostEnt^.h_addr[0]);
Mattias
More information about the fpc-pascal
mailing list