Skip to content

Instantly share code, notes, and snippets.

@fxlv
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fxlv/6657ba422a9e7afd18ac to your computer and use it in GitHub Desktop.
Save fxlv/6657ba422a9e7afd18ac to your computer and use it in GitHub Desktop.
Excerpt from eglibc-2.13/resolv/res_send.c, comments added to explain logic.
/*
* ns == current nameserver index (eg. 1,2 or 3)
* statp->retrans == retransmition time interval (this is defined in resolv.h)
*
* do a bitwise shift to the left to get the new timeout
* if ns == 0 then this does nothing
*/
int seconds = (statp->retrans << ns);
if (ns > 0)
// divide the time that was calculated after the bitwise shift by the nameserver count
seconds /= statp->nscount;
if (seconds <= 0)
// seconds can't be smaller than 0, so set it to 1 in case it is smaller
seconds = 1;
bool single_request = (statp->options & RES_SNGLKUP) != 0;
bool single_request_reopen = (statp->options & RES_SNGLKUPREOP) != 0;
int save_gotsomewhere = *gotsomewhere;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment