X-Git-Url: https://git.openssl.org/?a=blobdiff_plain;f=crypto%2Fbio%2Fb_sock.c;h=86f38172fba682f8b46b8b477bf0358f0a03add9;hb=0bf23d9b2055223c6e7a1398d2243a65dfa4c30d;hp=701a04bdd9eb4cd934040768efb9fb865f823222;hpb=e24e40657f7318248356699e8ec99cb746450708;p=openssl.git diff --git a/crypto/bio/b_sock.c b/crypto/bio/b_sock.c index 701a04bdd9..86f38172fb 100644 --- a/crypto/bio/b_sock.c +++ b/crypto/bio/b_sock.c @@ -56,7 +56,7 @@ * [including the GNU Public Licence.] */ -#ifndef NO_SOCK +#ifndef OPENSSL_NO_SOCK #include #include @@ -65,24 +65,25 @@ #include "cryptlib.h" #include -#ifdef WIN16 +#ifdef OPENSSL_SYS_WIN16 #define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ #else #define SOCKET_PROTOCOL IPPROTO_TCP #endif #ifdef SO_MAXCONN -#define MAX_LISTEN SOMAXCONN -#elif defined(SO_MAXCONN) #define MAX_LISTEN SO_MAXCONN +#elif defined(SOMAXCONN) +#define MAX_LISTEN SOMAXCONN #else #define MAX_LISTEN 32 #endif -#ifdef WINDOWS +#ifdef OPENSSL_SYS_WINDOWS static int wsa_init_done=0; #endif +#if 0 static unsigned long BIO_ghbn_hits=0L; static unsigned long BIO_ghbn_miss=0L; @@ -93,10 +94,13 @@ static struct ghbn_cache_st struct hostent *ent; unsigned long order; } ghbn_cache[GHBN_NUM]; +#endif static int get_ip(const char *str,unsigned char *ip); +#if 0 static void ghbn_free(struct hostent *a); static struct hostent *ghbn_dup(struct hostent *a); +#endif int BIO_get_host_ip(const char *str, unsigned char *ip) { int i; @@ -228,6 +232,7 @@ int BIO_sock_error(int sock) return(j); } +#if 0 long BIO_ghbn_ctrl(int cmd, int iarg, char *parg) { int i; @@ -265,7 +270,9 @@ long BIO_ghbn_ctrl(int cmd, int iarg, char *parg) } return(1); } +#endif +#if 0 static struct hostent *ghbn_dup(struct hostent *a) { struct hostent *ret; @@ -343,20 +350,27 @@ static void ghbn_free(struct hostent *a) OPENSSL_free(a); } +#endif + struct hostent *BIO_gethostbyname(const char *name) { +#if 1 + /* Caching gethostbyname() results forever is wrong, + * so we have to let the true gethostbyname() worry about this */ + return gethostbyname(name); +#else struct hostent *ret; int i,lowi=0,j; unsigned long low= (unsigned long)-1; -/* return(gethostbyname(name)); */ -#if 0 /* It doesn't make sense to use locking here: The function interface - * is not thread-safe, because threads can never be sure when - * some other thread destroys the data they were given a pointer to. - */ +# if 0 + /* It doesn't make sense to use locking here: The function interface + * is not thread-safe, because threads can never be sure when + * some other thread destroys the data they were given a pointer to. + */ CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); -#endif +# endif j=strlen(name); if (j < 128) { @@ -384,20 +398,21 @@ struct hostent *BIO_gethostbyname(const char *name) * parameter is 'char *', instead of 'const char *' */ ret=gethostbyname( -#ifndef CONST_STRICT +# ifndef CONST_STRICT (char *) -#endif +# endif name); if (ret == NULL) goto end; if (j > 128) /* too big to cache */ { -#if 0 /* If we were trying to make this function thread-safe (which - * is bound to fail), we'd have to give up in this case - * (or allocate more memory). */ +# if 0 + /* If we were trying to make this function thread-safe (which + * is bound to fail), we'd have to give up in this case + * (or allocate more memory). */ ret = NULL; -#endif +# endif goto end; } @@ -421,15 +436,17 @@ struct hostent *BIO_gethostbyname(const char *name) ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits; } end: -#if 0 +# if 0 CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); -#endif +# endif return(ret); +#endif } + int BIO_sock_init(void) { -#ifdef WINDOWS +#ifdef OPENSSL_SYS_WINDOWS static struct WSAData wsa_state; if (!wsa_init_done) @@ -449,29 +466,41 @@ int BIO_sock_init(void) return(-1); } } -#endif /* WINDOWS */ +#endif /* OPENSSL_SYS_WINDOWS */ +#ifdef WATT32 + extern int _watt_do_exit; + _watt_do_exit = 0; /* don't make sock_init() call exit() */ + if (sock_init()) + return (-1); +#endif return(1); } void BIO_sock_cleanup(void) { -#ifdef WINDOWS +#ifdef OPENSSL_SYS_WINDOWS if (wsa_init_done) { wsa_init_done=0; +#ifndef OPENSSL_SYS_WINCE WSACancelBlockingCall(); +#endif WSACleanup(); } #endif } -#if !defined(VMS) || __VMS_VER >= 70000000 +#if !defined(OPENSSL_SYS_VMS) || __VMS_VER >= 70000000 int BIO_socket_ioctl(int fd, long type, unsigned long *arg) { int i; +#ifdef __DJGPP__ + i=ioctlsocket(fd,type,(char *)arg); +#else i=ioctlsocket(fd,type,arg); +#endif /* __DJGPP__ */ if (i < 0) SYSerr(SYS_F_IOCTLSOCKET,get_last_socket_error()); return(i); @@ -494,16 +523,16 @@ static int get_ip(const char *str, unsigned char ip[4]) { ok=1; tmp[num]=tmp[num]*10+c-'0'; - if (tmp[num] > 255) return(-1); + if (tmp[num] > 255) return(0); } else if (c == '.') { if (!ok) return(-1); - if (num == 3) break; + if (num == 3) return(0); num++; ok=0; } - else if ((num == 3) && ok) + else if (c == '\0' && (num == 3) && ok) break; else return(0);