From ef97e32ba2ed98b791af4504103b5f0378bb6b9b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Sun, 20 Nov 2005 00:45:03 +0000 Subject: * bump version number * make nss-mdns shut up * deal with OOM * other cleanups git-svn-id: file:///home/lennart/svn/public/nss-mdns/trunk@87 0ee8848e-81ea-0310-a63a-f631d1a40d77 --- src/dns.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/dns.c') diff --git a/src/dns.c b/src/dns.c index 61c66d8..e7e9765 100644 --- a/src/dns.c +++ b/src/dns.c @@ -34,8 +34,10 @@ struct dns_packet* dns_packet_new(void) { struct dns_packet *p; - p = malloc(sizeof(struct dns_packet)); - assert(p); + + if (!(p = malloc(sizeof(struct dns_packet)))) + return NULL; + p->size = p->rindex = 2*6; memset(p->data, 0, p->size); return p; @@ -47,13 +49,15 @@ void dns_packet_free(struct dns_packet *p) { } void dns_packet_set_field(struct dns_packet *p, unsigned idx, uint16_t v) { - assert(p && idx < 2*6); + assert(p); + assert(idx < 2*6); ((uint16_t*) p->data)[idx] = htons(v); } uint16_t dns_packet_get_field(struct dns_packet *p, unsigned idx) { - assert(p && idx < 2*6); + assert(p); + assert(idx < 2*6); return ntohs(((uint16_t*) p->data)[idx]); } @@ -70,6 +74,7 @@ uint8_t* dns_packet_append_name(struct dns_packet *p, const char *name) { d = dns_packet_extend(p, n+1); if (!f) f = d; + d[0] = n; memcpy(d+1, name, n); @@ -95,8 +100,10 @@ uint8_t* dns_packet_append_name(struct dns_packet *p, const char *name) { uint8_t* dns_packet_append_uint16(struct dns_packet *p, uint16_t v) { uint8_t *d; assert(p); + d = dns_packet_extend(p, sizeof(uint16_t)); *((uint16_t*) d) = htons(v); + return d; } @@ -158,7 +165,6 @@ int dns_packet_check_valid_response(struct dns_packet *p) { return -1; return 0; - } static ssize_t consume_labels(struct dns_packet *p, size_t idx, char *ret_name, size_t l) { -- cgit