X-Git-Url: https://git.openssl.org/gitweb/?p=openssl.git;a=blobdiff_plain;f=crypto%2Fbio%2Fb_sock.c;h=eece85bb51f0491ed3f898f23d566fbb3f8eb1c3;hp=567ee4824d7b845497b06eb3ef024b93e20854d9;hb=59d9bb591c950062ef3721f6b58fddbaae910f2a;hpb=0d4fb8439092ff8253af72ac6bc193e77ebbcf2f diff --git a/crypto/bio/b_sock.c b/crypto/bio/b_sock.c index 567ee4824d..eece85bb51 100644 --- a/crypto/bio/b_sock.c +++ b/crypto/bio/b_sock.c @@ -64,7 +64,6 @@ NETDB_DEFINE_CONTEXT #endif #ifndef OPENSSL_NO_SOCK -# include # define SOCKET_PROTOCOL IPPROTO_TCP # ifdef SO_MAXCONN # define MAX_LISTEN SO_MAXCONN @@ -77,17 +76,6 @@ NETDB_DEFINE_CONTEXT static int wsa_init_done = 0; # endif -/* - * WSAAPI specifier is required to make indirect calls to run-time - * linked WinSock 2 functions used in this module, to be specific - * [get|free]addrinfo and getnameinfo. This is because WinSock uses - * uses non-C calling convention, __stdcall vs. __cdecl, on x86 - * Windows. On non-WinSock platforms WSAAPI needs to be void. - */ -# ifndef WSAAPI -# define WSAAPI -# endif - # if OPENSSL_API_COMPAT < 0x10100000L int BIO_get_host_ip(const char *str, unsigned char *ip) { @@ -391,8 +379,40 @@ int BIO_socket_nbio(int s, int mode) l = mode; # ifdef FIONBIO + l = mode; + ret = BIO_socket_ioctl(s, FIONBIO, &l); +# elif defined(F_GETFL) && defined(F_SETFL) && (defined(O_NONBLOCK) || defined(FNDELAY)) + /* make sure this call always pushes an error level; BIO_socket_ioctl() does so, so we do too. */ + + l = fcntl(s, F_GETFL, 0); + if (l == -1) { + SYSerr(SYS_F_FCNTL, get_last_rtl_error()); + ret = -1; + } else { +# if defined(O_NONBLOCK) + l &= ~O_NONBLOCK; +# else + l &= ~FNDELAY; /* BSD4.x */ +# endif + if (mode) { +# if defined(O_NONBLOCK) + l |= O_NONBLOCK; +# else + l |= FNDELAY; /* BSD4.x */ +# endif + } + ret = fcntl(s, F_SETFL, l); + + if (ret < 0) { + SYSerr(SYS_F_FCNTL, get_last_rtl_error()); + } + } +# else + /* make sure this call always pushes an error level; BIO_socket_ioctl() does so, so we do too. */ + BIOerr(BIO_F_BIO_SOCKET_NBIO, ERR_R_PASSED_INVALID_ARGUMENT); # endif + return (ret == 0); } @@ -412,7 +432,7 @@ int BIO_sock_info(int sock, BIOerr(BIO_F_BIO_SOCK_INFO, BIO_R_GETSOCKNAME_ERROR); return 0; } - if (addr_len > sizeof(*info->addr)) { + if ((size_t)addr_len > sizeof(*info->addr)) { BIOerr(BIO_F_BIO_SOCK_INFO, BIO_R_GETSOCKNAME_TRUNCATED_ADDRESS); return 0; }