Remove apps cache for gethostbyname
Reviewed-by: Richard Levitte <levitte@openssl.org>
This commit is contained in:
parent
cab4cd3fe9
commit
ff660b9312
@ -139,7 +139,6 @@ typedef unsigned int u_int;
|
|||||||
# include "netdb.h"
|
# include "netdb.h"
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
static struct hostent *GetHostByName(const char *name);
|
|
||||||
# if defined(OPENSSL_SYS_WINDOWS) || (defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK))
|
# if defined(OPENSSL_SYS_WINDOWS) || (defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK))
|
||||||
static void ssl_sock_cleanup(void);
|
static void ssl_sock_cleanup(void);
|
||||||
# endif
|
# endif
|
||||||
@ -564,7 +563,7 @@ static int do_accept(int acc_sock, int *sock, char **host)
|
|||||||
*host = app_malloc(strlen(h1->h_name) + 1, "copy hostname");
|
*host = app_malloc(strlen(h1->h_name) + 1, "copy hostname");
|
||||||
BUF_strlcpy(*host, h1->h_name, strlen(h1->h_name) + 1);
|
BUF_strlcpy(*host, h1->h_name, strlen(h1->h_name) + 1);
|
||||||
|
|
||||||
h2 = GetHostByName(*host);
|
h2 = gethostbyname(*host);
|
||||||
if (h2 == NULL) {
|
if (h2 == NULL) {
|
||||||
BIO_printf(bio_err, "gethostbyname failure\n");
|
BIO_printf(bio_err, "gethostbyname failure\n");
|
||||||
closesocket(ret);
|
closesocket(ret);
|
||||||
@ -655,7 +654,7 @@ static int host_ip(const char *str, unsigned char ip[4])
|
|||||||
if (!ssl_sock_init())
|
if (!ssl_sock_init())
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
he = GetHostByName(str);
|
he = gethostbyname(str);
|
||||||
if (he == NULL) {
|
if (he == NULL) {
|
||||||
BIO_printf(bio_err, "gethostbyname failure\n");
|
BIO_printf(bio_err, "gethostbyname failure\n");
|
||||||
goto err;
|
goto err;
|
||||||
@ -693,51 +692,4 @@ int extract_port(const char *str, unsigned short *port_ptr)
|
|||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
# define GHBN_NUM 4
|
|
||||||
static struct ghbn_cache_st {
|
|
||||||
char name[128];
|
|
||||||
struct hostent ent;
|
|
||||||
unsigned long order;
|
|
||||||
} ghbn_cache[GHBN_NUM];
|
|
||||||
|
|
||||||
static unsigned long ghbn_hits = 0L;
|
|
||||||
static unsigned long ghbn_miss = 0L;
|
|
||||||
|
|
||||||
static struct hostent *GetHostByName(const char *name)
|
|
||||||
{
|
|
||||||
struct hostent *ret;
|
|
||||||
int i, lowi = 0;
|
|
||||||
unsigned long low = (unsigned long)-1;
|
|
||||||
|
|
||||||
for (i = 0; i < GHBN_NUM; i++) {
|
|
||||||
if (low > ghbn_cache[i].order) {
|
|
||||||
low = ghbn_cache[i].order;
|
|
||||||
lowi = i;
|
|
||||||
}
|
|
||||||
if (ghbn_cache[i].order > 0) {
|
|
||||||
if (strncmp(name, ghbn_cache[i].name, 128) == 0)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (i == GHBN_NUM) { /* no hit */
|
|
||||||
ghbn_miss++;
|
|
||||||
ret = gethostbyname(name);
|
|
||||||
if (ret == NULL)
|
|
||||||
return (NULL);
|
|
||||||
/* else add to cache */
|
|
||||||
if (strlen(name) < sizeof ghbn_cache[0].name) {
|
|
||||||
strcpy(ghbn_cache[lowi].name, name);
|
|
||||||
memcpy((char *)&(ghbn_cache[lowi].ent), ret,
|
|
||||||
sizeof(struct hostent));
|
|
||||||
ghbn_cache[lowi].order = ghbn_miss + ghbn_hits;
|
|
||||||
}
|
|
||||||
return (ret);
|
|
||||||
} else {
|
|
||||||
ghbn_hits++;
|
|
||||||
ret = &(ghbn_cache[i].ent);
|
|
||||||
ghbn_cache[i].order = ghbn_miss + ghbn_hits;
|
|
||||||
return (ret);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user