LLVMFuzzerTestOneInput:
   25|    614|LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
   26|    614|    if(size >= MAX_PACKET_LEN)
  ------------------
  |  |   60|    614|#define MAX_PACKET_LEN 65535
  ------------------
  |  Branch (26:8): [True: 2, False: 612]
  ------------------
   27|      2|        return 0;
   28|    612|    memcpy(message_buf, data, size);
   29|    612|    message_buf[size] = 0; /* zero terminate */
   30|       |
   31|    612|    struct message m;
   32|    612|    memset(&m, 0, sizeof(struct message));
   33|       |
   34|    612|    int parseResult = message_parse(&m, message_buf);
   35|    612|    if(!parseResult)
  ------------------
  |  Branch (35:8): [True: 409, False: 203]
  ------------------
   36|    409|        return 0;
   37|       |
   38|    203|    mdns_daemon_t *d = mdnsd_new(QCLASS_IN, 1000);
  ------------------
  |  |   40|    203|#define QCLASS_IN (1)
  ------------------
   39|       |
   40|    203|    struct in_addr addr = {};
   41|    203|    mdnsd_in(d, &m, addr, 2000);
   42|    203|    mdnsd_free(d);
   43|       |
   44|    203|    return 0;
   45|    612|}

net2short:
   37|   887k|{
   38|   887k|	unsigned short int i;
   39|       |
   40|   887k|	i = **bufp;
   41|   887k|	i <<= 8;
   42|   887k|	i |= *(*bufp + 1);
   43|   887k|	*bufp += 2;
   44|       |
   45|   887k|	return i;
   46|   887k|}
net2long:
   49|  94.3k|{
   50|  94.3k|	long int l;
   51|       |
   52|  94.3k|	l = **bufp;
   53|  94.3k|	l <<= 8;
   54|  94.3k|	l |= *(*bufp + 1);
   55|  94.3k|	l <<= 8;
   56|  94.3k|	l |= *(*bufp + 2);
   57|  94.3k|	l <<= 8;
   58|  94.3k|	l |= *(*bufp + 3);
   59|  94.3k|	*bufp += 4;
   60|       |
   61|  94.3k|	return l;
   62|  94.3k|}
