diff options
author | beck <> | 2002-05-15 02:29:21 +0000 |
---|---|---|
committer | beck <> | 2002-05-15 02:29:21 +0000 |
commit | b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9 (patch) | |
tree | fa27cf82a1250b64ed3bf5f4a18c7354d470bbcc /src/lib/libssl/src/crypto/bio/b_sock.c | |
parent | e471e1ea98d673597b182ea85f29e30c97cd08b5 (diff) | |
download | openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.gz openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.tar.bz2 openbsd-b64270d1e45fe7f3241e4c9b6ce60d5ac89bc2e9.zip |
OpenSSL 0.9.7 stable 2002 05 08 merge
Diffstat (limited to 'src/lib/libssl/src/crypto/bio/b_sock.c')
-rw-r--r-- | src/lib/libssl/src/crypto/bio/b_sock.c | 66 |
1 files changed, 40 insertions, 26 deletions
diff --git a/src/lib/libssl/src/crypto/bio/b_sock.c b/src/lib/libssl/src/crypto/bio/b_sock.c index 62cc3f1a0c..dcaef68ea7 100644 --- a/src/lib/libssl/src/crypto/bio/b_sock.c +++ b/src/lib/libssl/src/crypto/bio/b_sock.c | |||
@@ -56,7 +56,7 @@ | |||
56 | * [including the GNU Public Licence.] | 56 | * [including the GNU Public Licence.] |
57 | */ | 57 | */ |
58 | 58 | ||
59 | #ifndef NO_SOCK | 59 | #ifndef OPENSSL_NO_SOCK |
60 | 60 | ||
61 | #include <stdio.h> | 61 | #include <stdio.h> |
62 | #include <stdlib.h> | 62 | #include <stdlib.h> |
@@ -65,21 +65,21 @@ | |||
65 | #include "cryptlib.h" | 65 | #include "cryptlib.h" |
66 | #include <openssl/bio.h> | 66 | #include <openssl/bio.h> |
67 | 67 | ||
68 | #ifdef WIN16 | 68 | #ifdef OPENSSL_SYS_WIN16 |
69 | #define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ | 69 | #define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ |
70 | #else | 70 | #else |
71 | #define SOCKET_PROTOCOL IPPROTO_TCP | 71 | #define SOCKET_PROTOCOL IPPROTO_TCP |
72 | #endif | 72 | #endif |
73 | 73 | ||
74 | #ifdef SO_MAXCONN | 74 | #ifdef SO_MAXCONN |
75 | #define MAX_LISTEN SOMAXCONN | ||
76 | #elif defined(SO_MAXCONN) | ||
77 | #define MAX_LISTEN SO_MAXCONN | 75 | #define MAX_LISTEN SO_MAXCONN |
76 | #elif defined(SOMAXCONN) | ||
77 | #define MAX_LISTEN SOMAXCONN | ||
78 | #else | 78 | #else |
79 | #define MAX_LISTEN 32 | 79 | #define MAX_LISTEN 32 |
80 | #endif | 80 | #endif |
81 | 81 | ||
82 | #ifdef WINDOWS | 82 | #ifdef OPENSSL_SYS_WINDOWS |
83 | static int wsa_init_done=0; | 83 | static int wsa_init_done=0; |
84 | #endif | 84 | #endif |
85 | 85 | ||
@@ -95,8 +95,10 @@ static struct ghbn_cache_st | |||
95 | } ghbn_cache[GHBN_NUM]; | 95 | } ghbn_cache[GHBN_NUM]; |
96 | 96 | ||
97 | static int get_ip(const char *str,unsigned char *ip); | 97 | static int get_ip(const char *str,unsigned char *ip); |
98 | #if 0 | ||
98 | static void ghbn_free(struct hostent *a); | 99 | static void ghbn_free(struct hostent *a); |
99 | static struct hostent *ghbn_dup(struct hostent *a); | 100 | static struct hostent *ghbn_dup(struct hostent *a); |
101 | #endif | ||
100 | int BIO_get_host_ip(const char *str, unsigned char *ip) | 102 | int BIO_get_host_ip(const char *str, unsigned char *ip) |
101 | { | 103 | { |
102 | int i; | 104 | int i; |
@@ -266,6 +268,7 @@ long BIO_ghbn_ctrl(int cmd, int iarg, char *parg) | |||
266 | return(1); | 268 | return(1); |
267 | } | 269 | } |
268 | 270 | ||
271 | #if 0 | ||
269 | static struct hostent *ghbn_dup(struct hostent *a) | 272 | static struct hostent *ghbn_dup(struct hostent *a) |
270 | { | 273 | { |
271 | struct hostent *ret; | 274 | struct hostent *ret; |
@@ -343,20 +346,27 @@ static void ghbn_free(struct hostent *a) | |||
343 | OPENSSL_free(a); | 346 | OPENSSL_free(a); |
344 | } | 347 | } |
345 | 348 | ||
349 | #endif | ||
350 | |||
346 | struct hostent *BIO_gethostbyname(const char *name) | 351 | struct hostent *BIO_gethostbyname(const char *name) |
347 | { | 352 | { |
353 | #if 1 | ||
354 | /* Caching gethostbyname() results forever is wrong, | ||
355 | * so we have to let the true gethostbyname() worry about this */ | ||
356 | return gethostbyname(name); | ||
357 | #else | ||
348 | struct hostent *ret; | 358 | struct hostent *ret; |
349 | int i,lowi=0,j; | 359 | int i,lowi=0,j; |
350 | unsigned long low= (unsigned long)-1; | 360 | unsigned long low= (unsigned long)-1; |
351 | 361 | ||
352 | /* return(gethostbyname(name)); */ | ||
353 | 362 | ||
354 | #if 0 /* It doesn't make sense to use locking here: The function interface | 363 | # if 0 |
355 | * is not thread-safe, because threads can never be sure when | 364 | /* It doesn't make sense to use locking here: The function interface |
356 | * some other thread destroys the data they were given a pointer to. | 365 | * is not thread-safe, because threads can never be sure when |
357 | */ | 366 | * some other thread destroys the data they were given a pointer to. |
367 | */ | ||
358 | CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); | 368 | CRYPTO_w_lock(CRYPTO_LOCK_GETHOSTBYNAME); |
359 | #endif | 369 | # endif |
360 | j=strlen(name); | 370 | j=strlen(name); |
361 | if (j < 128) | 371 | if (j < 128) |
362 | { | 372 | { |
@@ -384,20 +394,21 @@ struct hostent *BIO_gethostbyname(const char *name) | |||
384 | * parameter is 'char *', instead of 'const char *' | 394 | * parameter is 'char *', instead of 'const char *' |
385 | */ | 395 | */ |
386 | ret=gethostbyname( | 396 | ret=gethostbyname( |
387 | #ifndef CONST_STRICT | 397 | # ifndef CONST_STRICT |
388 | (char *) | 398 | (char *) |
389 | #endif | 399 | # endif |
390 | name); | 400 | name); |
391 | 401 | ||
392 | if (ret == NULL) | 402 | if (ret == NULL) |
393 | goto end; | 403 | goto end; |
394 | if (j > 128) /* too big to cache */ | 404 | if (j > 128) /* too big to cache */ |
395 | { | 405 | { |
396 | #if 0 /* If we were trying to make this function thread-safe (which | 406 | # if 0 |
397 | * is bound to fail), we'd have to give up in this case | 407 | /* If we were trying to make this function thread-safe (which |
398 | * (or allocate more memory). */ | 408 | * is bound to fail), we'd have to give up in this case |
409 | * (or allocate more memory). */ | ||
399 | ret = NULL; | 410 | ret = NULL; |
400 | #endif | 411 | # endif |
401 | goto end; | 412 | goto end; |
402 | } | 413 | } |
403 | 414 | ||
@@ -421,15 +432,17 @@ struct hostent *BIO_gethostbyname(const char *name) | |||
421 | ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits; | 432 | ghbn_cache[i].order=BIO_ghbn_miss+BIO_ghbn_hits; |
422 | } | 433 | } |
423 | end: | 434 | end: |
424 | #if 0 | 435 | # if 0 |
425 | CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); | 436 | CRYPTO_w_unlock(CRYPTO_LOCK_GETHOSTBYNAME); |
426 | #endif | 437 | # endif |
427 | return(ret); | 438 | return(ret); |
439 | #endif | ||
428 | } | 440 | } |
429 | 441 | ||
442 | |||
430 | int BIO_sock_init(void) | 443 | int BIO_sock_init(void) |
431 | { | 444 | { |
432 | #ifdef WINDOWS | 445 | #ifdef OPENSSL_SYS_WINDOWS |
433 | static struct WSAData wsa_state; | 446 | static struct WSAData wsa_state; |
434 | 447 | ||
435 | if (!wsa_init_done) | 448 | if (!wsa_init_done) |
@@ -449,13 +462,13 @@ int BIO_sock_init(void) | |||
449 | return(-1); | 462 | return(-1); |
450 | } | 463 | } |
451 | } | 464 | } |
452 | #endif /* WINDOWS */ | 465 | #endif /* OPENSSL_SYS_WINDOWS */ |
453 | return(1); | 466 | return(1); |
454 | } | 467 | } |
455 | 468 | ||
456 | void BIO_sock_cleanup(void) | 469 | void BIO_sock_cleanup(void) |
457 | { | 470 | { |
458 | #ifdef WINDOWS | 471 | #ifdef OPENSSL_SYS_WINDOWS |
459 | if (wsa_init_done) | 472 | if (wsa_init_done) |
460 | { | 473 | { |
461 | wsa_init_done=0; | 474 | wsa_init_done=0; |
@@ -465,7 +478,7 @@ void BIO_sock_cleanup(void) | |||
465 | #endif | 478 | #endif |
466 | } | 479 | } |
467 | 480 | ||
468 | #if !defined(VMS) || __VMS_VER >= 70000000 | 481 | #if !defined(OPENSSL_SYS_VMS) || __VMS_VER >= 70000000 |
469 | 482 | ||
470 | int BIO_socket_ioctl(int fd, long type, unsigned long *arg) | 483 | int BIO_socket_ioctl(int fd, long type, unsigned long *arg) |
471 | { | 484 | { |
@@ -494,16 +507,16 @@ static int get_ip(const char *str, unsigned char ip[4]) | |||
494 | { | 507 | { |
495 | ok=1; | 508 | ok=1; |
496 | tmp[num]=tmp[num]*10+c-'0'; | 509 | tmp[num]=tmp[num]*10+c-'0'; |
497 | if (tmp[num] > 255) return(-1); | 510 | if (tmp[num] > 255) return(0); |
498 | } | 511 | } |
499 | else if (c == '.') | 512 | else if (c == '.') |
500 | { | 513 | { |
501 | if (!ok) return(-1); | 514 | if (!ok) return(-1); |
502 | if (num == 3) break; | 515 | if (num == 3) return(0); |
503 | num++; | 516 | num++; |
504 | ok=0; | 517 | ok=0; |
505 | } | 518 | } |
506 | else if ((num == 3) && ok) | 519 | else if (c == '\0' && (num == 3) && ok) |
507 | break; | 520 | break; |
508 | else | 521 | else |
509 | return(0); | 522 | return(0); |
@@ -661,6 +674,7 @@ int BIO_accept(int sock, char **addr) | |||
661 | ret=accept(sock,(struct sockaddr *)&from,(void *)&len); | 674 | ret=accept(sock,(struct sockaddr *)&from,(void *)&len); |
662 | if (ret == INVALID_SOCKET) | 675 | if (ret == INVALID_SOCKET) |
663 | { | 676 | { |
677 | if(BIO_sock_should_retry(ret)) return -2; | ||
664 | SYSerr(SYS_F_ACCEPT,get_last_socket_error()); | 678 | SYSerr(SYS_F_ACCEPT,get_last_socket_error()); |
665 | BIOerr(BIO_F_BIO_ACCEPT,BIO_R_ACCEPT_ERROR); | 679 | BIOerr(BIO_F_BIO_ACCEPT,BIO_R_ACCEPT_ERROR); |
666 | goto end; | 680 | goto end; |