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

version» Context lines:

pike.git/lib/modules/Protocols.pmod/DNS.pmod:1: - // $Id: DNS.pmod,v 1.70 2002/12/23 18:59:54 grubba Exp $ + // $Id: DNS.pmod,v 1.71 2003/01/20 17:44:00 nilsson Exp $   // Not yet finished -- Fredrik Hubinette      //! Domain Name System   //! RFC 1035      #pike __REAL_VERSION__      constant NOERROR=0;   constant FORMERR=1;   constant SERVFAIL=2;
pike.git/lib/modules/Protocols.pmod/DNS.pmod:93:       //! Type - IPv6 address record (RFC 2874, incomplete support)    T_A6=38,   };      //! Low level DNS protocol   class protocol   {    string mklabel(string s)    { -  if(strlen(s)>63) +  if(sizeof(s)>63)    error("Too long component in domain name.\n"); -  return sprintf("%c%s",strlen(s),s); +  return sprintf("%c%s",sizeof(s),s);    }       static private string mkname(string|array(string) labels, int pos,    mapping(string:int) comp)    {    if(stringp(labels))    labels = labels/"."-({""});    if(!labels || !sizeof(labels))    return "\0";    string n = labels*".";    if(comp[n])    return sprintf("%2c", comp[n]|0xc000);    else {    if(pos<0x4000)    comp[n]=pos;    string l = mklabel(labels[0]); -  return l + mkname(labels[1..], pos+strlen(l), comp); +  return l + mkname(labels[1..], pos+sizeof(l), comp);    }    }       static private string mkrdata(mapping entry, int pos, mapping(string:int) c)    {    switch(entry->type) {    case T_CNAME:    return mkname(entry->cname, pos, c);    case T_PTR:    return mkname(entry->ptr, pos, c);
pike.git/lib/modules/Protocols.pmod/DNS.pmod:138:    return mkname(entry->mf, pos, c);    case T_MB:    return mkname(entry->mb, pos, c);    case T_MG:    return mkname(entry->mg, pos, c);    case T_MR:    return mkname(entry->mr, pos, c);    case T_MX:    return sprintf("%2c", entry->preference)+mkname(entry->mx, pos+2, c);    case T_HINFO: -  return sprintf("%1c%s%1c%s", strlen(entry->cpu||""), entry->cpu||"", -  strlen(entry->os||""), entry->os||""); +  return sprintf("%1c%s%1c%s", sizeof(entry->cpu||""), entry->cpu||"", +  sizeof(entry->os||""), entry->os||"");    case T_MINFO:    string rmailbx = mkname(entry->rmailbx, pos, c); -  return rmailbx + mkname(entry->emailbx, pos+strlen(rmailbx), c); +  return rmailbx + mkname(entry->emailbx, pos+sizeof(rmailbx), c);    case T_SRV:    return sprintf("%2c%2c%2c", entry->priority, entry->weight, entry->port) +    mkname(entry->target||"", pos+6, c);    case T_A:    case T_AAAA:    return sprintf("%@1c", (array(int))((entry->a||"0.0.0.0")/".")[0..3]);    case T_SOA:    string mname = mkname(entry->mname, pos, c); -  return mname + mkname(entry->rname, pos+strlen(mname), c) + +  return mname + mkname(entry->rname, pos+sizeof(mname), c) +    sprintf("%4c%4c%4c%4c%4c", entry->serial, entry->refresh,    entry->retry, entry->expire, entry->minimum);    case T_TXT:    return Array.map(stringp(entry->txt)? ({entry->txt}):(entry->txt||({})),    lambda(string t) { -  return sprintf("%1c%s", strlen(t), t); +  return sprintf("%1c%s", sizeof(t), t);    })*"";    default:    return "";    }    }       static private string encode_entries(array(mapping) entries, int pos,    mapping(string:int) comp)    {    string res="";    foreach(entries, mapping entry) {    string e = mkname(entry->name, pos, comp)+    sprintf("%2c%2c%4c", entry->type, entry->cl, entry->ttl); -  pos += strlen(e)+2; +  pos += sizeof(e)+2;    string rd = entry->rdata || mkrdata(entry, pos, comp); -  res += e + sprintf("%2c", strlen(rd)) + rd; -  pos += strlen(rd); +  res += e + sprintf("%2c", sizeof(rd)) + rd; +  pos += sizeof(rd);    }    return res;    }       string low_low_mkquery(mapping q)    {    array qd = q->qd && (arrayp(q->qd)? q->qd : ({q->qd}));    array an = q->an && (arrayp(q->an)? q->an : ({q->an}));    array ns = q->ns && (arrayp(q->ns)? q->ns : ({q->ns}));    array ar = q->ar && (arrayp(q->ar)? q->ar : ({q->ar}));    string r = sprintf("%2c%c%c%2c%2c%2c%2c", q->id,    ((q->rd)&1)|(((q->tc)&1)<<1)|(((q->aa)&1)<<2)|    (((q->opcode)&15)<<3)|(((q->qr)&1)<<7),    ((q->rcode)&15)|(((q->cd)&1)<<4)|(((q->ad)&1)<<5)|    (((q->ra)&1)<<7),    qd && sizeof(qd), an && sizeof(an),    ns && sizeof(ns), ar && sizeof(ar));    mapping(string:int) c = ([]);    if(qd)    foreach(qd, mapping _qd) -  r += mkname(_qd->name, strlen(r), c) + +  r += mkname(_qd->name, sizeof(r), c) +    sprintf("%2c%2c", _qd->type, _qd->cl);    if(an) -  r+=encode_entries(an, strlen(r), c); +  r+=encode_entries(an, sizeof(r), c);    if(ns) -  r+=encode_entries(ns, strlen(r), c); +  r+=encode_entries(ns, sizeof(r), c);    if(ar) -  r+=encode_entries(ar, strlen(r), c); +  r+=encode_entries(ar, sizeof(r), c);    return r;    }       string low_mkquery(int id,    string dname,    int cl,    int type)    {    return low_low_mkquery((["id":id, "rd":1,    "qd":(["name":dname, "cl":cl, "type":type])]));
pike.git/lib/modules/Protocols.pmod/DNS.pmod:294:    int decode_int(string s, array(int) next)    {    sscanf(s[next[0]..next[0]+3],"%4c",int ret);    next[0]+=4;    return ret;    }       array decode_entries(string s,int num, array(int) next)    {    array(string) ret=({}); -  for(int e=0;e<num && next[0]<strlen(s);e++) +  for(int e=0;e<num && next[0]<sizeof(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];    switch(m->type)
pike.git/lib/modules/Protocols.pmod/DNS.pmod:395:    m->tc=(m->c1>>1)&1;    m->aa=(m->c1>>2)&1;    m->opcode=(m->c1>>3)&15;    m->qr=(m->c1>>7)&1;       m->rcode=m->c2&15;    m->cd=(m->c2>>4)&1;    m->ad=(m->c2>>5)&1;    m->ra=(m->c2>>7)&1;    -  m->length=strlen(s); +  m->length=sizeof(s);       array(string) tmp=({});    int e;       array(int) next=({12});    m->qd = allocate(m->qdcount);    for(int i=0; i<m->qdcount; i++) {    m->qd[i]=(["name":decode_domain(s,next)]);    sscanf(s[next[0]..next[0]+3],"%2c%2c",m->qd[i]->type, m->qd[i]->cl);    next[0]+=4;