message_parse:
  348|    612|{
  349|    612|	int i;
  350|    612|	unsigned char *buf;
  351|       |
  352|    612|	if (packet == 0 || m == 0)
  ------------------
  |  Branch (352:6): [True: 0, False: 612]
  |  Branch (352:21): [True: 0, False: 612]
  ------------------
  353|      0|		return 1;
  354|       |
  355|       |	/* Header stuff bit crap */
  356|    612|	m->_buf = buf = packet;
  357|    612|	m->id = net2short(&buf);
  358|    612|	if (buf[0] & 0x80)
  ------------------
  |  Branch (358:6): [True: 327, False: 285]
  ------------------
  359|    327|		m->header.qr = 1;
  360|    612|	m->header.opcode = (buf[0] & 0x78) >> 3;
  361|    612|	if (buf[0] & 0x04)
  ------------------
  |  Branch (361:6): [True: 241, False: 371]
  ------------------
  362|    241|		m->header.aa = 1;
  363|    612|	if (buf[0] & 0x02)
  ------------------
  |  Branch (363:6): [True: 260, False: 352]
  ------------------
  364|    260|		m->header.tc = 1;
  365|    612|	if (buf[0] & 0x01)
  ------------------
  |  Branch (365:6): [True: 297, False: 315]
  ------------------
  366|    297|		m->header.rd = 1;
  367|    612|	if (buf[1] & 0x80)
  ------------------
  |  Branch (367:6): [True: 146, False: 466]
  ------------------
  368|    146|		m->header.ra = 1;
  369|    612|	m->header.z = (buf[1] & 0x70) >> 4;
  370|    612|	m->header.rcode = buf[1] & 0x0F;
  371|    612|	buf += 2;
  372|       |
  373|    612|	m->qdcount = net2short(&buf);
  374|    612|	if (m->_len + (sizeof(struct question) * m->qdcount) > MAX_PACKET_LEN - 8) {
  ------------------
  |  |   60|    612|#define MAX_PACKET_LEN 65535
  ------------------
  |  Branch (374:6): [True: 6, False: 606]
  ------------------
  375|      6|		m->qdcount = 0;
  376|      6|		return 1;
  377|      6|	}
  378|       |
  379|    606|	m->ancount = net2short(&buf);
  380|    606|	if (m->_len + (sizeof(struct resource) * m->ancount) > MAX_PACKET_LEN - 8) {
  ------------------
  |  |   60|    606|#define MAX_PACKET_LEN 65535
  ------------------
  |  Branch (380:6): [True: 25, False: 581]
  ------------------
  381|     25|		m->ancount = 0;
  382|     25|		return 1;
  383|     25|	}
  384|       |
  385|    581|	m->nscount = net2short(&buf);
  386|    581|	if (m->_len + (sizeof(struct resource) * m->nscount) > MAX_PACKET_LEN - 8) {
  ------------------
  |  |   60|    581|#define MAX_PACKET_LEN 65535
  ------------------
  |  Branch (386:6): [True: 6, False: 575]
  ------------------
  387|      6|		m->nscount = 0;
  388|      6|		return 1;
  389|      6|	}
  390|       |
  391|    575|	m->arcount = net2short(&buf);
  392|    575|	if (m->_len + (sizeof(struct resource) * m->arcount) > MAX_PACKET_LEN - 8) {
  ------------------
  |  |   60|    575|#define MAX_PACKET_LEN 65535
  ------------------
  |  Branch (392:6): [True: 6, False: 569]
  ------------------
  393|      6|		m->arcount = 0;
  394|      6|		return 1;
  395|      6|	}
  396|       |
  397|       |	/* Process questions */
  398|    569|	my(m->qd, sizeof(struct question) * m->qdcount);
  ------------------
  |  |  342|    569|	while (m->_len & 7)			\
  |  |  ------------------
  |  |  |  Branch (342:9): [True: 0, False: 569]
  |  |  ------------------
  |  |  343|    569|		m->_len++;			\
  |  |  344|    569|	(x) = (void *)(m->_packet + m->_len);	\
  |  |  345|    569|	m->_len += (y);
  ------------------
  399|   301k|	for (i = 0; i < m->qdcount; i++) {
  ------------------
  |  Branch (399:14): [True: 300k, False: 545]
  ------------------
  400|   300k|		if (_label(m, &buf, &(m->qd[i].name)))
  ------------------
  |  Branch (400:7): [True: 24, False: 300k]
  ------------------
  401|     24|			return 1;
  402|   300k|		m->qd[i].type  = net2short(&buf);
  403|   300k|		m->qd[i].clazz = net2short(&buf);
  404|   300k|	}
  405|       |
  406|       |	/* Process rrs */
  407|    545|	my(m->an, sizeof(struct resource) * m->ancount);
  ------------------
  |  |  342|  1.77k|	while (m->_len & 7)			\
  |  |  ------------------
  |  |  |  Branch (342:9): [True: 1.23k, False: 545]
  |  |  ------------------
  |  |  343|  1.23k|		m->_len++;			\
  |  |  344|    545|	(x) = (void *)(m->_packet + m->_len);	\
  |  |  345|    545|	m->_len += (y);
  ------------------
  408|    545|	my(m->ns, sizeof(struct resource) * m->nscount);
  ------------------
  |  |  342|    545|	while (m->_len & 7)			\
  |  |  ------------------
  |  |  |  Branch (342:9): [True: 0, False: 545]
  |  |  ------------------
  |  |  343|    545|		m->_len++;			\
  |  |  344|    545|	(x) = (void *)(m->_packet + m->_len);	\
  |  |  345|    545|	m->_len += (y);
  ------------------
  409|    545|	my(m->ar, sizeof(struct resource) * m->arcount);
  ------------------
  |  |  342|    545|	while (m->_len & 7)			\
  |  |  ------------------
  |  |  |  Branch (342:9): [True: 0, False: 545]
  |  |  ------------------
  |  |  343|    545|		m->_len++;			\
  |  |  344|    545|	(x) = (void *)(m->_packet + m->_len);	\
  |  |  345|    545|	m->_len += (y);
  ------------------
  410|    545|	if (_rrparse(m, m->an, m->ancount, &buf))
  ------------------
  |  Branch (410:6): [True: 117, False: 428]
  ------------------
  411|    117|		return 1;
  412|    428|	if (_rrparse(m, m->ns, m->nscount, &buf))
  ------------------
  |  Branch (412:6): [True: 13, False: 415]
  ------------------
  413|     13|		return 1;
  414|    415|	if (_rrparse(m, m->ar, m->arcount, &buf))
  ------------------
  |  Branch (414:6): [True: 6, False: 409]
  ------------------
  415|      6|		return 1;
  416|       |
  417|    409|	return 0;
  418|    415|}
