Exemplo n.º 1
0
/** 
    Return 1 on success, 0 on failure. 
 */
int _rrparse(struct message *m, struct resource *rr, int count, unsigned char **bufp)
{
    int i;
    for(i=0; i < count; i++)
    {
        _label(m, bufp, &(rr[i].name));
        rr[i].type = net2short(bufp);
        rr[i].rr_class = net2short(bufp);
        rr[i].ttl = net2long(bufp);
        rr[i].rdlength = net2short(bufp);

        // if not going to overflow, make copy of source rdata
        if(rr[i].rdlength + (*bufp - m->_buf) > MAX_PACKET_LEN || m->_len + rr[i].rdlength > MAX_PACKET_LEN) return 0;
        rr[i].rdata = m->_packet + m->_len;
        m->_len += rr[i].rdlength;
        memcpy(rr[i].rdata,*bufp,rr[i].rdlength);

        // parse commonly known ones
        switch(rr[i].type)
        {
        case 1:
            if(m->_len + 16 > MAX_PACKET_LEN) return 0;
            rr[i].known.a.name = m->_packet + m->_len;
            m->_len += 16;
            sprintf(rr[i].known.a.name,"%d.%d.%d.%d",(*bufp)[0],(*bufp)[1],(*bufp)[2],(*bufp)[3]);
            rr[i].known.a.ip = net2long(bufp);
            break;
        case 2:
            _label(m, bufp, &(rr[i].known.ns.name));
            break;
        case 5:
            _label(m, bufp, &(rr[i].known.cname.name));
            break;
        case 12:
            _label(m, bufp, &(rr[i].known.ptr.name));
            break;
        case 33:
            rr[i].known.srv.priority = net2short(bufp);
            rr[i].known.srv.weight = net2short(bufp);
            rr[i].known.srv.port = net2short(bufp);
            _label(m, bufp, &(rr[i].known.srv.name));
            break;            
        default:
            *bufp += rr[i].rdlength;
        }
    }

    return 1;
}
Exemplo n.º 2
0
void message_parse(struct message *m, unsigned char *packet)
{
    unsigned char *buf;
    int i;
    
    if(packet == 0 || m == 0) return;

    // keep all our mem in one (aligned) block for easy freeing    
    #define my(x,y) while(m->_len&7) m->_len++; x = (void*)(m->_packet + m->_len); m->_len += y;

    // header stuff bit crap
    m->_buf = buf = packet;
    m->id = net2short(&buf);
    if(buf[0] & 0x80) m->header.qr = 1;
    m->header.opcode = (buf[0] & 0x78) >> 3;
    if(buf[0] & 0x04) m->header.aa = 1;
    if(buf[0] & 0x02) m->header.tc = 1;
    if(buf[0] & 0x01) m->header.rd = 1;
    if(buf[1] & 0x80) m->header.ra = 1;
    m->header.z = (buf[1] & 0x70) >> 4;
    m->header.rcode = buf[1] & 0x0F;
    buf += 2;
    m->qdcount = net2short(&buf);
    if(m->_len + (sizeof(struct question) * m->qdcount) > MAX_PACKET_LEN - 8) { m->qdcount = 0; return; }
    m->ancount = net2short(&buf);
    if(m->_len + (sizeof(struct resource) * m->ancount) > MAX_PACKET_LEN - 8) { m->ancount = 0; return; }
    m->nscount = net2short(&buf);
    if(m->_len + (sizeof(struct resource) * m->nscount) > MAX_PACKET_LEN - 8) { m->nscount = 0; return; }
    m->arcount = net2short(&buf);
    if(m->_len + (sizeof(struct resource) * m->arcount) > MAX_PACKET_LEN - 8) { m->arcount = 0; return; }

    // process questions
    my(m->qd, sizeof(struct question) * m->qdcount);
    
    for(i=0; i < m->qdcount; i++)
    {
        _label(m, &buf, &(m->qd[i].name));
        m->qd[i].type = net2short(&buf);
        m->qd[i].rr_class = net2short(&buf);
    }

    // process rrs
    my(m->an, sizeof(struct resource) * m->ancount);
    my(m->ns, sizeof(struct resource) * m->nscount);
    my(m->ar, sizeof(struct resource) * m->arcount);
    if(! _rrparse(m,m->an,m->ancount,&buf))
      m->ancount = 0; // some error in parsing, set those counts to 0
    if(! _rrparse(m,m->ns,m->nscount,&buf)) 
      m->nscount = 0;
    if(! _rrparse(m,m->ar,m->arcount,&buf)) 
      m->arcount = 0;
}
Exemplo n.º 3
0
void MT_ExperimentDataFile::registerFile(
    const char* label,
    const char* filename)
{
    std::string _label(label);
    std::string _filename(filename);

    /* the label can't have any spaces */
    _label = MT_ReplaceSpacesInString(_label);
    /* store the filename as relative to the XDF */
    std::string rel_filename = MT_CalculateRelativePath(filename,
                                                        m_XMLFile.GetFilename());

    MT_AddOrReplaceNodeValue(getFilesNode(), _label.c_str(), rel_filename.c_str());
}
Exemplo n.º 4
0
bool MT_ExperimentDataFile::writeParameterToXML(const char* param_name,
                                             const char* value)
{
    if(m_bStatus == MT_XDF_ERROR)
    {
        return setError();
    }

    std::string _label(param_name);

    /* the label can't have any spaces */
    _label = MT_ReplaceSpacesInString(_label);

    MT_AddOrReplaceNodeValue(getParametersNode(), _label.c_str(), value);

    /* save the file */
    m_XMLFile.SaveFile();

    return setOK();
}