X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fbio%2Fb_sock.c;h=57aec21f7f5f510b78019e7d7e284ab3b35dce2f;hp=0eee25a0bc9b44742ff1fb12ccaf8879ab47065f;hb=d636aa7109aceeb870df83c4978b271824617530;hpb=eef0c1f34c7b7d6a38e02f3294eb509aef081749 diff --git a/crypto/bio/b_sock.c b/crypto/bio/b_sock.c index 0eee25a0bc..57aec21f7f 100644 --- a/crypto/bio/b_sock.c +++ b/crypto/bio/b_sock.c @@ -88,11 +88,6 @@ NETDB_DEFINE_CONTEXT static int wsa_init_done=0; #endif -#if defined(OPENSSL_SYS_BEOS_BONE) -/* BONE's IP6 support is incomplete */ -#undef AF_INET6 -#endif - #if 0 static unsigned long BIO_ghbn_hits=0L; static unsigned long BIO_ghbn_miss=0L; @@ -593,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 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; +#endif struct sockaddr_in *sa_in; int s=INVALID_SOCKET,cs; unsigned char ip[4]; @@ -654,7 +655,7 @@ int BIO_get_accept_socket(char *host, int bind_mode) if (strchr(h,':')) { if (h[1]=='\0') h=NULL; -#ifdef AF_INET6 +#if OPENSSL_USE_IPV6 hint.ai_family = AF_INET6; #else h=NULL; @@ -665,7 +666,11 @@ int BIO_get_accept_socket(char *host, int bind_mode) } 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; +#endif (*p_freeaddrinfo.f)(res); goto again; } while (0); @@ -692,7 +697,7 @@ int BIO_get_accept_socket(char *host, int bind_mode) } again: - s=socket(server.sa_family,SOCK_STREAM,SOCKET_PROTOCOL); + s=socket(ossl_sock_family(server),SOCK_STREAM,SOCKET_PROTOCOL); if (s == INVALID_SOCKET) { SYSerr(SYS_F_SOCKET,get_last_socket_error()); @@ -710,7 +715,7 @@ again: bind_mode=BIO_BIND_NORMAL; } #endif - if (bind(s,&server,sizeof(server)) == -1) + if (bind(s,(struct sockaddr *)&server,sizeof(server)) == -1) { #ifdef SO_REUSEADDR err_num=get_last_socket_error(); @@ -720,8 +725,8 @@ again: client = server; if (h == NULL || strcmp(h,"*") == 0) { -#ifdef AF_INET6 - if (client.sa_family == AF_INET6) +#if OPENSSL_USE_IPV6 + if (ossl_sock_family(client) == AF_INET6) { struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)&client; @@ -730,15 +735,15 @@ again: } else #endif - if (client.sa_family == AF_INET) + if (ossl_sock_family(client) == AF_INET) { - struct sockaddr_in *sin6 = + struct sockaddr_in *sin4 = (struct sockaddr_in *)&client; - sin6->sin_addr.s_addr=htonl(0x7F000001); + sin4->sin_addr.s_addr=htonl(0x7F000001); } 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) { int ii; @@ -808,18 +813,18 @@ int BIO_accept(int sock, char **addr) if (addr == NULL) goto end; #ifdef EAI_FAMILY -# if defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_BEOS_BONE) || defined(OPENSSL_SYS_MSDOS) -# define SOCKLEN_T size_t -# else -# define SOCKLEN_T socklen_t -#endif do { char h[NI_MAXHOST],s[NI_MAXSERV]; size_t nl; static union { void *p; - int (*f)(const struct sockaddr *,SOCKLEN_T, + int (*f)(const struct sockaddr *,size_t/*socklen_t*/, char *,size_t,char *,size_t,int); } p_getnameinfo = {NULL}; + /* 2nd argument to getnameinfo is specified to + * be socklen_t. Unfortunately there is a number + * of environments where socklen_t is not defined. + * As it's passed by value, it's safe to pass it + * as size_t... */ if (p_getnameinfo.p==NULL) {