示例#1
0
文件: dns.c 项目: DNSPod/dnspod-sr
//jump from author.c
uchar *
fill_rrset_in_msg(struct hlpc * h, uchar * from, uchar * to, int *pn,
                  uchar * hdr)
{
    uchar type;
    int i, step = 0;
    uint16_t txtlen = 0;
    struct hlpf hf;
    int num = 0;
    struct mvalue *mv = NULL;
    int n = *pn;
    type = from[0];
    from++;                     //type
    mv = (struct mvalue *) from;
    from = from + sizeof(struct mvalue);
    num = mv->num;
    if (num > MAX_MSG_SEG) {
        num = MAX_MSG_SEG;
    }
    hf.hdr = hdr;
    hf.ttl = mv->ttl;
    hf.type = type;
    if (type == A)
        step = 4;
    if (type == AAAA)
        step = 16;
    switch (type)               //7
    {
    case A:
    case AAAA:
        for (i = 0; i < num; i++) {
            to = fill_name_in_msg(h, to, n);
            hf.from = from;
            hf.to = to;
            //jump type and dclass
            //then we get ttl's position
            //plus hdr we get it's offset
            //only for A record
            to = fill_all_records_in_msg(h, &hf, pn);
            from += step;
        }
        return to;
        break;
    case CNAME:                // cname must has 1 record
        to = fill_name_in_msg(h, to, n);
        hf.from = from;
        hf.to = to;
        hf.len = strlen((const char *)from) + 1;
        to = fill_all_records_in_msg(h, &hf, pn);
        return to;
        break;
    case NS:
        for (i = 0; i < num; i++) {
//             h[n].len = strlen((const char *)from) + 1;
            to = fill_name_in_msg(h, to, n);
            hf.from = from;
            hf.to = to;
            hf.len = strlen((const char *)from) + 1;
            to = fill_all_records_in_msg(h, &hf, pn);
            from += hf.len;//strlen((const char *)from) + 1;
        }
        return to;
        break;
    case MX:
        for (i = 0; i < num; i++) {
            to = fill_name_in_msg(h, to, n);
            hf.from = from;
            hf.to = to;
            hf.len = strlen((const char *)(from + sizeof(uint16_t))) + 1;
            to = fill_all_records_in_msg(h, &hf, pn);
            from += sizeof(uint16_t);   //jump ref
            from += hf.len;//strlen((const char *)from) + 1;   //jump name and tail 0
        }
        return to;
        break;
    case TXT:
        for (i = 0; i < num; i++) {
            txtlen = *(uint16_t *) from;
            h[n].len = txtlen;
            to = fill_name_in_msg(h, to, n);
            hf.from = from;
            hf.to = to;
            to = fill_all_records_in_msg(h, &hf, pn);
            from = from + txtlen + sizeof(uint16_t);
        }
        return to;
        break;
    case SRV:
        for (i = 0; i < num; i++) {
            to = fill_name_in_msg(h, to, n);
            hf.from = from;
            hf.to = to;
            hf.len = strlen((const char *)(from + sizeof(uint16_t) * 3))  + 1;
            to = fill_all_records_in_msg(h, &hf, pn);
            from += sizeof(uint16_t) * 3;       //pri wei port
            from += hf.len;//strlen((const char *)from) + 1;   //target
        }
        return to;
        break;
    default:
        printf("not support or error in fill msg\n");
        break;
    }
    return NULL;
}
示例#2
0
文件: dns.c 项目: Chairo/dnspod-sr
//jump from author.c
uchar *fill_rrset_in_msg(struct hlpc *h,uchar *from,uchar *to,int n,uchar *hdr,uint16_t *ttloff)
{
 uchar type;
 type = from[0];
 int i,step = 0,ttloffidx;
 uint16_t txtlen = 0;
 struct hlpf hf;
 struct mvalue *mv = NULL;
 ttloffidx = ttloff[0]; //must be 0
 from ++;//type
 mv = (struct mvalue*)from;
 from = from + sizeof(struct mvalue);
 hf.hdr = hdr;
 hf.ttl = mv->ttl;
 hf.type = type;
 if(type == A)
	step = 4;
 if(type == AAAA)
	step = 16;
 switch(type) //7
	{
	 case A: case AAAA:
		for(i = 0;i < mv->num;i ++)
			{
			 to = fill_name_in_msg(h,to,n);
			 hf.from = from;
			 hf.to = to;
			 //jump type and dclass
			 //then we get ttl's position
			 //plus hdr we get it's offset
			 //only for A record
			 if(type == A)
				{
				 //ttloff[0] idx
				 //+1, jump it
				 ttloff[ttloff[0] + 1] = to + sizeof(uint16_t) + sizeof(uint16_t) - hdr;
				 ttloff[0] ++;
				}
			 to = fill_all_records_in_msg(h,&hf,n);
			 from += step;
			}
		return to;
		break;
	 case CNAME: // cname must has 1 record
		 to = fill_name_in_msg(h,to,n);
		 hf.from = from;
		 hf.to = to;
		 to = fill_all_records_in_msg(h,&hf,n);
		 return to;
		 break;
	 case NS:
		for(i = 0;i < mv->num;i ++)
			{
			 to = fill_name_in_msg(h,to,n);
			 hf.from = from;
			 hf.to = to;
			 to = fill_all_records_in_msg(h,&hf,n);
			 from += strlen(from) + 1;
			}
		return to;
		break;
	 case MX:
		for(i = 0;i < mv->num;i ++)
			{
			 to = fill_name_in_msg(h,to,n);
			 hf.from = from;
			 hf.to = to;
			 to = fill_all_records_in_msg(h,&hf,n);
			 from += strlen(from) + 1; //ref and name
			}
		return to;
		break;
	 case TXT:
		for(i = 0;i < mv->num;i ++)
			{
			 to = fill_name_in_msg(h,to,n);
			 hf.from = from;
			 hf.to = to;
			 to = fill_all_records_in_msg(h,&hf,n);
			 txtlen = *(uint16_t*)from;
			 from = from + txtlen + sizeof(uint16_t);
			}
		return to;
		break;
	 case SRV:
		for(i = 0;i < mv->num;i ++)
			{
			 to = fill_name_in_msg(h,to,n);
			 hf.from = from;
			 hf.to = to;
			 to = fill_all_records_in_msg(h,&hf,n);
			 from += sizeof(uint16_t) * 3; //pri wei port
			 from += strlen(from) + 1; //target
			}
		 return to;
		 break;
	 default:
		printf("not support or error in fill msg\n");
		break;
	}
 return NULL;
}