Lines Matching refs:p
40 AvahiDnsPacket *p; in avahi_dns_packet_new() local
53 if (!(p = avahi_malloc(sizeof(AvahiDnsPacket) + max_size))) in avahi_dns_packet_new()
54 return p; in avahi_dns_packet_new()
56 p->size = p->rindex = AVAHI_DNS_PACKET_HEADER_SIZE; in avahi_dns_packet_new()
57 p->max_size = max_size; in avahi_dns_packet_new()
58 p->name_table = NULL; in avahi_dns_packet_new()
59 p->data = NULL; in avahi_dns_packet_new()
61 memset(AVAHI_DNS_PACKET_DATA(p), 0, p->size); in avahi_dns_packet_new()
62 return p; in avahi_dns_packet_new()
66 AvahiDnsPacket *p; in avahi_dns_packet_new_query() local
68 if (!(p = avahi_dns_packet_new(mtu))) in avahi_dns_packet_new_query()
71 …avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_FLAGS, AVAHI_DNS_FLAGS(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)… in avahi_dns_packet_new_query()
72 return p; in avahi_dns_packet_new_query()
76 AvahiDnsPacket *p; in avahi_dns_packet_new_response() local
78 if (!(p = avahi_dns_packet_new(mtu))) in avahi_dns_packet_new_response()
81 …avahi_dns_packet_set_field(p, AVAHI_DNS_FIELD_FLAGS, AVAHI_DNS_FLAGS(1, 0, aa, 0, 0, 0, 0, 0, 0, 0… in avahi_dns_packet_new_response()
82 return p; in avahi_dns_packet_new_response()
85 AvahiDnsPacket* avahi_dns_packet_new_reply(AvahiDnsPacket* p, unsigned mtu, int copy_queries, int a… in avahi_dns_packet_new_reply() argument
87 assert(p); in avahi_dns_packet_new_reply()
96 saved_rindex = p->rindex; in avahi_dns_packet_new_reply()
97 p->rindex = AVAHI_DNS_PACKET_HEADER_SIZE; in avahi_dns_packet_new_reply()
99 for (n = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_QDCOUNT); n > 0; n--) { in avahi_dns_packet_new_reply()
103 if ((k = avahi_dns_packet_consume_key(p, &unicast_response))) { in avahi_dns_packet_new_reply()
109 p->rindex = saved_rindex; in avahi_dns_packet_new_reply()
111 …avahi_dns_packet_set_field(r, AVAHI_DNS_FIELD_QDCOUNT, avahi_dns_packet_get_field(p, AVAHI_DNS_FIE… in avahi_dns_packet_new_reply()
114 …avahi_dns_packet_set_field(r, AVAHI_DNS_FIELD_ID, avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_ID… in avahi_dns_packet_new_reply()
118 … (avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_FLAGS) & AVAHI_DNS_FLAG_OPCODE)); in avahi_dns_packet_new_reply()
124 void avahi_dns_packet_free(AvahiDnsPacket *p) { in avahi_dns_packet_free() argument
125 assert(p); in avahi_dns_packet_free()
127 if (p->name_table) in avahi_dns_packet_free()
128 avahi_hashmap_free(p->name_table); in avahi_dns_packet_free()
130 avahi_free(p); in avahi_dns_packet_free()
133 void avahi_dns_packet_set_field(AvahiDnsPacket *p, unsigned idx, uint16_t v) { in avahi_dns_packet_set_field() argument
134 assert(p); in avahi_dns_packet_set_field()
137 ((uint16_t*) AVAHI_DNS_PACKET_DATA(p))[idx] = htons(v); in avahi_dns_packet_set_field()
140 uint16_t avahi_dns_packet_get_field(AvahiDnsPacket *p, unsigned idx) { in avahi_dns_packet_get_field() argument
141 assert(p); in avahi_dns_packet_get_field()
144 return ntohs(((uint16_t*) AVAHI_DNS_PACKET_DATA(p))[idx]); in avahi_dns_packet_get_field()
147 void avahi_dns_packet_inc_field(AvahiDnsPacket *p, unsigned idx) { in avahi_dns_packet_inc_field() argument
148 assert(p); in avahi_dns_packet_inc_field()
151 avahi_dns_packet_set_field(p, idx, avahi_dns_packet_get_field(p, idx) + 1); in avahi_dns_packet_inc_field()
156 AvahiDnsPacket *p = user_data; in name_table_cleanup() local
158 if ((uint8_t*) value >= AVAHI_DNS_PACKET_DATA(p) + p->size) in name_table_cleanup()
159 avahi_hashmap_remove(p->name_table, key); in name_table_cleanup()
162 void avahi_dns_packet_cleanup_name_table(AvahiDnsPacket *p) { in avahi_dns_packet_cleanup_name_table() argument
163 if (p->name_table) in avahi_dns_packet_cleanup_name_table()
164 avahi_hashmap_foreach(p->name_table, name_table_cleanup, p); in avahi_dns_packet_cleanup_name_table()
167 uint8_t* avahi_dns_packet_append_name(AvahiDnsPacket *p, const char *name) { in avahi_dns_packet_append_name() argument
171 assert(p); in avahi_dns_packet_append_name()
174 saved_size = p->size; in avahi_dns_packet_append_name()
175 saved_ptr = avahi_dns_packet_extend(p, 0); in avahi_dns_packet_append_name()
184 if (p->name_table && (prev = avahi_hashmap_lookup(p->name_table, name))) { in avahi_dns_packet_append_name()
187 assert(prev >= AVAHI_DNS_PACKET_DATA(p)); in avahi_dns_packet_append_name()
188 idx = (unsigned) (prev - AVAHI_DNS_PACKET_DATA(p)); in avahi_dns_packet_append_name()
190 assert(idx < p->size); in avahi_dns_packet_append_name()
194 if (!(t = (uint8_t*) avahi_dns_packet_extend(p, sizeof(uint16_t)))) in avahi_dns_packet_append_name()
208 if (!(d = avahi_dns_packet_append_string(p, label))) in avahi_dns_packet_append_name()
211 if (!p->name_table) in avahi_dns_packet_append_name()
213 … p->name_table = avahi_hashmap_new(avahi_string_hash, avahi_string_equal, avahi_free, NULL); in avahi_dns_packet_append_name()
218 avahi_hashmap_insert(p->name_table, u, d); in avahi_dns_packet_append_name()
221 if (!(d = avahi_dns_packet_extend(p, 1))) in avahi_dns_packet_append_name()
229 p->size = saved_size; in avahi_dns_packet_append_name()
230 avahi_dns_packet_cleanup_name_table(p); in avahi_dns_packet_append_name()
235 uint8_t* avahi_dns_packet_append_uint16(AvahiDnsPacket *p, uint16_t v) { in avahi_dns_packet_append_uint16() argument
237 assert(p); in avahi_dns_packet_append_uint16()
239 if (!(d = avahi_dns_packet_extend(p, sizeof(uint16_t)))) in avahi_dns_packet_append_uint16()
247 uint8_t *avahi_dns_packet_append_uint32(AvahiDnsPacket *p, uint32_t v) { in avahi_dns_packet_append_uint32() argument
249 assert(p); in avahi_dns_packet_append_uint32()
251 if (!(d = avahi_dns_packet_extend(p, sizeof(uint32_t)))) in avahi_dns_packet_append_uint32()
262 uint8_t *avahi_dns_packet_append_bytes(AvahiDnsPacket *p, const void *b, size_t l) { in avahi_dns_packet_append_bytes() argument
265 assert(p); in avahi_dns_packet_append_bytes()
269 if (!(d = avahi_dns_packet_extend(p, l))) in avahi_dns_packet_append_bytes()
276 uint8_t* avahi_dns_packet_append_string(AvahiDnsPacket *p, const char *s) { in avahi_dns_packet_append_string() argument
280 assert(p); in avahi_dns_packet_append_string()
286 if (!(d = avahi_dns_packet_extend(p, k+1))) in avahi_dns_packet_append_string()
295 uint8_t *avahi_dns_packet_extend(AvahiDnsPacket *p, size_t l) { in avahi_dns_packet_extend() argument
298 assert(p); in avahi_dns_packet_extend()
300 if (p->size+l > p->max_size) in avahi_dns_packet_extend()
303 d = AVAHI_DNS_PACKET_DATA(p) + p->size; in avahi_dns_packet_extend()
304 p->size += l; in avahi_dns_packet_extend()
309 int avahi_dns_packet_check_valid(AvahiDnsPacket *p) { in avahi_dns_packet_check_valid() argument
311 assert(p); in avahi_dns_packet_check_valid()
313 if (p->size < AVAHI_DNS_PACKET_HEADER_SIZE) in avahi_dns_packet_check_valid()
316 flags = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_FLAGS); in avahi_dns_packet_check_valid()
324 int avahi_dns_packet_check_valid_multicast(AvahiDnsPacket *p) { in avahi_dns_packet_check_valid_multicast() argument
326 assert(p); in avahi_dns_packet_check_valid_multicast()
328 if (avahi_dns_packet_check_valid(p) < 0) in avahi_dns_packet_check_valid_multicast()
331 flags = avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_FLAGS); in avahi_dns_packet_check_valid_multicast()
339 int avahi_dns_packet_is_query(AvahiDnsPacket *p) { in avahi_dns_packet_is_query() argument
340 assert(p); in avahi_dns_packet_is_query()
342 return !(avahi_dns_packet_get_field(p, AVAHI_DNS_FIELD_FLAGS) & AVAHI_DNS_FLAG_QR); in avahi_dns_packet_is_query()
345 static int consume_labels(AvahiDnsPacket *p, unsigned idx, char *ret_name, size_t l) { in consume_labels() argument
351 assert(p && ret_name && l); in consume_labels()
356 if (idx+1 > p->size) in consume_labels()
359 n = AVAHI_DNS_PACKET_DATA(p)[idx]; in consume_labels()
378 if (idx + n > p->size) in consume_labels()
390 if (!(avahi_escape_label((char*) AVAHI_DNS_PACKET_DATA(p) + idx, n, &ret_name, &l))) in consume_labels()
400 if (idx+2 > p->size) in consume_labels()
403 …label_ptr = ((unsigned) (AVAHI_DNS_PACKET_DATA(p)[idx] & ~0xC0)) << 8 | AVAHI_DNS_PACKET_DATA(p)[i… in consume_labels()
421 int avahi_dns_packet_consume_name(AvahiDnsPacket *p, char *ret_name, size_t l) { in avahi_dns_packet_consume_name() argument
424 if ((r = consume_labels(p, p->rindex, ret_name, l)) < 0) in avahi_dns_packet_consume_name()
427 p->rindex += r; in avahi_dns_packet_consume_name()
431 int avahi_dns_packet_consume_uint16(AvahiDnsPacket *p, uint16_t *ret_v) { in avahi_dns_packet_consume_uint16() argument
434 assert(p); in avahi_dns_packet_consume_uint16()
437 if (p->rindex + sizeof(uint16_t) > p->size) in avahi_dns_packet_consume_uint16()
440 d = (uint8_t*) (AVAHI_DNS_PACKET_DATA(p) + p->rindex); in avahi_dns_packet_consume_uint16()
442 p->rindex += sizeof(uint16_t); in avahi_dns_packet_consume_uint16()
447 int avahi_dns_packet_consume_uint32(AvahiDnsPacket *p, uint32_t *ret_v) { in avahi_dns_packet_consume_uint32() argument
450 assert(p); in avahi_dns_packet_consume_uint32()
453 if (p->rindex + sizeof(uint32_t) > p->size) in avahi_dns_packet_consume_uint32()
456 d = (uint8_t*) (AVAHI_DNS_PACKET_DATA(p) + p->rindex); in avahi_dns_packet_consume_uint32()
458 p->rindex += sizeof(uint32_t); in avahi_dns_packet_consume_uint32()
463 int avahi_dns_packet_consume_bytes(AvahiDnsPacket *p, void * ret_data, size_t l) { in avahi_dns_packet_consume_bytes() argument
464 assert(p); in avahi_dns_packet_consume_bytes()
468 if (p->rindex + l > p->size) in avahi_dns_packet_consume_bytes()
471 memcpy(ret_data, AVAHI_DNS_PACKET_DATA(p) + p->rindex, l); in avahi_dns_packet_consume_bytes()
472 p->rindex += l; in avahi_dns_packet_consume_bytes()
477 int avahi_dns_packet_consume_string(AvahiDnsPacket *p, char *ret_string, size_t l) { in avahi_dns_packet_consume_string() argument
480 assert(p); in avahi_dns_packet_consume_string()
484 if (p->rindex >= p->size) in avahi_dns_packet_consume_string()
487 k = AVAHI_DNS_PACKET_DATA(p)[p->rindex]; in avahi_dns_packet_consume_string()
489 if (p->rindex+1+k > p->size) in avahi_dns_packet_consume_string()
495 memcpy(ret_string, AVAHI_DNS_PACKET_DATA(p)+p->rindex+1, l-1); in avahi_dns_packet_consume_string()
498 p->rindex += 1+k; in avahi_dns_packet_consume_string()
503 const void* avahi_dns_packet_get_rptr(AvahiDnsPacket *p) { in avahi_dns_packet_get_rptr() argument
504 assert(p); in avahi_dns_packet_get_rptr()
506 if (p->rindex > p->size) in avahi_dns_packet_get_rptr()
509 return AVAHI_DNS_PACKET_DATA(p) + p->rindex; in avahi_dns_packet_get_rptr()
512 int avahi_dns_packet_skip(AvahiDnsPacket *p, size_t length) { in avahi_dns_packet_skip() argument
513 assert(p); in avahi_dns_packet_skip()
515 if (p->rindex + length > p->size) in avahi_dns_packet_skip()
518 p->rindex += length; in avahi_dns_packet_skip()
522 static int parse_rdata(AvahiDnsPacket *p, AvahiRecord *r, uint16_t rdlength) { in parse_rdata() argument
526 assert(p); in parse_rdata()
529 start = avahi_dns_packet_get_rptr(p); in parse_rdata()
536 if (avahi_dns_packet_consume_name(p, buf, sizeof(buf)) < 0) in parse_rdata()
545 if (avahi_dns_packet_consume_uint16(p, &r->data.srv.priority) < 0 || in parse_rdata()
546 avahi_dns_packet_consume_uint16(p, &r->data.srv.weight) < 0 || in parse_rdata()
547 avahi_dns_packet_consume_uint16(p, &r->data.srv.port) < 0 || in parse_rdata()
548 avahi_dns_packet_consume_name(p, buf, sizeof(buf)) < 0) in parse_rdata()
556 if (avahi_dns_packet_consume_string(p, buf, sizeof(buf)) < 0) in parse_rdata()
561 if (avahi_dns_packet_consume_string(p, buf, sizeof(buf)) < 0) in parse_rdata()
570 … if (avahi_string_list_parse(avahi_dns_packet_get_rptr(p), rdlength, &r->data.txt.string_list) < 0) in parse_rdata()
573 if (avahi_dns_packet_skip(p, rdlength) < 0) in parse_rdata()
584 if (avahi_dns_packet_consume_bytes(p, &r->data.a.address, sizeof(AvahiIPv4Address)) < 0) in parse_rdata()
593 … if (avahi_dns_packet_consume_bytes(p, &r->data.aaaa.address, sizeof(AvahiIPv6Address)) < 0) in parse_rdata()
604 r->data.generic.data = avahi_memdup(avahi_dns_packet_get_rptr(p), rdlength); in parse_rdata()
607 if (avahi_dns_packet_skip(p, rdlength) < 0) in parse_rdata()
615 if ((const uint8_t*) avahi_dns_packet_get_rptr(p) - (const uint8_t*) start != rdlength) in parse_rdata()
621 AvahiRecord* avahi_dns_packet_consume_record(AvahiDnsPacket *p, int *ret_cache_flush) { in avahi_dns_packet_consume_record() argument
628 assert(p); in avahi_dns_packet_consume_record()
630 if (avahi_dns_packet_consume_name(p, name, sizeof(name)) < 0 || in avahi_dns_packet_consume_record()
631 avahi_dns_packet_consume_uint16(p, &type) < 0 || in avahi_dns_packet_consume_record()
632 avahi_dns_packet_consume_uint16(p, &class) < 0 || in avahi_dns_packet_consume_record()
633 avahi_dns_packet_consume_uint32(p, &ttl) < 0 || in avahi_dns_packet_consume_record()
634 avahi_dns_packet_consume_uint16(p, &rdlength) < 0 || in avahi_dns_packet_consume_record()
635 p->rindex + rdlength > p->size) in avahi_dns_packet_consume_record()
645 if (parse_rdata(p, r, rdlength) < 0) in avahi_dns_packet_consume_record()
660 AvahiKey* avahi_dns_packet_consume_key(AvahiDnsPacket *p, int *ret_unicast_response) { in avahi_dns_packet_consume_key() argument
665 assert(p); in avahi_dns_packet_consume_key()
667 if (avahi_dns_packet_consume_name(p, name, sizeof(name)) < 0 || in avahi_dns_packet_consume_key()
668 avahi_dns_packet_consume_uint16(p, &type) < 0 || in avahi_dns_packet_consume_key()
669 avahi_dns_packet_consume_uint16(p, &class) < 0) in avahi_dns_packet_consume_key()
688 uint8_t* avahi_dns_packet_append_key(AvahiDnsPacket *p, AvahiKey *k, int unicast_response) { in avahi_dns_packet_append_key() argument
692 assert(p); in avahi_dns_packet_append_key()
695 size = p->size; in avahi_dns_packet_append_key()
697 if (!(t = avahi_dns_packet_append_name(p, k->name)) || in avahi_dns_packet_append_key()
698 !avahi_dns_packet_append_uint16(p, k->type) || in avahi_dns_packet_append_key()
699 …!avahi_dns_packet_append_uint16(p, k->clazz | (unicast_response ? AVAHI_DNS_UNICAST_RESPONSE : 0))… in avahi_dns_packet_append_key()
700 p->size = size; in avahi_dns_packet_append_key()
701 avahi_dns_packet_cleanup_name_table(p); in avahi_dns_packet_append_key()
709 static int append_rdata(AvahiDnsPacket *p, AvahiRecord *r) { in append_rdata() argument
710 assert(p); in append_rdata()
719 if (!(avahi_dns_packet_append_name(p, r->data.ptr.name))) in append_rdata()
726 if (!avahi_dns_packet_append_uint16(p, r->data.srv.priority) || in append_rdata()
727 !avahi_dns_packet_append_uint16(p, r->data.srv.weight) || in append_rdata()
728 !avahi_dns_packet_append_uint16(p, r->data.srv.port) || in append_rdata()
729 !avahi_dns_packet_append_name(p, r->data.srv.name)) in append_rdata()
735 if (!avahi_dns_packet_append_string(p, r->data.hinfo.cpu) || in append_rdata()
736 !avahi_dns_packet_append_string(p, r->data.hinfo.os)) in append_rdata()
748 if (!(data = avahi_dns_packet_extend(p, n))) in append_rdata()
758 if (!avahi_dns_packet_append_bytes(p, &r->data.a.address, sizeof(r->data.a.address))) in append_rdata()
765 … if (!avahi_dns_packet_append_bytes(p, &r->data.aaaa.address, sizeof(r->data.aaaa.address))) in append_rdata()
773 if (!avahi_dns_packet_append_bytes(p, r->data.generic.data, r->data.generic.size)) in append_rdata()
783 uint8_t* avahi_dns_packet_append_record(AvahiDnsPacket *p, AvahiRecord *r, int cache_flush, unsigne… in avahi_dns_packet_append_record() argument
787 assert(p); in avahi_dns_packet_append_record()
790 size = p->size; in avahi_dns_packet_append_record()
792 if (!(t = avahi_dns_packet_append_name(p, r->key->name)) || in avahi_dns_packet_append_record()
793 !avahi_dns_packet_append_uint16(p, r->key->type) || in avahi_dns_packet_append_record()
794 …!avahi_dns_packet_append_uint16(p, cache_flush ? (r->key->clazz | AVAHI_DNS_CACHE_FLUSH) : (r->key… in avahi_dns_packet_append_record()
795 !avahi_dns_packet_append_uint32(p, (max_ttl && r->ttl > max_ttl) ? max_ttl : r->ttl) || in avahi_dns_packet_append_record()
796 !(l = avahi_dns_packet_append_uint16(p, 0))) in avahi_dns_packet_append_record()
799 start = avahi_dns_packet_extend(p, 0); in avahi_dns_packet_append_record()
801 if (append_rdata(p, r) < 0) in avahi_dns_packet_append_record()
804 size = avahi_dns_packet_extend(p, 0) - start; in avahi_dns_packet_append_record()
816 p->size = size; in avahi_dns_packet_append_record()
817 avahi_dns_packet_cleanup_name_table(p); in avahi_dns_packet_append_record()
822 int avahi_dns_packet_is_empty(AvahiDnsPacket *p) { in avahi_dns_packet_is_empty() argument
823 assert(p); in avahi_dns_packet_is_empty()
825 return p->size <= AVAHI_DNS_PACKET_HEADER_SIZE; in avahi_dns_packet_is_empty()
828 size_t avahi_dns_packet_space(AvahiDnsPacket *p) { in avahi_dns_packet_space() argument
829 assert(p); in avahi_dns_packet_space()
831 assert(p->size <= p->max_size); in avahi_dns_packet_space()
833 return p->max_size - p->size; in avahi_dns_packet_space()
838 AvahiDnsPacket p; in avahi_rdata_parse() local
843 p.data = (void*) rdata; in avahi_rdata_parse()
844 p.max_size = p.size = size; in avahi_rdata_parse()
845 p.rindex = 0; in avahi_rdata_parse()
846 p.name_table = NULL; in avahi_rdata_parse()
848 ret = parse_rdata(&p, record, size); in avahi_rdata_parse()
850 assert(!p.name_table); in avahi_rdata_parse()
857 AvahiDnsPacket p; in avahi_rdata_serialize() local
863 p.data = (void*) rdata; in avahi_rdata_serialize()
864 p.max_size = max_size; in avahi_rdata_serialize()
865 p.size = p.rindex = 0; in avahi_rdata_serialize()
866 p.name_table = NULL; in avahi_rdata_serialize()
868 ret = append_rdata(&p, record); in avahi_rdata_serialize()
870 if (p.name_table) in avahi_rdata_serialize()
871 avahi_hashmap_free(p.name_table); in avahi_rdata_serialize()
876 return p.size; in avahi_rdata_serialize()