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.69 2002/12/01 22:54:25 nilsson Exp $ + // $Id: DNS.pmod,v 1.70 2002/12/23 18:59:54 grubba Exp $   // Not yet finished -- Fredrik Hubinette      //! Domain Name System   //! RFC 1035      #pike __REAL_VERSION__      constant NOERROR=0;   constant FORMERR=1;   constant SERVFAIL=2;   constant NXDOMAIN=3;   constant NOTIMPL=4;   constant NXRRSET=8;      constant QUERY=0;    -  + //! Resource classes + enum ResourceClass + {    //! Class Internet - constant C_IN=1; +  C_IN=1,    -  +  //! Class CSNET (Obsolete) +  C_CS=2, +     //! Class CHAOS - constant C_CH=3; +  C_CH=3,       //! Class Hesiod - constant C_HS=4; +  C_HS=4,       //! Class ANY - constant C_ANY=255; +  C_ANY=255, + };    -  + //! Entry types + enum EntryType + {    //! Type - host address - constant T_A=1; +  T_A=1,       //! Type - authoritative name server - constant T_NS=2; +  T_NS=2,       //! Type - mail destination (Obsolete - use MX) - constant T_MD=3; +  T_MD=3,       //! Type - mail forwarder (Obsolete - use MX) - constant T_MF=4; +  T_MF=4,       //! Type - canonical name for an alias - constant T_CNAME=5; +  T_CNAME=5,       //! Type - start of a zone of authority - constant T_SOA=6; +  T_SOA=6,       //! Type - mailbox domain name (EXPERIMENTAL) - constant T_MB=7; +  T_MB=7,       //! Type - mail group member (EXPERIMENTAL) - constant T_MG=8; +  T_MG=8,       //! Type - mail rename domain name (EXPERIMENTAL) - constant T_MR=9; +  T_MR=9,       //! Type - null RR (EXPERIMENTAL) - constant T_NULL=10; +  T_NULL=10,       //! Type - well known service description - constant T_WKS=11; +  T_WKS=11,       //! Type - domain name pointer - constant T_PTR=12; +  T_PTR=12,       //! Type - host information - constant T_HINFO=13; +  T_HINFO=13,       //! Type - mailbox or mail list information - constant T_MINFO=14; +  T_MINFO=14,       //! Type - mail exchange - constant T_MX=15; +  T_MX=15,       //! Type - text strings - constant T_TXT=16; +  T_TXT=16,       //! Type - IPv6 address record (RFC 1886, deprecated) - constant T_AAAA=28; +  T_AAAA=28,       //! Type - Service location record (RFC 2782) - constant T_SRV=33; +  T_SRV=33,       //! Type - IPv6 address record (RFC 2874, incomplete support) - constant T_A6=38; +  T_A6=38, + };      //! Low level DNS protocol   class protocol   {    string mklabel(string s)    {    if(strlen(s)>63)    error("Too long component in domain name.\n");    return sprintf("%c%s",strlen(s),s);    }
pike.git/lib/modules/Protocols.pmod/DNS.pmod:403:    sscanf(s[next[0]..next[0]+3],"%2c%2c",m->qd[i]->type, m->qd[i]->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;    }   };    + //! Implements a Domain Name Service (DNS) server.   class server   {    inherit protocol;    inherit Stdio.UDP : udp;       static void send_reply(mapping r, mapping q, mapping m)    {    // FIXME: Needs to handle truncation somehow.    if(!r)    r = (["rcode":4]);    r->id = q->id;    r->qr = 1;    r->opcode = q->opcode;    r->rd = q->rd;    r->qd = r->qd || q->qd;    string s = mkquery(r);    udp::send(m->ip, m->port, s);    }    -  static mapping reply_query(mapping q, mapping m) +  //! Reply to a query (stub). +  //! +  //! @param query +  //! Parsed query. +  //! +  //! @param udp_data +  //! Raw UDP data. +  //! +  //! Overload this function to implement the proper lookup. +  //! +  //! @returns +  //! Returns @tt{0@} (zero) on failure, or a result mapping on success: +  //! @mapping +  //! @member int "rcode" +  //! @member array(mapping(string:string|int))|void "qd" +  //! @array +  //! @elem mapping(string:string|int) entry +  //! @mapping +  //! @member string|array(string) "name" +  //! @member int "type" +  //! @member int "cl" +  //! @endmapping +  //! @endarray +  //! @member array|void "an" +  //! @member array|void "ns" +  //! @member array|void "ar" +  //! @endmapping +  static mapping reply_query(mapping query, mapping udp_data)    {    // Override this function.    //    // Return mapping may contain:    // aa, ra, {ad, cd,} rcode, an, ns, ar       return 0;    }       static void handle_query(mapping q, mapping m)