提交 d636aa71 编写于 作者: D Dr. Stephen Henson

PR: 2047

Submitted by: David Lee <live4thee@gmail.com>, steve@openssl.org
Approved by: steve@openssl.org

Fix for IPv6 handling in BIO_get_accept_socket().
上级 1d42dbaf
...@@ -588,7 +588,13 @@ static int get_ip(const char *str, unsigned char ip[4]) ...@@ -588,7 +588,13 @@ static int get_ip(const char *str, unsigned char ip[4])
int BIO_get_accept_socket(char *host, int bind_mode) int BIO_get_accept_socket(char *host, int bind_mode)
{ {
int ret=0; int ret=0;
#if OPENSSL_USE_IPV6
# define ossl_sock_family(s) s.ss_family
struct sockaddr_storage server,client;
#else
# define ossl_sock_family(s) s.sa_family
struct sockaddr server,client; struct sockaddr server,client;
#endif
struct sockaddr_in *sa_in; struct sockaddr_in *sa_in;
int s=INVALID_SOCKET,cs; int s=INVALID_SOCKET,cs;
unsigned char ip[4]; unsigned char ip[4];
...@@ -660,7 +666,11 @@ int BIO_get_accept_socket(char *host, int bind_mode) ...@@ -660,7 +666,11 @@ int BIO_get_accept_socket(char *host, int bind_mode)
} }
if ((*p_getaddrinfo.f)(h,p,&hint,&res)) break; if ((*p_getaddrinfo.f)(h,p,&hint,&res)) break;
#if OPENSSL_USE_IPV6
memcpy(&server, res->ai_addr, res->ai_addrlen);
#else
server = *res->ai_addr; server = *res->ai_addr;
#endif
(*p_freeaddrinfo.f)(res); (*p_freeaddrinfo.f)(res);
goto again; goto again;
} while (0); } while (0);
...@@ -687,7 +697,7 @@ int BIO_get_accept_socket(char *host, int bind_mode) ...@@ -687,7 +697,7 @@ int BIO_get_accept_socket(char *host, int bind_mode)
} }
again: again:
s=socket(server.sa_family,SOCK_STREAM,SOCKET_PROTOCOL); s=socket(ossl_sock_family(server),SOCK_STREAM,SOCKET_PROTOCOL);
if (s == INVALID_SOCKET) if (s == INVALID_SOCKET)
{ {
SYSerr(SYS_F_SOCKET,get_last_socket_error()); SYSerr(SYS_F_SOCKET,get_last_socket_error());
...@@ -705,7 +715,7 @@ again: ...@@ -705,7 +715,7 @@ again:
bind_mode=BIO_BIND_NORMAL; bind_mode=BIO_BIND_NORMAL;
} }
#endif #endif
if (bind(s,&server,sizeof(server)) == -1) if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1)
{ {
#ifdef SO_REUSEADDR #ifdef SO_REUSEADDR
err_num=get_last_socket_error(); err_num=get_last_socket_error();
...@@ -716,7 +726,7 @@ again: ...@@ -716,7 +726,7 @@ again:
if (h == NULL || strcmp(h,"*") == 0) if (h == NULL || strcmp(h,"*") == 0)
{ {
#if OPENSSL_USE_IPV6 #if OPENSSL_USE_IPV6
if (client.sa_family == AF_INET6) if (ossl_sock_family(client) == AF_INET6)
{ {
struct sockaddr_in6 *sin6 = struct sockaddr_in6 *sin6 =
(struct sockaddr_in6 *)&client; (struct sockaddr_in6 *)&client;
...@@ -725,7 +735,7 @@ again: ...@@ -725,7 +735,7 @@ again:
} }
else else
#endif #endif
if (client.sa_family == AF_INET) if (ossl_sock_family(client) == AF_INET)
{ {
struct sockaddr_in *sin4 = struct sockaddr_in *sin4 =
(struct sockaddr_in *)&client; (struct sockaddr_in *)&client;
...@@ -733,7 +743,7 @@ again: ...@@ -733,7 +743,7 @@ again:
} }
else goto err; else goto err;
} }
cs=socket(client.sa_family,SOCK_STREAM,SOCKET_PROTOCOL); cs=socket(ossl_sock_family(client),SOCK_STREAM,SOCKET_PROTOCOL);
if (cs != INVALID_SOCKET) if (cs != INVALID_SOCKET)
{ {
int ii; int ii;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册