DNSPacketWriter pw(packet, DNSName(qname), DNSRecordContent::TypeToNumber(qtype));
pw.getHeader()->rd=wantRecursion;
- pw.getHeader()->id=random();
+ pw.getHeader()->id=dns_random(UINT16_MAX);
if(!subnet.empty() || !ecsRange.empty()) {
EDNSSubnetOpts opt;
known.push_back(ptr);
}
for(;n < total; ++n) {
- toSend.push_back(known[random()%known.size()].get());
+ toSend.push_back(known[dns_random(known.size())].get());
}
random_shuffle(toSend.begin(), toSend.end());
g_recvcounter.store(0);
void mainthread()
{
- Utility::srandom(time(0) ^ getpid());
+ Utility::srandom();
int newgid=0;
if(!::arg()["setgid"].empty())
// TODO Keep track of 'down' masters
set<ComboAddress>::const_iterator it(domainConfig.second.masters.begin());
- std::advance(it, random() % domainConfig.second.masters.size());
+ std::advance(it, dns_random(domainConfig.second.masters.size()));
ComboAddress master = *it;
string dir = workdir + "/" + domain.toString();
for(const auto& nmpair : netmasks) {
Netmask nm(nmpair.second);
if(nm.match(bestwho)) {
- return destinations[random() % destinations.size()].second;
+ return destinations[dns_random(destinations.size())].second;
}
}
}
g_argc = argc;
g_argv = argv;
g_stats.startupTime=time(0);
+ Utility::srandom();
versionSetProduct(ProductRecursor);
reportBasicTypes();
reportOtherTypes();
dt.set();
unsigned int hits=0, misses=0;
for(; n < 10000; ++n) {
- DNSName domain(domains[random() % domains.size()]);
+ DNSName domain(domains[dns_random(domains.size())]);
B.lookup(QType(QType::NS), domain);
while(B.get(rr)) {
hits++;
DTime dt;
dt.set();
for(unsigned int n=0; n < 100000; ++n) {
- rnd = random();
+ rnd = dns_random(UINT32_MAX);
snprintf(tmp, sizeof(tmp), "%d.%d.%d.%d",
octets[0], octets[1], octets[2], octets[3]);
rr.content=tmp;
DNSPacketWriter pw(packet, qname, QType::A);
pw.getHeader()->rd=true;
pw.getHeader()->qr=false;
- pw.getHeader()->id=random();
+ pw.getHeader()->id=dns_random(UINT16_MAX);
string qpacket((const char*)&packet[0], packet.size());
pw.startRecord(qname, QType::A, ttd);
pw2.getHeader()->rd=true;
pw2.getHeader()->qr=false;
- pw2.getHeader()->id=random();
+ pw2.getHeader()->id=dns_random(UINT16_MAX);
qpacket.assign((const char*)&packet[0], packet.size());
found = rpc.getResponsePacket(tag, qpacket, time(nullptr), &fpacket, &age, &qhash);
DNSPacketWriter pw(packet, qname, QType::A);
pw.getHeader()->rd=true;
pw.getHeader()->qr=false;
- pw.getHeader()->id=random();
+ pw.getHeader()->id=dns_random(UINT16_MAX);
string qpacket(reinterpret_cast<const char*>(&packet[0]), packet.size());
pw.startRecord(qname, QType::A, ttd);
}
// Sets the random seed.
-void Utility::srandom( unsigned int seed )
+void Utility::srandom(void)
{
- ::srandom(seed);
+ struct timeval tv;
+ gettimeofday(&tv, 0);
+ ::srandom(tv.tv_sec ^ tv.tv_usec ^ getpid());
}
// Writes a vector.
static int writev( Utility::sock_t socket, const iovec *vector, size_t count );
//! Sets the random seed.
- static void srandom( unsigned int seed );
-
+ static void srandom(void);
+
//! Drops the program's group privileges.
static void dropGroupPrivs( int uid, int gid );