-#include "mdnsd.h"
#include <string.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include "mdnsd.h"
// size of query/publish hashes
#define SPRIME 108
struct cached *cur = 0;
q->nexttry = 0;
q->tries = 0;
- while(cur = _c_next(d,cur,q->name,q->type))
+ while((cur = _c_next(d,cur,q->name,q->type)))
if(q->nexttry == 0 || cur->rr.ttl - 7 < q->nexttry) q->nexttry = cur->rr.ttl - 7;
if(q->nexttry != 0 && q->nexttry < d->checkqlist) d->checkqlist = q->nexttry;
}
struct cached *c = 0;
struct query *cur;
int i = _namehash(q->name) % LPRIME;
- while(c = _c_next(d,c,q->name,q->type)) c->q = 0;
+ while((c = _c_next(d,c,q->name,q->type))) c->q = 0;
if(d->qlist == q) d->qlist = q->list;
else {
for(cur=d->qlist;cur->list != q;cur = cur->list);
if(r->class == 32768 + d->class)
{ // cache flush
- while(c = _c_next(d,c,r->name,r->type)) c->rr.ttl = 0;
+ while((c = _c_next(d,c,r->name,r->type))) c->rr.ttl = 0;
_c_expire(d,&d->cache[i]);
}
-
+
if(r->ttl == 0)
{ // process deletes
- while(c = _c_next(d,c,r->name,r->type))
+ while((c = _c_next(d,c,r->name,r->type)))
if(_a_match(r,&c->rr))
{
c->rr.ttl = 0;
- _c_expire(d,&d->cache[i]);
}
+ _c_expire(d,&d->cache[i]);
return;
}
}
c->next = d->cache[i];
d->cache[i] = c;
- if(c->q = _q_next(d, 0, r->name, r->type))
+ if((c->q = _q_next(d, 0, r->name, r->type)))
_q_answer(d,c);
}
int _r_out(mdnsd d, struct message *m, mdnsdr *list)
{ // copy a published record into an outgoing message
- mdnsdr r, next;
+ mdnsdr r;
int ret = 0;
while((r = *list) != 0 && message_packet_len(m) + _rr_len(&r->rr) < d->frame)
{
mdnsd mdnsd_new(int class, int frame)
{
- int i;
mdnsd d;
d = (mdnsd)malloc(sizeof(struct mdnsd_struct));
bzero(d,sizeof(struct mdnsd_struct));
void mdnsd_free(mdnsd d)
{
- int i;
// loop through all hashes, free everything
// free answers if any
free(d);
*ip = inet_addr("224.0.0.251");
m->header.qr = 1;
m->header.aa = 1;
-
+
if(d->uanswers)
{ // send out individual unicast answers
struct unicast *u = d->uanswers;
struct timeval *mdnsd_sleep(mdnsd d)
{
int sec, usec;
- mdnsdr r;
d->sleep.tv_sec = d->sleep.tv_usec = 0;
#define RET while(d->sleep.tv_usec > 1000000) {d->sleep.tv_sec++;d->sleep.tv_usec -= 1000000;} return &d->sleep;
if(d->uanswers || d->a_now) return &d->sleep;
gettimeofday(&d->now,0);
-
+
if(d->a_pause)
{ // then check for paused answers
if((usec = _tvdiff(d->now,d->pause)) > 0) d->sleep.tv_usec = usec;
q->next = d->queries[i];
q->list = d->qlist;
d->qlist = d->queries[i] = q;
- while(cur = _c_next(d,cur,q->name,q->type))
+ while((cur = _c_next(d,cur,q->name,q->type)))
cur->q = q; // any cached entries should be associated
_q_reset(d,q);
q->nexttry = d->checkqlist = d->now.tv_sec; // new questin, immediately send out