X-Git-Url: https://git.openssl.org/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fbio%2Fb_sock.c;h=071acda48e83e6fdbbaffa9b4f68c89ed44bc40b;hp=eece85bb51f0491ed3f898f23d566fbb3f8eb1c3;hb=2bd8c8539595b8708e825d306a45ddddc17c915c;hpb=59d9bb591c950062ef3721f6b58fddbaae910f2a diff --git a/crypto/bio/b_sock.c b/crypto/bio/b_sock.c index eece85bb51..071acda48e 100644 --- a/crypto/bio/b_sock.c +++ b/crypto/bio/b_sock.c @@ -72,7 +72,7 @@ NETDB_DEFINE_CONTEXT # else # define MAX_LISTEN 32 # endif -# if defined(OPENSSL_SYS_WINDOWS) || (defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)) +# if defined(OPENSSL_SYS_WINDOWS) static int wsa_init_done = 0; # endif @@ -141,7 +141,7 @@ int BIO_get_port(const char *str, unsigned short *port_ptr) int BIO_sock_error(int sock) { int j = 0, i; - socklen_t size = 0; + socklen_t size = sizeof(j); /* * Note: under Windows the third parameter is of type (char *) whereas @@ -151,7 +151,7 @@ int BIO_sock_error(int sock) */ i = getsockopt(sock, SOL_SOCKET, SO_ERROR, (void *)&j, &size); if (i < 0) - return (1); + return (get_last_socket_error()); else return (j); } @@ -202,38 +202,16 @@ int BIO_sock_init(void) return (-1); # endif -# if defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK) - WORD wVerReq; - WSADATA wsaData; - int err; - - if (!wsa_init_done) { - wsa_init_done = 1; - wVerReq = MAKEWORD(2, 0); - err = WSAStartup(wVerReq, &wsaData); - if (err != 0) { - SYSerr(SYS_F_WSASTARTUP, err); - BIOerr(BIO_F_BIO_SOCK_INIT, BIO_R_WSASTARTUP); - return (-1); - } - } -# endif - return (1); } -void BIO_sock_cleanup(void) +void bio_sock_cleanup_int(void) { # ifdef OPENSSL_SYS_WINDOWS if (wsa_init_done) { wsa_init_done = 0; WSACleanup(); } -# elif defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK) - if (wsa_init_done) { - wsa_init_done = 0; - WSACleanup(); - } # endif } @@ -316,16 +294,10 @@ int BIO_get_accept_socket(char *host, int bind_mode) int BIO_accept(int sock, char **ip_port) { - BIO_ADDR *res = BIO_ADDR_new(); + BIO_ADDR res; int ret = -1; - if (res == NULL) { - BIOerr(BIO_F_BIO_ACCEPT, ERR_R_MALLOC_FAILURE); - return ret; - } - - ret = BIO_accept_ex(sock, res, 0); - + ret = BIO_accept_ex(sock, &res, 0); if (ret == (int)INVALID_SOCKET) { if (BIO_sock_should_retry(ret)) { ret = -2; @@ -337,8 +309,8 @@ int BIO_accept(int sock, char **ip_port) } if (ip_port != NULL) { - char *host = BIO_ADDR_hostname_string(res, 1); - char *port = BIO_ADDR_service_string(res, 1); + char *host = BIO_ADDR_hostname_string(&res, 1); + char *port = BIO_ADDR_service_string(&res, 1); *ip_port = OPENSSL_zalloc(strlen(host) + strlen(port) + 2); strcpy(*ip_port, host); strcat(*ip_port, ":"); @@ -348,7 +320,6 @@ int BIO_accept(int sock, char **ip_port) } end: - BIO_ADDR_free(res); return ret; } # endif