aboutsummaryrefslogtreecommitdiff
path: root/resolv
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2004-09-18 18:00:50 +0000
committerUlrich Drepper <drepper@redhat.com>2004-09-18 18:00:50 +0000
commite33b89df220fae37a1819b3fa39d1cc3cd2e31aa (patch)
tree73d5ff78d6eeab0ea2146aa91b63766a95ac2096 /resolv
parent9530eaf007c2663992c465caf0aee6a7c5b650ee (diff)
downloadglibc-e33b89df220fae37a1819b3fa39d1cc3cd2e31aa.tar
glibc-e33b89df220fae37a1819b3fa39d1cc3cd2e31aa.tar.gz
glibc-e33b89df220fae37a1819b3fa39d1cc3cd2e31aa.tar.bz2
glibc-e33b89df220fae37a1819b3fa39d1cc3cd2e31aa.zip
(res_nmkquery): Randomize request ID every time.
Diffstat (limited to 'resolv')
-rw-r--r--resolv/res_mkquery.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/resolv/res_mkquery.c b/resolv/res_mkquery.c
index 05b94bd79e..2d25b169a2 100644
--- a/resolv/res_mkquery.c
+++ b/resolv/res_mkquery.c
@@ -1,7 +1,7 @@
/*
* Copyright (c) 1985, 1993
* The Regents of the University of California. All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
@@ -13,7 +13,7 @@
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
@@ -29,14 +29,14 @@
/*
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
- *
+ *
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies, and that
* the name of Digital Equipment Corporation not be used in advertising or
* publicity pertaining to distribution of the document or software without
* specific, written prior permission.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
@@ -81,6 +81,13 @@ static const char rcsid[] = "$BINDId: res_mkquery.c,v 8.12 1999/10/13 16:39:40 v
/* Options. Leave them on. */
/* #define DEBUG */
+#ifdef _LIBC
+# include <hp-timing.h>
+# if HP_TIMING_AVAIL
+# define RANDOM_BITS(Var) { uint64_t v64; HP_TIMING_NOW (v64); Var = v64; }
+# endif
+#endif
+
extern const char *_res_opcodes[];
/*
@@ -115,7 +122,28 @@ res_nmkquery(res_state statp,
return (-1);
memset(buf, 0, HFIXEDSZ);
hp = (HEADER *) buf;
+ /* We randomize the IDs every time. The old code just
+ incremented by one after the initial randomization which
+ still predictable if the application does multiple
+ requests. */
+#if 0
hp->id = htons(++statp->id);
+#else
+ hp->id = htons(statp->id);
+ int randombits;
+ do
+ {
+#ifdef RANDOM_BITS
+ RANDOM_BITS (randombits);
+#else
+ struct timeval tv;
+ __gettimeofday (&tv, NULL);
+ random_time_bits = (tv.tv_sec << 8) ^ tv.tv_usec;
+#endif
+ }
+ while (randombits == 0);
+ statp->id = (statp->id + randombits) & 0xffff;
+#endif
hp->opcode = op;
hp->rd = (statp->options & RES_RECURSE) != 0;
hp->rcode = NOERROR;