]> git.karo-electronics.de Git - mdnsd.git/commitdiff
fix warnings and a crasher in mdnsd.c
authorSimon Budig <simon@budig.de>
Thu, 22 Jan 2009 23:01:19 +0000 (00:01 +0100)
committerOle Reinhardt <ole.reinhardt@kernelconcepts.de>
Sun, 28 Apr 2013 23:01:52 +0000 (01:01 +0200)
mdnsd.c

diff --git a/mdnsd.c b/mdnsd.c
index 2efc0a7106167a39ecd44a311ccd176f0926e798..68e69cd8f0ab5f57d165cbdd28bba41d3327717e 100644 (file)
--- a/mdnsd.c
+++ b/mdnsd.c
@@ -1,5 +1,7 @@
-#include "mdnsd.h"
 #include <string.h>
+#include <stdlib.h>
+#include <arpa/inet.h>
+#include "mdnsd.h"
 
 // size of query/publish hashes
 #define SPRIME 108
@@ -198,7 +200,7 @@ void _q_reset(mdnsd d, struct query *q)
     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;
 }
@@ -208,7 +210,7 @@ void _q_done(mdnsd d, struct query *q)
     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);
@@ -288,18 +290,18 @@ void _cache(mdnsd d, struct resource *r)
 
     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;
     }
 
@@ -330,7 +332,7 @@ void _cache(mdnsd d, struct resource *r)
     }
     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);
 }
 
@@ -344,7 +346,7 @@ void _a_copy(struct message *m, mdnsda a)
 
 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)
     {
@@ -363,7 +365,6 @@ int _r_out(mdnsd d, struct message *m, mdnsdr *list)
 
 mdnsd mdnsd_new(int class, int frame)
 {
-    int i;
     mdnsd d;
     d = (mdnsd)malloc(sizeof(struct mdnsd_struct));
     bzero(d,sizeof(struct mdnsd_struct));
@@ -401,7 +402,6 @@ void mdnsd_flush(mdnsd d)
 
 void mdnsd_free(mdnsd d)
 {
-    int i;
     // loop through all hashes, free everything
     // free answers if any
     free(d);
@@ -467,7 +467,7 @@ int mdnsd_out(mdnsd d, struct message *m, unsigned long int *ip, unsigned short
     *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;
@@ -612,7 +612,6 @@ int mdnsd_out(mdnsd d, struct message *m, unsigned long int *ip, unsigned short
 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;
 
@@ -620,7 +619,7 @@ struct timeval *mdnsd_sleep(mdnsd d)
     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;
@@ -665,7 +664,7 @@ void mdnsd_query(mdnsd d, char *host, int type, int (*answer)(mdnsda a, void *ar
         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