<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Il 16/01/23 22:23, Mattias Gaertner via fpc-pascal ha scritto:<br>
</p>
<blockquote type="cite"
cite="mid:20230116222331.3771d330@limapholos">
<pre class="moz-quote-pre" wrap="">On Mon, 16 Jan 2023 22:12:52 +0100
Mattias Gaertner via fpc-pascal <a class="moz-txt-link-rfc2396E" href="mailto:fpc-pascal@lists.freepascal.org"><fpc-pascal@lists.freepascal.org></a> wrote:
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">On Mon, 16 Jan 2023 19:50:34 +0100
Giuliano Colla via fpc-pascal <a class="moz-txt-link-rfc2396E" href="mailto:fpc-pascal@lists.freepascal.org"><fpc-pascal@lists.freepascal.org></a> wrote:
</pre>
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">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:
</pre>
</blockquote>
</blockquote>
<pre class="moz-quote-pre" wrap="">
Btw, gethostbyname is obsolete. Applications should use getaddrinfo,
getnameinfo, and gai_strerror instead.
</pre>
</blockquote>
I know that it's obsolete. It's not reentrant and it is ugly. But
I'm pretty sure that it will survive for a long time to come,
because it provides you a check on a name *before* creating a
socket. If the name is wrong (a typo, e.g.) you don't need to get
rid of an useless socket, as it would happen with getaddrinfo and
getnameinfo. <br>
<blockquote type="cite"
cite="mid:20230116222331.3771d330@limapholos">
<pre class="moz-quote-pre" wrap="">
</pre>
<blockquote type="cite">
<blockquote type="cite">
<blockquote type="cite">
<pre class="moz-quote-pre" wrap="">[...]</pre>
</blockquote>
</blockquote>
</blockquote>
</blockquote>
<br>
<blockquote type="cite"
cite="mid:20230116222331.3771d330@limapholos">
<pre class="moz-quote-pre" wrap="">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]);
</pre>
</blockquote>
<p><br>
</p>
<p>IT WORKS!</p>
<p>But for me it's a bit obscure why in Delphi mode the right syntax
is</p>
<pre>HostEnt.h_addr^</pre>
<p>and in objfpc</p>
<pre>HostEnt.h^.h_addr[0]</pre>
<p>I can understand the first caret (Delphi puts it there
implicitly) but not the rest.</p>
<p>However thanks a lot. If gethostbyname can be a little obsolete,
Delphi mode for me is much more obsolete and deprecated!<br>
</p>
Giuliano<br>
</body>
</html>