Both getaddrinfo() and getnameinfo() have to be preceeded with a call
to BIO_sock_init().
Also, make sure to give gai_strerror() the actual error code.
Reviewed-by: Stephen Henson <steve@openssl.org>
static int addr_strings(const BIO_ADDR *ap, int numeric,
char **hostname, char **service)
{
static int addr_strings(const BIO_ADDR *ap, int numeric,
char **hostname, char **service)
{
+ if (BIO_sock_init() != 1)
+ return 0;
+
if (1) {
#ifdef AI_PASSIVE
int ret = 0;
if (1) {
#ifdef AI_PASSIVE
int ret = 0;
+ if (BIO_sock_init() != 1)
+ return 0;
+
#ifdef AI_PASSIVE
struct addrinfo hints;
#ifdef AI_PASSIVE
struct addrinfo hints;
/* Note that |res| SHOULD be a 'struct addrinfo **' thanks to
* macro magic in bio_lcl.h
*/
/* Note that |res| SHOULD be a 'struct addrinfo **' thanks to
* macro magic in bio_lcl.h
*/
- switch (getaddrinfo(host, service, &hints, res)) {
+ switch ((gai_ret = getaddrinfo(host, service, &hints, res))) {
# ifdef EAI_SYSTEM
case EAI_SYSTEM:
SYSerr(SYS_F_GETADDRINFO, get_last_socket_error());
# ifdef EAI_SYSTEM
case EAI_SYSTEM:
SYSerr(SYS_F_GETADDRINFO, get_last_socket_error());
break;
default:
BIOerr(BIO_F_BIO_LOOKUP, ERR_R_SYS_LIB);
break;
default:
BIOerr(BIO_F_BIO_LOOKUP, ERR_R_SYS_LIB);
- ERR_add_error_data(1, gai_strerror(ret));
+ ERR_add_error_data(1, gai_strerror(gai_ret));