Esempio n. 1
0
//we found some ns
//try to find their ip
int
retrive_ip(mbuf_type *mbuf, uchar * itor, int num, uchar * ip, struct htable *ht, int *fq)
{
    struct mvalue *mi = NULL;
    int i, xlen, iplen = IP_DATA_LEN;
    int got = 0;
    uchar *ipbuffer = mbuf->ipbuffer;
    *fq = 0;
    uchar *nstd, *iitor = ip;
    hashval_t hash;
    
    for (i = 0; i < num; i++) {
        xlen = strlen((const char *)itor) + 1;
        nstd = itor;
        itor = itor + xlen;
        hash = 0;
        xlen =
            find_record_with_ttl(ht, nstd, xlen, A, ipbuffer,
                                 iplen - sizeof(struct mvalue), NULL, &hash);
        if (xlen > 0) {
            mi = (struct mvalue *) ipbuffer;
            if (mi->seg > 0)    //segment
                make_A_record_from_segment(ipbuffer, iitor);
            else
                memcpy(iitor, ipbuffer, mi->len + sizeof(struct mvalue));
            iitor = iitor + mi->len + sizeof(struct mvalue);
            iplen = iplen - mi->len - sizeof(struct mvalue);
            got++;
        }
        if (xlen < 0)           //iplen is not enough
        {
            *fq = i;
            break;
        }
    }
    if (iitor != ip)            //found some ip
    {
        mi = (struct mvalue *) iitor;
        mi->num = 0;            //tail 0
        mi->ttl = 0;
        mi->hits = 0;
        mi->len = 0;
        return got;
    }
    return -1;                  //no ip
}
Esempio n. 2
0
//we found some ns
//try to find their ip
int retrive_ip(uchar *itor,int num,uchar *ip,struct htable *ht,int *fq)
{
 struct mvalue *mi = NULL;
 int i,xlen,iplen = IP_DATA_LEN;
 int got = 0;
 uchar ipbuffer[400] = {0};
 *fq = 0;
 uchar nstd[512] = {0},*iitor = ip;
 for(i = 0;i < num;i ++)
	{
	 nstd[0] = A; //NS's A
	 xlen = strlen(itor) + 1;
	 memcpy(nstd + 1,itor,xlen);
	 itor = itor + xlen;
	 xlen = find_record_with_ttl(ht,nstd,ipbuffer,iplen - sizeof(struct mvalue),NULL);
	 if(xlen > 0)
		{
		 mi = (struct mvalue*)ipbuffer;
		 if(mi->seg > 0) //segment
			make_A_record_from_segment(ipbuffer);
		 //after make_A_xxxx
		 //ipbuffer changed and mi changed too
		 memcpy(iitor,ipbuffer,mi->len + sizeof(struct mvalue));
		 iitor = iitor + mi->len + sizeof(struct mvalue);
		 iplen = iplen - mi->len - sizeof(struct mvalue);
		 got ++;
		}
	 if(xlen < 0) //iplen is not enough
		{
		 *fq = i;
		 break;
		}
	}
 if(iitor != ip) //found some ip
	{
	 mi = (struct mvalue*)iitor;
	 mi->num = 0; //tail 0
	 mi->ttl = 0;
	 mi->hits = 0;
	 mi->len = 0;
	 return got;
	}
 return -1; //no ip
}