pike.git
/
lib
/
modules
/
Protocols.pmod
/
DNS.pmod
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/lib/modules/Protocols.pmod/DNS.pmod:59:
// This will have to be generalized for // the server part... string mkquery(string dname, int cl, int type) { return low_mkquery(random(65536),dname,cl,type); }
-
string decode_domain(string msg, int
*
n)
+
string decode_domain(string msg,
array(
int
)
n)
{
-
string
*
domains=({});
+
array(
string
)
domains=({});
int pos=n[0]; int next=-1;
-
string
*
ret=({});
+
array(
string
)
ret=({});
while(pos < sizeof(msg)) { switch(int len=msg[pos]) { case 0: if(next==-1) next=pos+1; n[0]=next; return ret*"."; case 1..63:
pike.git/lib/modules/Protocols.pmod/DNS.pmod:89:
default: if(next==-1) next=pos+2; pos=((len&63)<<8) + msg[pos+1]; continue; } break; } }
-
string decode_string(string s, int
*
next)
+
string decode_string(string s,
array(
int
)
next)
{ int len=s[next[0]]; next[0]+=len+1; return s[next[0]-len..next[0]-1]; }
-
int decode_short(string s, int
*
next)
+
int decode_short(string s,
array(
int
)
next)
{ sscanf(s[next[0]..next[0]+1],"%2c",int ret); next[0]+=2; return ret; }
-
int decode_int(string s, int
*
next)
+
int decode_int(string s,
array(
int
)
next)
{ sscanf(s[next[0]..next[0]+1],"%2c",int ret); next[0]+=2; return ret; }
-
mixed
*
decode_entries(string s,int num, int
*
next)
+
array
decode_entries(string s,int num,
array(
int
)
next)
{
-
string
*
ret=({});
+
array(
string
)
ret=({});
for(int e=0;e<num && next[0]<strlen(s);e++) { mapping m=([]); m->name=decode_domain(s,next); sscanf(s[next[0]..next[0]+10], "%2c%2c%4c%2c", m->type,m->cl,m->ttl,m->len); next[0]+=10; int tmp=next[0];
pike.git/lib/modules/Protocols.pmod/DNS.pmod:187:
m->opcode=(m->c1>>1)&15; m->qr=m->c1&1; m->rcode=(m->c2>>4)&15; m->cd=(m->c2>>3)&1; m->ad=(m->c2>>2)&1; m->ra=(m->c2)&1; m->length=strlen(s);
-
string
*
tmp=({});
+
array(
string
)
tmp=({});
int e; if(m->qdcount!=1) return m;
-
int
*
next=({12});
+
array(
int
)
next=({12});
m->qd=decode_domain(s,next); sscanf(s[next[0]..next[0]+3],"%2c%2c",m->type, m->cl); next[0]+=4; m->an=decode_entries(s,m->ancount,next); m->ns=decode_entries(s,m->nscount,next); m->ar=decode_entries(s,m->arcount,next); return m; } };
pike.git/lib/modules/Protocols.pmod/DNS.pmod:410:
//! 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)
+
array
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)); if(m && m->an && sizeof(m->an)) break; } } else { m = do_sync_query(mkquery(s, C_IN, T_A)); } if (!m) { return ({ 0, ({}), ({}) }); }
-
string
*
names=({});
-
string
*
ips=({});
+
array(
string
)
names=({});
+
array(
string
)
ips=({});
foreach(m->an, mapping x) { if(x->name) names+=({x->name}); if(x->a) ips+=({x->a}); } return ({ sizeof(names)?names[0]:0, ips,
pike.git/lib/modules/Protocols.pmod/DNS.pmod:456:
string arpa_from_ip(string ip) { return reverse(ip/".")*"."+".IN-ADDR.ARPA"; } string ip_from_arpa(string arpa) { return reverse(arpa/".")[2..]*"."; }
-
mixed
*
gethostbyaddr(string s)
+
array
gethostbyaddr(string s)
{ mapping m=do_sync_query(mkquery(arpa_from_ip(s), C_IN, T_PTR)); if (m) {
-
string
*
names=({});
-
string
*
ips=({});
+
array(
string
)
names=({});
+
array(
string
)
ips=({});
foreach(m->an, mapping x) { if(x->ptr) names+=({x->ptr}); if(x->name) { ips+=({ip_from_arpa(x->name)}); } }
pike.git/lib/modules/Protocols.pmod/DNS.pmod:520:
{ if(m2->preference<minpref) { ret=m2->mx; minpref=m2->preference; } } return ret; }
-
string
*
get_mx(string host)
+
array(
string
)
get_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)) break;
pike.git/lib/modules/Protocols.pmod/DNS.pmod:563:
inherit Stdio.UDP : udp; async_client next_client; class Request { string req; string domain; function callback; int retries; int timestamp;
-
mixed
*
args;
+
array
args;
}; mapping requests=([]); 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);