1035.c:_label:
   98|   395k|{
   99|   395k|	int x;
  100|   395k|	char *label, *name;
  101|       |
  102|       |
  103|       |	/* Sanity check */
  104|   395k|	if (m->_len > (int)sizeof(m->_packet))
  ------------------
  |  Branch (104:6): [True: 106, False: 395k]
  ------------------
  105|    106|		return 1;
  106|       |
  107|       |	/* Set namep to the end of the block */
  108|   395k|	*namep = name = (char *)m->_packet + m->_len;
  109|       |
  110|       |	/* Loop storing label in the block */
  111|   400k|	for (label = (char *)*bufp; *label != 0; name += *label + 1, label += *label + 1) {
  ------------------
  |  Branch (111:30): [True: 5.10k, False: 395k]
  ------------------
  112|       |		/* Skip past any compression pointers, kick out if end encountered (bad data prolly) */
  113|  5.10k|		int prevOffset = -1;
  114|  5.71k|		while (*label & 0xc0) {
  ------------------
  |  Branch (114:10): [True: 2.06k, False: 3.65k]
  ------------------
  115|  2.06k|			unsigned short int offset = _ldecomp(label);
  116|  2.06k|			if (offset <= prevOffset || offset > m->_len)
  ------------------
  |  Branch (116:8): [True: 14, False: 2.05k]
  |  Branch (116:32): [True: 10, False: 2.04k]
  ------------------
  117|     24|				return 1;
  118|  2.04k|			if (*(label = (char *)m->_buf + offset) == 0)
  ------------------
  |  Branch (118:8): [True: 1.43k, False: 611]
  ------------------
  119|  1.43k|				break;
  120|    611|			prevOffset = offset;
  121|    611|		}
  122|       |
  123|       |		/* Make sure we're not over the limits */
  124|  5.08k|		if ((name + *label) - *namep > 255 || m->_len + ((name + *label) - *namep) >= MAX_PACKET_LEN)
  ------------------
  |  |   60|  5.07k|#define MAX_PACKET_LEN 65535
  ------------------
  |  Branch (124:7): [True: 11, False: 5.07k]
  |  Branch (124:41): [True: 3, False: 5.07k]
  ------------------
  125|     14|			return 1;
  126|       |
  127|       |		/* Copy chars for this label */
  128|  5.07k|		memcpy(name, label + 1, (size_t)*label);
  129|  5.07k|		name[(size_t)*label] = '.';
  130|  5.07k|	}
  131|       |
  132|       |	/* Advance buffer */
  133|   397k|	for (label = (char *)*bufp; *label != 0 && !(*label & 0xc0 && label++); label += *label + 1)
  ------------------
  |  Branch (133:30): [True: 3.07k, False: 394k]
  |  Branch (133:47): [True: 1.25k, False: 1.81k]
  |  Branch (133:64): [True: 1.25k, False: 0]
  ------------------
  134|  1.81k|		;
  135|   395k|	*bufp = (unsigned char *)(label + 1);
  136|       |
  137|       |	/* Terminate name and check for cache or cache it */
  138|   395k|	*name = '\0';
  139|   634k|	for (x = 0; x < MAX_NUM_LABELS && m->_labels[x]; x++) {
  ------------------
  |  |   61|  1.26M|#define MAX_NUM_LABELS 512
  ------------------
  |  Branch (139:14): [True: 634k, False: 0]
  |  Branch (139:36): [True: 633k, False: 1.25k]
  ------------------
  140|   633k|		if (strcmp(*namep, m->_labels[x]))
  ------------------
  |  Branch (140:7): [True: 239k, False: 394k]
  ------------------
  141|   239k|			continue;
  142|       |
  143|   394k|		*namep = m->_labels[x];
  144|   394k|		return 0;
  145|   633k|	}
  146|       |
  147|       |	/* No cache, so cache it if room */
  148|  1.25k|	if (x < MAX_NUM_LABELS && m->_labels[x] == 0)
  ------------------
  |  |   61|  2.51k|#define MAX_NUM_LABELS 512
  ------------------
  |  Branch (148:6): [True: 1.25k, False: 0]
  |  Branch (148:28): [True: 1.25k, False: 0]
  ------------------
  149|  1.25k|		m->_labels[x] = *namep;
  150|  1.25k|	m->_len += (int)(name - *namep) + 1;
  151|       |
  152|  1.25k|	return 0;
  153|   395k|}
1035.c:_ldecomp:
   85|  2.06k|{
   86|  2.06k|	unsigned short int i;
   87|       |
   88|  2.06k|	i = 0xc0 ^ ptr[0];
   89|  2.06k|	i <<= 8;
   90|  2.06k|	i |= (unsigned char)ptr[1];
   91|  2.06k|	if (i >= 4096)
  ------------------
  |  Branch (91:6): [True: 1.02k, False: 1.04k]
  ------------------
   92|  1.02k|		i = 4095;
   93|       |
   94|  2.06k|	return i;
   95|  2.06k|}
