eraddr,
            sizeof(serveraddr)) == -1) {
    close(sock);
    return NULL;
}</code></pre>

<p>OpenSSL provides portable helper functions to do these tasks which also integrate into the OpenSSL error system to log error data, e.g.</p>

<pre><code>int sock = -1;
BIO_ADDRINFO *res;
const BIO_ADDRINFO *ai = NULL;

/*
 * Lookup IP address info for the server.
 */
if (!BIO_lookup_ex(hostname, port, BIO_LOOKUP_CLIENT, family, SOCK_STREAM, 0,
                   &amp;res))
    return NULL;

/*
 * Loop throug