On Mon, 16 Jan 2023, Giuliano Colla via fpc-pascal 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:
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/
In order to recover h_addr I have a line which works perfectly in Delphi mode
(inherited from an old Kylix app):
Addr := Pin_addr(HostEnt.h_addr^);
I believed that in objfpc mode it was sufficient to change it in
Addr := @(Pin_addr(HostEnt.h_addr^));
or in
Addr := Pin_addr(@HostEnt.h_addr^);
Should that not simply be
Addr := Pin_addr(HostEnt.h_addr^)
(if addr is a pointer)
or
addr:=Pin_addr(HostEnt.h_addr^)^
if Addr is an in_addr record ?
Michael.
_______________________________________________
fpc-pascal maillist - fpc-pascal@lists.freepascal.org
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal