pike.git / lib / modules / Protocols.pmod / DNS.pmod

version» Context lines:

pike.git/lib/modules/Protocols.pmod/DNS.pmod:204:    m->ns=decode_entries(s,m->nscount,next);    m->ar=decode_entries(s,m->arcount,next);    return m;    }   };         class client {    inherit protocol;    -  string nameserver; +  array(string) nameservers = ({});    array domains = ({});    void create(void|string server)    {    if(!server)    {    string domain; -  foreach(Stdio.read_file("/etc/resolv.conf")/"\n", string line) +  string resolv_conf = Stdio.read_file("/etc/resolv.conf"); +  +  if (!resolv_conf) { +  throw(({ "Protocols.DNS.client(): No /etc/resolv.conf!\n", +  backtrace() })); +  } +  +  foreach(resolv_conf/"\n", string line)    {    string rest;    sscanf(line,"%s#",line);    sscanf(line,"%*[\r \t]%s",line);    line=reverse(line);    sscanf(line,"%*[\r \t]%s",line);    line=reverse(line);    sscanf(line,"%s%*[ \t]%s",line,rest);    switch(line)    {
pike.git/lib/modules/Protocols.pmod/DNS.pmod:233:    // Save domain for later.    domain = rest;    break;    case "search":    rest = replace(rest, "\t", " ");    foreach(rest / " " - ({""}), string dom)    domains += ({dom});    break;       case "nameserver": -  nameserver=rest; +  nameservers += ({ rest });    break;    }    } -  +  if (!sizeof(nameservers)) { +  nameservers = ({ "127.0.0.1" }); +  }    if(domain)    domains = ({ domain }) + domains;    } else { -  nameserver=server; +  nameservers= ({ server });    }    }          // Warning: NO TIMEOUT    mapping do_sync_query(string s)    {    object udp=spider.dumUDP();    udp->bind(0); -  udp->send(nameserver,53,s); +  udp->send(nameservers[0],53,s);    mapping m;    do {    m=udp->read();    } while (m->port != 53 || -  m->ip != nameserver || +  m->ip != nameservers[0] ||    m->data[0..1]!=s[0..1]);    return decode_res(m->data);    }          // Warning: NO TIMEOUT    mixed *gethostbyname(string s)    {    mapping m;    if(sizeof(domains) && s[-1] != '.' && sizeof(s/".") < 3) {
pike.git/lib/modules/Protocols.pmod/DNS.pmod:384:       static private void remove(object(Request) r)    {    if(!r) return;    sscanf(r->req,"%2c",int id);    m_delete(requests,id);    r->callback(r->domain,0,@r->args);    destruct(r);    }    -  void retry(object(Request) r) +  void retry(object(Request) r, void|int nsno)    {    if(!r) return; -  +  if (nsno >= sizeof(nameservers)) {    if(r->retries++ > 12)    {    call_out(remove,120,r); -  }else{ -  call_out(retry,5,r); -  send(nameserver,53,r->req); +  return; +  } else { +  nsno = 0;    }    }    -  +  send(nameservers[nsno],53,r->req); +  call_out(retry,5,r,nsno+1); +  } +     void do_query(string domain, int cl, int type,    function(string,mapping,mixed...:void) callback,    mixed ... args)    {    id++;    id&=65535;    string req=low_mkquery(id,domain,cl,type);       if(requests[id])    throw(({"Cannot find an empty request slot.\n",backtrace()}));    object r=Request();    r->req=req;    r->domain=domain;    r->callback=callback;    r->args=args;    requests[id]=r; -  call_out(retry,5,r); -  udp::send(nameserver,53,r->req); +  udp::send(nameservers[0],53,r->req); +  call_out(retry,5,r,1);    }       static private void rec_data()    {    mapping m=udp::read(); -  if(m->port != 53 || m->ip != nameserver) return; +  if(m->port != 53 || search(nameservers, m->ip) == -1) return;    sscanf(m->data,"%2c",int id);    object r=requests[id];    if(!r) return;    m_delete(requests,id);    r->callback(r->domain,decode_res(m->data),@r->args);    destruct(r);    }       static private void generic_get(string d,    mapping answer,