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

version» Context lines:

pike.git/lib/modules/Protocols.pmod/DNS.pmod:1:   // Not yet finished -- Fredrik Hubinette    + //! module Protocols + //! submodule DNS +    constant NOERROR=0;   constant FORMERR=1;   constant SERVFAIL=2;   constant NXDOMAIN=3;   constant NOTIMPL=4;   constant NXRRSET=8;      constant QUERY=0;      constant C_IN=1;
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;    }   };         #define RETRIES 12   #define RETRY_DELAY 5    - class client { + class client + { + //! + //! class client + //! Synchronous DNS client. + //! +     inherit protocol;       static private int is_ip(string ip)    {    return(replace(ip,    ({ "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "." }),    ({ "", "", "", "", "", "", "", "", "", "", "" })) == "");    }       static private mapping etc_hosts;
pike.git/lib/modules/Protocols.pmod/DNS.pmod:267:    }    }    }    } else {    // Couldn't read /etc/hosts.    }    }    return(etc_hosts[lower_case(host)]);    }    +  //! +  //! method void create() +  //! method void create(void|string|array server, void|int|array domain) +  //! +     array(string) nameservers = ({});    array domains = ({});    void create(void|string|array(string) server, void|int|array(string) domain)    {    if(!server)    {    string domain;      #if __NT__    domain=get_tcpip_param("Domain");
pike.git/lib/modules/Protocols.pmod/DNS.pmod:344:    }    if(domain)    domains = ({ domain }) + domains;    domains -= ({ "" });    domains = Array.map(domains, lambda(string d) {    if (d[-1] == '.') {    return d[..sizeof(d)-2];    }    return d;    }); -  } else { +  } +  else +  {    if(arrayp(server))    nameservers = server;    else    nameservers = ({ server });       if(arrayp(domain))    domains = domain;    else    if(stringp(domain))    domains = ({ domain }); -  +     }    }    -  +     mapping do_sync_query(string s)    {    object udp = Stdio.UDP();    udp->bind(0);    mapping m;    int i;    for (i=0; i < RETRIES; i++) {    udp->send(nameservers[i % sizeof(nameservers)], 53, s);       while (udp->wait(RETRY_DELAY)) {
pike.git/lib/modules/Protocols.pmod/DNS.pmod:383:    (search(nameservers, m->ip) != -1)) {    // Success.    return decode_res(m->data);    }    }    }    // Failure.    return 0;    }    +  //! +  //! method array gethostbyname(string hostname) +  //! method array gethostbyaddr(string hostip) +  //! Querys the host name or ip from the default or given +  //! DNS server. The result is a mapping with three elements, +  //! <data_description type=array> +  //! <elem value=hostname type=string>hostname</elem> +  //! <elem value=ip type=array(string)>ip number(s)</elem> +  //! <elem value=ip type=array(string)>dns name(s)</elem> +  //! </data_description> +  //!       mixed *gethostbyname(string s)    {    mapping m;    if(sizeof(domains) && s[-1] != '.' && sizeof(s/".") < 3) {    m = do_sync_query(mkquery(s, C_IN, T_A));    if(!m || !m->an || !sizeof(m->an))    foreach(domains, string domain)    {    m = do_sync_query(mkquery(s+"."+domain, C_IN, T_A));
pike.git/lib/modules/Protocols.pmod/DNS.pmod:457:    sizeof(names)?names[0]:0,    ips,    names,    });    } else {    // Lookup failed.    return({ 0, ({}), ({}) });    }    }    +  //! +  //! method string get_primary_mx(string hostname) +  //! Querys the primary mx for the host. +  //! returns the hostname of the primary mail exchanger +  //! +     string get_primary_mx(string host)    {    mapping m;    if(sizeof(domains) && host[-1] != '.' && sizeof(host/".") < 3) {    m=do_sync_query(mkquery(host, C_IN, T_MX));    if(!m || !m->an || !sizeof(m->an))    foreach(domains, string domain)    {    m=do_sync_query(mkquery(host+"."+domain, C_IN, T_MX));    if(m && m->an && sizeof(m->an))