1035.c:_rrparse:
  256|  1.38k|{
  257|  1.38k|	int i;
  258|       |
  259|  95.6k|	for (i = 0; i < count; i++) {
  ------------------
  |  Branch (259:14): [True: 94.4k, False: 1.25k]
  ------------------
  260|  94.4k|		if (_label(m, bufp, &(rr[i].name)))
  ------------------
  |  Branch (260:7): [True: 116, False: 94.3k]
  ------------------
  261|    116|			return 1;
  262|  94.3k|		rr[i].type     = net2short(bufp);
  263|  94.3k|		rr[i].clazz    = net2short(bufp);
  264|  94.3k|		rr[i].ttl      = net2long(bufp);
  265|  94.3k|		rr[i].rdlength = net2short(bufp);
  266|       |//		fprintf(stderr, "Record type %d clazz 0x%2x ttl %lu len %d\n", rr[i].type, rr[i].clazz, rr[i].ttl, rr[i].rdlength);
  267|       |
  268|       |		/* If not going to overflow, make copy of source rdata */
  269|  94.3k|		if (rr[i].rdlength + (*bufp - m->_buf) > MAX_PACKET_LEN || m->_len + rr[i].rdlength > MAX_PACKET_LEN) {
  ------------------
  |  |   60|   188k|#define MAX_PACKET_LEN 65535
  ------------------
              		if (rr[i].rdlength + (*bufp - m->_buf) > MAX_PACKET_LEN || m->_len + rr[i].rdlength > MAX_PACKET_LEN) {
  ------------------
  |  |   60|  94.2k|#define MAX_PACKET_LEN 65535
  ------------------
  |  Branch (269:7): [True: 3, False: 94.2k]
  |  Branch (269:62): [True: 11, False: 94.2k]
  ------------------
  270|     14|			rr[i].rdlength = 0;
  271|     14|			return 1;
  272|     14|		}
  273|       |
  274|       |		/* For the following records the rdata will be parsed later. So don't set it here:
  275|       |		 * NS, CNAME, PTR, DNAME, SOA, MX, AFSDB, RT, KX, RP, PX, SRV, NSEC
  276|       |		 * See 18.14 of https://tools.ietf.org/html/rfc6762#page-47 */
  277|  94.2k|		if (rr[i].type == QTYPE_NS || rr[i].type == QTYPE_CNAME || rr[i].type == QTYPE_PTR || rr[i].type == QTYPE_SRV) {
  ------------------
  |  |   69|   188k|#define QTYPE_NS     2
  ------------------
              		if (rr[i].type == QTYPE_NS || rr[i].type == QTYPE_CNAME || rr[i].type == QTYPE_PTR || rr[i].type == QTYPE_SRV) {
  ------------------
  |  |   70|   188k|#define QTYPE_CNAME  5
  ------------------
              		if (rr[i].type == QTYPE_NS || rr[i].type == QTYPE_CNAME || rr[i].type == QTYPE_PTR || rr[i].type == QTYPE_SRV) {
  ------------------
  |  |   71|   188k|#define QTYPE_PTR    12
  ------------------
              		if (rr[i].type == QTYPE_NS || rr[i].type == QTYPE_CNAME || rr[i].type == QTYPE_PTR || rr[i].type == QTYPE_SRV) {
  ------------------
  |  |   74|  93.8k|#define QTYPE_SRV    33
  ------------------
  |  Branch (277:7): [True: 79, False: 94.2k]
  |  Branch (277:33): [True: 295, False: 93.9k]
  |  Branch (277:62): [True: 81, False: 93.8k]
  |  Branch (277:89): [True: 67, False: 93.7k]
  ------------------
  278|    522|			rr[i].rdlength = 0;
  279|  93.7k|		} else {
  280|  93.7k|			rr[i].rdata = m->_packet + m->_len;
  281|  93.7k|			m->_len += rr[i].rdlength;
  282|  93.7k|			memcpy(rr[i].rdata, *bufp, rr[i].rdlength);
  283|  93.7k|		}
  284|       |
  285|       |
  286|       |		/* Parse commonly known ones */
  287|  94.2k|		switch (rr[i].type) {
  288|     96|		case QTYPE_A:
  ------------------
  |  |   68|     96|#define QTYPE_A      1
  ------------------
  |  Branch (288:3): [True: 96, False: 94.1k]
  ------------------
  289|     96|			if (m->_len + INET_ADDRSTRLEN > MAX_PACKET_LEN)
  ------------------
  |  |   60|     96|#define MAX_PACKET_LEN 65535
  ------------------
  |  Branch (289:8): [True: 1, False: 95]
  ------------------
  290|      1|				return 1;
  291|     95|			rr[i].known.a.name = (char *)m->_packet + m->_len;
  292|     95|			m->_len += INET_ADDRSTRLEN;
  293|     95|			inet_ntop(AF_INET, *bufp, rr[i].known.a.name, INET_ADDRSTRLEN);
  294|     95|			memcpy(&(rr[i].known.a.ip.s_addr), *bufp, sizeof(rr[i].known.a.ip.s_addr));
  295|     95|			*bufp += sizeof(rr[i].known.a.ip.s_addr);
  296|     95|			break;
  297|       |
  298|     94|		case QTYPE_AAAA:
  ------------------
  |  |   73|     94|#define QTYPE_AAAA   28
  ------------------
  |  Branch (298:3): [True: 94, False: 94.1k]
  ------------------
  299|     94|			if (m->_len + INET6_ADDRSTRLEN > MAX_PACKET_LEN)
  ------------------
  |  |   60|     94|#define MAX_PACKET_LEN 65535
  ------------------
  |  Branch (299:8): [True: 1, False: 93]
  ------------------
  300|      1|				return 1;
  301|     93|			rr[i].known.aaaa.name = (char *)m->_packet + m->_len;
  302|     93|			m->_len += INET6_ADDRSTRLEN;
  303|     93|			inet_ntop(AF_INET6, *bufp, rr[i].known.aaaa.name, INET6_ADDRSTRLEN);
  304|     93|			memcpy(rr[i].known.aaaa.ip6.s6_addr, *bufp, sizeof(rr[i].known.aaaa.ip6.s6_addr));
  305|     93|			*bufp += sizeof(rr[i].known.aaaa.ip6.s6_addr);
  306|     93|			break;
  307|       |
  308|     79|		case QTYPE_NS:
  ------------------
  |  |   69|     79|#define QTYPE_NS     2
  ------------------
  |  Branch (308:3): [True: 79, False: 94.2k]
  ------------------
  309|     79|			if (_label(m, bufp, &(rr[i].known.ns.name)))
  ------------------
  |  Branch (309:8): [True: 1, False: 78]
  ------------------
  310|      1|				return 1;
  311|     78|			break;
  312|       |
  313|    295|		case QTYPE_CNAME:
  ------------------
  |  |   70|    295|#define QTYPE_CNAME  5
  ------------------
  |  Branch (313:3): [True: 295, False: 93.9k]
  ------------------
  314|    295|			if (_label(m, bufp, &(rr[i].known.cname.name)))
  ------------------
  |  Branch (314:8): [True: 1, False: 294]
  ------------------
  315|      1|				return 1;
  316|    294|			break;
  317|       |
  318|    294|		case QTYPE_PTR:
  ------------------
  |  |   71|     81|#define QTYPE_PTR    12
  ------------------
  |  Branch (318:3): [True: 81, False: 94.2k]
  ------------------
  319|     81|			if (_label(m, bufp, &(rr[i].known.ptr.name)))
  ------------------
  |  Branch (319:8): [True: 1, False: 80]
  ------------------
  320|      1|				return 1;
  321|     80|			break;
  322|       |
  323|     80|		case QTYPE_SRV:
  ------------------
  |  |   74|     67|#define QTYPE_SRV    33
  ------------------
  |  Branch (323:3): [True: 67, False: 94.2k]
  ------------------
  324|     67|			rr[i].known.srv.priority = net2short(bufp);
  325|     67|			rr[i].known.srv.weight = net2short(bufp);
  326|     67|			rr[i].known.srv.port = net2short(bufp);
  327|     67|			if (_label(m, bufp, &(rr[i].known.srv.name)))
  ------------------
  |  Branch (327:8): [True: 1, False: 66]
  ------------------
  328|      1|				return 1;
  329|     66|			break;
  330|       |
  331|     66|		case QTYPE_TXT:
  ------------------
  |  |   72|      0|#define QTYPE_TXT    16
  ------------------
  |  Branch (331:3): [True: 0, False: 94.2k]
  ------------------
  332|  93.5k|		default:
  ------------------
  |  Branch (332:3): [True: 93.5k, False: 712]
  ------------------
  333|  93.5k|			*bufp += rr[i].rdlength;
  334|  94.2k|		}
  335|  94.2k|	}
  336|       |
  337|  1.25k|	return 0;
  338|  1.38k|}

mdnsd_new:
  733|    203|{
  734|    203|	mdns_daemon_t *d;
  735|       |
  736|    203|	d = calloc(1, sizeof(struct mdns_daemon));
  737|    203|	if (!d)
  ------------------
  |  Branch (737:6): [True: 0, False: 203]
  ------------------
  738|      0|		return NULL;
  739|       |
  740|    203|	gettimeofday(&d->now, 0);
  741|    203|	d->expireall = (unsigned long)d->now.tv_sec + GC;
  ------------------
  |  |   43|    203|#define GC 86400                /* Brute force garbage cleanup
  ------------------
  742|    203|	d->clazz = clazz;
  743|    203|	d->frame = frame;
  744|    203|	d->received_callback = NULL;
  745|    203|	d->local_ifaddrs = NULL;
  746|    203|	d->local_addrs_refreshed = 0;
  747|       |
  748|    203|	return d;
  749|    203|}
mdnsd_free:
  857|    203|{
  858|    203|	struct unicast *u;
  859|       |
  860|    203|	if (!d)
  ------------------
  |  Branch (860:6): [True: 0, False: 203]
  ------------------
  861|      0|		return;
  862|       |
  863|   205k|	for (size_t i = 0; i< LPRIME; i++) {
  ------------------
  |  |   41|   205k|#define LPRIME 1009		/* Size of cache hash */
  ------------------
  |  Branch (863:21): [True: 204k, False: 203]
  ------------------
  864|   204k|		struct cached *cur = d->cache[i];
  865|       |
  866|   204k|		while (cur) {
  ------------------
  |  Branch (866:10): [True: 0, False: 204k]
  ------------------
  867|      0|			struct cached *next = cur->next;
  868|       |
  869|      0|			cur->next = NULL;
  870|      0|			_free_cached(cur);
  871|      0|			cur = next;
  872|      0|		}
  873|   204k|	}
  874|       |
  875|  22.3k|	for (size_t i = 0; i< SPRIME; i++) {
  ------------------
  |  |   40|  22.3k|#define SPRIME 109		/* Size of query/publish hashes */
  ------------------
  |  Branch (875:21): [True: 22.1k, False: 203]
  ------------------
  876|  22.1k|		struct mdns_record *cur = d->published[i];
  877|  22.1k|		struct query *curq;
  878|       |
  879|  22.1k|		while (cur) {
  ------------------
  |  Branch (879:10): [True: 0, False: 22.1k]
  ------------------
  880|      0|			struct mdns_record *next = cur->next;
  881|       |
  882|      0|			cur->next = NULL;
  883|      0|			_free_record(cur);
  884|      0|			cur = next;
  885|      0|		}
  886|       |
  887|  22.1k|		curq = d->queries[i];
  888|  22.1k|		while (curq) {
  ------------------
  |  Branch (888:10): [True: 0, False: 22.1k]
  ------------------
  889|      0|			struct query *next = curq->next;
  890|       |
  891|      0|			curq->next = NULL;
  892|      0|			free(curq->name);
  893|      0|			free(curq);
  894|      0|			curq = next;
  895|      0|		}
  896|  22.1k|	}
  897|       |
  898|    203|	u = d->uanswers;
  899|    203|	while (u) {
  ------------------
  |  Branch (899:9): [True: 0, False: 203]
  ------------------
  900|      0|		struct unicast *next = u->next;
  901|       |
  902|      0|		u->next = NULL;
  903|      0|		free(u);
  904|      0|		u = next;
  905|      0|	}
  906|       |
  907|    203|	if (d->local_ifaddrs)
  ------------------
  |  Branch (907:6): [True: 0, False: 203]
  ------------------
  908|      0|		freeifaddrs(d->local_ifaddrs);
  909|       |
  910|    203|	free(d);
  911|    203|}
mdnsd_in:
  921|    203|{
  922|    203|	mdns_record_t *r = NULL;
  923|    203|	int i, j;
  924|    203|	bool did_addr_refresh = false;
  925|       |
  926|    203|	if (d->shutdown)
  ------------------
  |  Branch (926:6): [True: 0, False: 203]
  ------------------
  927|      0|		return 1;
  928|       |
  929|    203|	gettimeofday(&d->now, 0);
  930|       |
  931|       |	/* Ignore packets originated from any of our local IPv4 addresses */
  932|    203|	if (_is_local_ipv4(d, ip))
  ------------------
  |  Branch (932:6): [True: 203, False: 0]
  ------------------
  933|    203|		return 0;
  934|       |
  935|      0|	if (m->header.qr == 0) {
  ------------------
  |  Branch (935:6): [True: 0, False: 0]
  ------------------
  936|       |		/* Process each query */
  937|      0|		for (i = 0; i < m->qdcount; i++) {
  ------------------
  |  Branch (937:15): [True: 0, False: 0]
  ------------------
  938|      0|			mdns_record_t *r_start, *r_next;
  939|      0|			bool has_conflict = false;
  940|       |
  941|      0|			if (!m->qd || m->qd[i].clazz != d->clazz)
  ------------------
  |  Branch (941:8): [True: 0, False: 0]
  |  Branch (941:18): [True: 0, False: 0]
  ------------------
  942|      0|				continue;
  943|       |
  944|      0|			INFO("Query for %s of type %d ...", m->qd[i].name, m->qd[i].type);
  ------------------
  |  |   44|      0|#define INFO(fmt, args...) mdnsd_log(LOG_INFO, "%s(): " fmt, __func__, ##args)
  ------------------
  945|      0|			r = _r_next(d, NULL, m->qd[i].name, m->qd[i].type);
  946|      0|			if (!r)
  ------------------
  |  Branch (946:8): [True: 0, False: 0]
  ------------------
  947|      0|				continue;
  948|       |
  949|       |			/* Service enumeration/discovery prepare to send all matching records */
  950|      0|			if (!strcmp(m->qd[i].name, DISCO_NAME)) {
  ------------------
  |  |   41|      0|#define DISCO_NAME "_services._dns-sd._udp.local."
  ------------------
  |  Branch (950:8): [True: 0, False: 0]
  ------------------
  951|      0|				d->disco = 1;
  952|      0|				while (r) {
  ------------------
  |  Branch (952:12): [True: 0, False: 0]
  ------------------
  953|      0|					if (!strcmp(r->rr.name, DISCO_NAME))
  ------------------
  |  |   41|      0|#define DISCO_NAME "_services._dns-sd._udp.local."
  ------------------
  |  Branch (953:10): [True: 0, False: 0]
  ------------------
  954|      0|						_r_send(d, r);
  955|      0|					r = _r_next(d, r, m->qd[i].name, m->qd[i].type);
  956|      0|				}
  957|       |
  958|      0|				continue;
  959|      0|			}
  960|       |
  961|       |			/* Check all of our potential answers */
  962|      0|			for (r_start = r; r != NULL; r = r_next) {
  ------------------
  |  Branch (962:22): [True: 0, False: 0]
  ------------------
  963|      0|				INFO("Local record: %s, type: %d, rdname: %s", r->rr.name, r->rr.type, r->rr.rdname);
  ------------------
  |  |   44|      0|#define INFO(fmt, args...) mdnsd_log(LOG_INFO, "%s(): " fmt, __func__, ##args)
  ------------------
  964|       |
  965|       |				/* Fetch next here, because _conflict() might delete r, invalidating next */
  966|      0|				r_next = _r_next(d, r, m->qd[i].name, m->qd[i].type);
  967|       |
  968|       |				/* probing state, check for conflicts */
  969|      0|				if (r->unique && r->unique < 5 && !r->modified) {
  ------------------
  |  Branch (969:9): [True: 0, False: 0]
  |  Branch (969:22): [True: 0, False: 0]
  |  Branch (969:39): [True: 0, False: 0]
  ------------------
  970|       |					/* Check all to-be answers against our own */
  971|      0|					for (j = 0; j < m->ancount; j++) {
  ------------------
  |  Branch (971:18): [True: 0, False: 0]
  ------------------
  972|      0|						if (!m->an || m->qd[i].type != m->an[j].type || strcmp(m->qd[i].name, m->an[j].name))
  ------------------
  |  Branch (972:11): [True: 0, False: 0]
  |  Branch (972:21): [True: 0, False: 0]
  |  Branch (972:55): [True: 0, False: 0]
  ------------------
  973|      0|							continue;
  974|       |
  975|       |						/* This answer isn't ours, conflict! */
  976|      0|						if (!_a_match(&m->an[j], &r->rr)) {
  ------------------
  |  Branch (976:11): [True: 0, False: 0]
  ------------------
  977|       |							/* Before flagging conflict, force a local address refresh and re-check */
  978|      0|							if (!did_addr_refresh) {
  ------------------
  |  Branch (978:12): [True: 0, False: 0]
  ------------------
  979|      0|								did_addr_refresh = true;
  980|      0|								_refresh_local_ipv4(d, true);
  981|      0|							}
  982|      0|							if (_is_local_ipv4(d, ip))
  ------------------
  |  Branch (982:12): [True: 0, False: 0]
  ------------------
  983|      0|								continue;
  984|      0|							_conflict(d, r);
  985|      0|							has_conflict = true;
  986|      0|							break;
  987|      0|						}
  988|      0|					}
  989|      0|					continue;
  990|      0|				}
  991|       |
  992|       |				/* Check the known answers for this question */
  993|      0|				for (j = 0; j < m->ancount; j++) {
  ------------------
  |  Branch (993:17): [True: 0, False: 0]
  ------------------
  994|      0|					if (!m->an || m->qd[i].type != m->an[j].type || strcmp(m->qd[i].name, m->an[j].name))
  ------------------
  |  Branch (994:10): [True: 0, False: 0]
  |  Branch (994:20): [True: 0, False: 0]
  |  Branch (994:54): [True: 0, False: 0]
  ------------------
  995|      0|						continue;
  996|       |
  997|      0|					if (d->received_callback)
  ------------------
  |  Branch (997:10): [True: 0, False: 0]
  ------------------
  998|      0|						d->received_callback(&m->an[j], d->received_callback_data);
  999|       |
 1000|       |					/* Do they already have this answer? */
 1001|      0|					if (_a_match(&m->an[j], &r->rr))
  ------------------
  |  Branch (1001:10): [True: 0, False: 0]
  ------------------
 1002|      0|						break;
 1003|      0|				}
 1004|       |
 1005|      0|				INFO("Should we send answer? j: %d, m->ancount: %d", j, m->ancount);
  ------------------
  |  |   44|      0|#define INFO(fmt, args...) mdnsd_log(LOG_INFO, "%s(): " fmt, __func__, ##args)
  ------------------
 1006|      0|				if (j == m->ancount) {
  ------------------
  |  Branch (1006:9): [True: 0, False: 0]
  ------------------
 1007|      0|					INFO("Yes we should, enquing %s for outbound", r->rr.name);
  ------------------
  |  |   44|      0|#define INFO(fmt, args...) mdnsd_log(LOG_INFO, "%s(): " fmt, __func__, ##args)
  ------------------
 1008|      0|					_r_send(d, r);
 1009|      0|				}
 1010|      0|			}
 1011|       |
 1012|       |			/* Send the matching unicast reply */
 1013|      0|			if (!has_conflict && port != 5353)
  ------------------
  |  Branch (1013:8): [True: 0, False: 0]
  |  Branch (1013:25): [True: 0, False: 0]
  ------------------
 1014|      0|				_u_push(d, r_start, m->id, ip, port);
 1015|      0|		}
 1016|       |
 1017|      0|		return 0;
 1018|      0|	}
 1019|       |
 1020|       |	/* Process each answer, check for a conflict, and cache */
 1021|      0|	for (i = 0; i < m->ancount; i++) {
  ------------------
  |  Branch (1021:14): [True: 0, False: 0]
  ------------------
 1022|      0|		if (!m->an)
  ------------------
  |  Branch (1022:7): [True: 0, False: 0]
  ------------------
 1023|      0|			continue;
 1024|       |
 1025|      0|		if (!m->an[i].name) {
  ------------------
  |  Branch (1025:7): [True: 0, False: 0]
  ------------------
 1026|      0|			ERR("Got answer with NULL name at %p. Type: %d, TTL: %ld, skipping",
  ------------------
  |  |   47|      0|#define ERR(fmt, args...)  mdnsd_log(LOG_ERR, fmt, ##args)
  ------------------
 1027|      0|			    (void*)&m->an[i], m->an[i].type, m->an[i].ttl);
 1028|      0|			continue;
 1029|      0|		}
 1030|       |
 1031|      0|		INFO("Got Answer: Name: %s, Type: %d", m->an[i].name, m->an[i].type);
  ------------------
  |  |   44|      0|#define INFO(fmt, args...) mdnsd_log(LOG_INFO, "%s(): " fmt, __func__, ##args)
  ------------------
 1032|      0|		r = _r_next(d, NULL, m->an[i].name, m->an[i].type);
 1033|      0|		if (r && r->unique && r->modified && _a_match(&m->an[i], &r->rr)) {
  ------------------
  |  Branch (1033:7): [True: 0, False: 0]
  |  Branch (1033:12): [True: 0, False: 0]
  |  Branch (1033:25): [True: 0, False: 0]
  |  Branch (1033:40): [True: 0, False: 0]
  ------------------
 1034|       |			/* double check, is this actually from us, looped back? */
 1035|      0|			if (!did_addr_refresh) {
  ------------------
  |  Branch (1035:8): [True: 0, False: 0]
  ------------------
 1036|      0|				did_addr_refresh = true;
 1037|      0|				_refresh_local_ipv4(d, true);
 1038|      0|			}
 1039|      0|			if (_is_local_ipv4(d, ip))
  ------------------
  |  Branch (1039:8): [True: 0, False: 0]
  ------------------
 1040|      0|				continue;
 1041|      0|			_conflict(d, r);
 1042|      0|		}
 1043|       |
 1044|      0|		if (d->received_callback)
  ------------------
  |  Branch (1044:7): [True: 0, False: 0]
  ------------------
 1045|      0|			d->received_callback(&m->an[i], d->received_callback_data);
 1046|       |
 1047|      0|		if (_cache(d, &m->an[i], ip) != 0) {
  ------------------
  |  Branch (1047:7): [True: 0, False: 0]
  ------------------
 1048|      0|			ERR("Failed caching answer, possibly too long packet, skipping.");
  ------------------
  |  |   47|      0|#define ERR(fmt, args...)  mdnsd_log(LOG_ERR, fmt, ##args)
  ------------------
 1049|      0|			continue;
 1050|      0|		}
 1051|      0|	}
 1052|       |
 1053|      0|	return 0;
 1054|      0|}
mdnsd.c:_is_local_ipv4:
  709|    203|{
  710|    203|	struct ifaddrs *it;
  711|       |
  712|       |	/* Always consider the primary configured address as local */
  713|    203|	if (ip.s_addr == d->addr.s_addr)
  ------------------
  |  Branch (713:6): [True: 203, False: 0]
  ------------------
  714|    203|		return true;
  715|       |
  716|      0|	_refresh_local_ipv4(d, false);
  717|       |
  718|      0|	for (it = d->local_ifaddrs; it; it = it->ifa_next) {
  ------------------
  |  Branch (718:30): [True: 0, False: 0]
  ------------------
  719|      0|		struct sockaddr_in *sin;
  720|      0|		if (!it->ifa_addr)
  ------------------
  |  Branch (720:7): [True: 0, False: 0]
  ------------------
  721|      0|			continue;
  722|      0|		if (it->ifa_addr->sa_family != AF_INET)
  ------------------
  |  Branch (722:7): [True: 0, False: 0]
  ------------------
  723|      0|			continue;
  724|      0|		sin = (struct sockaddr_in *)it->ifa_addr;
  725|      0|		if (sin->sin_addr.s_addr == ip.s_addr)
  ------------------
  |  Branch (725:7): [True: 0, False: 0]
  ------------------
  726|      0|			return true;
  727|      0|	}
  728|       |
  729|      0|	return false;
  730|      0|}

