Exemple #1
0
uint8_t *dns_packet_append_name_compressed(struct dns_packet *p, const char *name, uint8_t *prev) {
    uint8_t *d;
    signed long k;
    assert(p);

    if (!prev)
        return dns_packet_append_name(p, name);
    
    k = prev - p->data;
    if (k < 0 || k >= 0x4000 || (size_t) k >= p->size)
        return dns_packet_append_name(p, name);

    d = dns_packet_extend(p, sizeof(uint16_t));
    SET_16_P(d, htons((0xC000 | k)));
    
    return prev;
}
Exemple #2
0
Fichier : dns.c Projet : acml/cvsnt
uint8_t *dns_packet_append_name_compressed(struct dns_packet *p, const char *name, uint8_t *prev)
{
    int8_t *d;
    ptrdiff_t k;
	uint16_t u;

	assert(p);

    if (!prev)
        return dns_packet_append_name(p, name);
    
    k = prev - p->data;
    if (k < 0 || k >= 0x4000 || (size_t) k >= p->size)
        return dns_packet_append_name(p, name);

    d = dns_packet_extend(p, sizeof(uint16_t));
	u=htons((0xC000 | (u_short)k));
	memcpy(d,&u,sizeof(u));
    
    return prev;
}