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.75 2003/04/22 21:56:43 nilsson Exp $ + // $Id: DNS.pmod,v 1.76 2003/04/22 22:18:11 marcus 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:116:    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+sizeof(l), comp);    }    }    +  static string make_raw_addr6(string addr6) +  { +  if(!addr6) return "\0"*16; +  if(has_value(addr6, "::")) { +  int parts = sizeof((addr6/":")-({""})); +  if(has_value(addr6, ".")) parts++; +  addr6 = replace(addr6, "::", ":"+"0:"*(8-parts)); +  sscanf(addr6, ":%s", addr6); +  } +  if(has_value(addr6, ".")) +  return sprintf("%2c%2c%2c%2c%2c%2c%c%c%c%c", +  array_sscanf(addr6, "%x:%x:%x:%x:%x:%x:%x.%x.%x.%x")); +  else +  return sprintf("%@2c", +  array_sscanf(addr6, "%x:%x:%x:%x:%x:%x:%x:%x")); +  } +     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);    case T_NS:    return mkname(entry->ns, pos, c);    case T_MD:
pike.git/lib/modules/Protocols.pmod/DNS.pmod:149:    sizeof(entry->os||""), entry->os||"");    case T_MINFO:    string rmailbx = mkname(entry->rmailbx, pos, 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:    return sprintf("%@1c", (array(int))((entry->a||"0.0.0.0")/".")[0..3]);    case T_AAAA: -  string addr6 = entry->a||"::"; -  if(has_value(addr6, "::")) { -  int parts = sizeof((addr6/":")-({""})); -  if(has_value(addr6, ".")) parts++; -  addr6 = replace(addr6, "::", ":"+"0:"*(8-parts)); -  sscanf(addr6, ":%s", addr6); -  } -  if(has_value(addr6, ".")) -  return sprintf("%2c%2c%2c%2c%2c%2c%c%c%c%c", -  array_sscanf(addr6, "%x:%x:%x:%x:%x:%x:%x.%x.%x.%x")); -  else -  return sprintf("%@2c", -  array_sscanf(addr6, "%x:%x:%x:%x:%x:%x:%x:%x")); +  return make_raw_addr6(entry->aaaa);    case T_SOA:    string mname = mkname(entry->mname, pos, 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", sizeof(t), t);    })*"";
pike.git/lib/modules/Protocols.pmod/DNS.pmod:369:    x[2]=x[2][1..];    m->name=x[2..]*".";    }       m->ttl=decode_int(s,next);    break;    case T_A:    m->a=sprintf("%{.%d%}",values(s[next[0]..next[0]+m->len-1]))[1..];    break;    case T_AAAA: -  m->a=sprintf("%{:%02X%02X%}", +  m->aaaa=sprintf("%{:%02X%02X%}",    values(s[next[0]..next[0]+m->len-1])/2)[1..];    break;    case T_SOA:    m->mname=decode_domain(s,next);    m->rname=decode_domain(s,next);    m->serial=decode_int(s,next);    m->refresh=decode_int(s,next);    m->retry=decode_int(s,next);    m->expire=decode_int(s,next);    m->minimum=decode_int(s,next);
pike.git/lib/modules/Protocols.pmod/DNS.pmod:914:    array y=({});    foreach(res, array t)    y+=({t[0]});    sort(y, res);       return res;    }       string arpa_from_ip(string ip)    { +  if(has_value(ip,':')) { +  string raw_ipv6 = make_raw_addr6(ip); +  return reverse(sprintf("%@02X", values(raw_ipv6)))/1*"."+".IP6.ARPA"; +  } else    return reverse(ip/".")*"."+".IN-ADDR.ARPA";    }       string ip_from_arpa(string arpa)    { -  return reverse(arpa/".")[2..]*"."; +  array(string) parts = reverse(arpa/"."); +  if(sizeof(parts)<2) return ""; +  if(lower_case(parts[1]) == "ip6") +  return map(parts[2..]/4, `*, "")*":"; +  else +  return parts[2..]*".";    }       //! @decl array gethostbyaddr(string hostip)    //! Queries the host name or ip from the default or given    //! DNS server. The result is an array with three elements,    //!    //! @returns    //! The requested data about the specified host.    //!    //! @array