Home Explore Blog CI



postgresql

38th chunk of `doc/src/sgml/libpq.sgml`
5571724f6836d17efec5a36bcb98d96aee252db92bceb6b40000000100000fa0
 specified both <literal>host</literal> and
       <literal>hostaddr</literal>, then <xref linkend="libpq-PQhost"/> will
       return the <literal>host</literal> information.  If only
       <literal>hostaddr</literal> was specified, then that is returned.
       If multiple hosts were specified in the connection parameters,
       <xref linkend="libpq-PQhost"/> returns the host actually connected to.
      </para>

      <para>
       <xref linkend="libpq-PQhost"/> returns <symbol>NULL</symbol> if the
       <parameter>conn</parameter> argument is <symbol>NULL</symbol>.
       Otherwise, if there is an error producing the host information (perhaps
       if the connection has not been fully established or there was an
       error), it returns an empty string.
      </para>

      <para>
       If multiple hosts were specified in the connection parameters, it is
       not possible to rely on the result of <xref linkend="libpq-PQhost"/> until
       the connection is established.  The status of the connection can be
       checked using the function <xref linkend="libpq-PQstatus"/>.
      </para>
     </listitem>
    </varlistentry>


    <varlistentry id="libpq-PQhostaddr">
     <term><function>PQhostaddr</function><indexterm><primary>PQhostaddr</primary></indexterm></term>

     <listitem>
      <para>
       Returns the server IP address of the active connection.
       This can be the address that a host name resolved to,
       or an IP address provided through the <literal>hostaddr</literal>
       parameter.
<synopsis>
char *PQhostaddr(const PGconn *conn);
</synopsis>
      </para>

      <para>
       <xref linkend="libpq-PQhostaddr"/> returns <symbol>NULL</symbol> if the
       <parameter>conn</parameter> argument is <symbol>NULL</symbol>.
       Otherwise, if there is an error producing the host information
       (perhaps if the connection has not been fully established or
       there was an error), it returns an empty string.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry id="libpq-PQport">
     <term><function>PQport</function><indexterm><primary>PQport</primary></indexterm></term>

     <listitem>
      <para>
       Returns the port of the active connection.

<synopsis>
char *PQport(const PGconn *conn);
</synopsis>
      </para>

      <para>
       If multiple ports were specified in the connection parameters,
       <xref linkend="libpq-PQport"/> returns the port actually connected to.
      </para>

      <para>
       <xref linkend="libpq-PQport"/> returns <symbol>NULL</symbol> if the
       <parameter>conn</parameter> argument is <symbol>NULL</symbol>.
       Otherwise, if there is an error producing the port information (perhaps
       if the connection has not been fully established or there was an
       error), it returns an empty string.
      </para>

      <para>
       If multiple ports were specified in the connection parameters, it is
       not possible to rely on the result of <xref linkend="libpq-PQport"/> until
       the connection is established.  The status of the connection can be
       checked using the function <xref linkend="libpq-PQstatus"/>.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry id="libpq-PQservice">
     <term><function>PQservice</function><indexterm><primary>PQservice</primary></indexterm></term>

     <listitem>
      <para>
       Returns the service of the active connection.

<synopsis>
char *PQservice(const PGconn *conn);
</synopsis>
      </para>

      <para>
       <xref linkend="libpq-PQservice"/> returns <symbol>NULL</symbol> if the
       <parameter>conn</parameter> argument is <symbol>NULL</symbol>.
       Otherwise, if there was no service provided, it returns an empty string.
      </para>
     </listitem>
    </varlistentry>

    <varlistentry id="libpq-PQtty">
     <term><function>PQtty</function><indexterm><primary>PQtty</primary></indexterm></term>

     <listitem>
      <para>
       This function no longer

Title: Connection Status Functions: Retrieving Host Address, Port, and Service
Summary
This section describes the functions PQhostaddr, PQport, and PQservice, which are used to retrieve the server IP address, port, and service name of the active connection, respectively. The functions return NULL if the PGconn argument is NULL and an empty string if there is an error producing the requested information. It is not possible to rely on the result of PQhost and PQport until the connection is established when multiple hosts or ports are specified.