---
name: "dns_random"
section: "3"
platform: "linux"
package: "libdjbdns1-dev"
version: "1.05-5+b1"
release: "Debian 5.0 (Lenny)"
platforms: ["linux"]
url: "https://new.carta.tech/dns_random"
---

# dns\_random(3)

The dns\_random library interface

## NAME

dns\_random - The dns\_random library interface

## SYNOPSIS

**#include \<dns.h\>**

**dns\_random\_init**(seed);\
 r = **dns\_random**(m);\
\
   char *seed*\[128\];\
   unsigned int *r*;\
   unsigned int *m*;

## DESCRIPTION

**dns\_random** computes a pseudorandom 32-bit integer and returns that integer modulo *m*. It returns 0 if *m* is 0.

**dns\_random\_init** initializes the pseudorandom number generator, taking account of *seed*, the current process ID, and the current time.

## Notes on DNS query security

A DNS client will accept any response that shows up at the right time, is addressed from the IP address of the legitimate server, is addressed to the UDP port used in the DNS query, repeats the query name and type used in the DNS query, and repeats the 16-bit ID used in the DNS query.

An active sniffing attacker can easily forge responses by copying information from queries. Blind attackers need to guess the time, UDP port, and ID for the targeted query name.

The [**dns\_transmit**(3)](/dns_transmit/3.md) functions use **dns\_random** to create query IDs and UDP ports. The **dns\_random** generator is designed to be extremely difficult to predict for an attacker who cannot guess *seed*. Note, however, that there are only about a billion possible ID-port pairs, so a prolonged blind attack will succeed eventually.

## SEE ALSO

[dns\_domain(3)](/dns_domain/3.md), [dns\_ip4(3)](/dns_ip4/3.md), [dns\_ip4\_qualify(3)](/dns_ip4_qualify/3.md), [dns\_mx(3)](/dns_mx/3.md), [dns\_name4(3)](/dns_name4/3.md), [dns\_packet(3)](/dns_packet/3.md), [dns\_transmit(3)](/dns_transmit/3.md), [dns\_txt(3)](/dns_txt/3.md)

http://cr.yp.to/djbdns/blurb/library.html
