mirror of
https://git.rtems.org/rtems-libbsd/
synced 2025-10-15 19:08:21 +08:00
Update to FreeBSD Stable/9 2015-04-08
This commit is contained in:
@@ -68,7 +68,7 @@
|
||||
|
||||
#if defined(LIBC_SCCS) && !defined(lint)
|
||||
static const char sccsid[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
|
||||
static const char rcsid[] = "$Id: res_init.c,v 1.16.18.7 2007/07/09 01:52:58 marka Exp $";
|
||||
static const char rcsid[] = "$Id: res_init.c,v 1.26 2008/12/11 09:59:00 marka Exp $";
|
||||
#endif /* LIBC_SCCS and not lint */
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
@@ -93,6 +93,19 @@ __FBSDID("$FreeBSD$");
|
||||
#include <unistd.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#ifndef HAVE_MD5
|
||||
# include "../dst/md5.h"
|
||||
#else
|
||||
# ifdef SOLARIS2
|
||||
# include <sys/md5.h>
|
||||
# elif _LIBC
|
||||
# include <md5.h>
|
||||
# endif
|
||||
#endif
|
||||
#ifndef _MD5_H_
|
||||
# define _MD5_H_ 1 /*%< make sure we do not include rsaref md5.h file */
|
||||
#endif
|
||||
|
||||
#include "un-namespace.h"
|
||||
|
||||
#include "port_after.h"
|
||||
@@ -180,9 +193,12 @@ __res_vinit(res_state statp, int preinit) {
|
||||
statp->retrans = RES_TIMEOUT;
|
||||
statp->retry = RES_DFLRETRY;
|
||||
statp->options = RES_DEFAULT;
|
||||
statp->id = res_randomid();
|
||||
}
|
||||
|
||||
statp->_rnd = malloc(16);
|
||||
res_rndinit(statp);
|
||||
statp->id = res_nrandomid(statp);
|
||||
|
||||
memset(u, 0, sizeof(u));
|
||||
#ifdef USELOOPBACK
|
||||
u[nserv].sin.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
|
||||
@@ -717,12 +733,48 @@ net_mask(in) /*!< XXX - should really use system's version of this */
|
||||
}
|
||||
#endif
|
||||
|
||||
u_int
|
||||
res_randomid(void) {
|
||||
static u_char srnd[16];
|
||||
|
||||
void
|
||||
res_rndinit(res_state statp)
|
||||
{
|
||||
struct timeval now;
|
||||
u_int32_t u32;
|
||||
u_int16_t u16;
|
||||
u_char *rnd = statp->_rnd == NULL ? srnd : statp->_rnd;
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid()));
|
||||
u32 = now.tv_sec;
|
||||
memcpy(rnd, &u32, 4);
|
||||
u32 = now.tv_usec;
|
||||
memcpy(rnd + 4, &u32, 4);
|
||||
u32 += now.tv_sec;
|
||||
memcpy(rnd + 8, &u32, 4);
|
||||
u16 = getpid();
|
||||
memcpy(rnd + 12, &u16, 2);
|
||||
}
|
||||
|
||||
u_int
|
||||
res_nrandomid(res_state statp) {
|
||||
struct timeval now;
|
||||
u_int16_t u16;
|
||||
MD5_CTX ctx;
|
||||
u_char *rnd = statp->_rnd == NULL ? srnd : statp->_rnd;
|
||||
|
||||
gettimeofday(&now, NULL);
|
||||
u16 = (u_int16_t) (now.tv_sec ^ now.tv_usec);
|
||||
memcpy(rnd + 14, &u16, 2);
|
||||
#ifndef HAVE_MD5
|
||||
MD5_Init(&ctx);
|
||||
MD5_Update(&ctx, rnd, 16);
|
||||
MD5_Final(rnd, &ctx);
|
||||
#else
|
||||
MD5Init(&ctx);
|
||||
MD5Update(&ctx, rnd, 16);
|
||||
MD5Final(rnd, &ctx);
|
||||
#endif
|
||||
memcpy(&u16, rnd + 14, 2);
|
||||
return ((u_int) u16);
|
||||
}
|
||||
|
||||
/*%
|
||||
@@ -752,10 +804,15 @@ res_nclose(res_state statp) {
|
||||
void
|
||||
res_ndestroy(res_state statp) {
|
||||
res_nclose(statp);
|
||||
if (statp->_u._ext.ext != NULL)
|
||||
if (statp->_u._ext.ext != NULL) {
|
||||
free(statp->_u._ext.ext);
|
||||
statp->_u._ext.ext = NULL;
|
||||
}
|
||||
if (statp->_rnd != NULL) {
|
||||
free(statp->_rnd);
|
||||
statp->_rnd = NULL;
|
||||
}
|
||||
statp->options &= ~RES_INIT;
|
||||
statp->_u._ext.ext = NULL;
|
||||
}
|
||||
|
||||
#ifndef _LIBC
|
||||
|
Reference in New Issue
Block a user