#include "1035.h"
-#include <string.h>
+#include <string.h>
unsigned short int net2short(unsigned char **bufp)
{
*(*bufp + 1) = (unsigned char)i;
i >>= 8;
**bufp = (unsigned char)i;
- *bufp += 2;
+ *bufp += 2;
}
void long2net(unsigned long int l, unsigned char **bufp)
// copy chars for this label
memcpy(name,label+1,*label);
name[*label] = '.';
- }
+ }
// advance buffer
for(label = *bufp; *label != 0 && !(*label & 0xc0 && label++); label += *label + 1);
// always ensure we get called w/o a pointer
if(*l1 & 0xc0) return _lmatch(m, m->_buf + _ldecomp(l1),l2);
if(*l2 & 0xc0) return _lmatch(m, l1, m->_buf + _ldecomp(l2));
-
+
// same already?
if(l1 == l2) return 1;
-
+
// compare all label characters
if(*l1 != *l2) return 0;
- for(len = 1; len <= *l1; len++)
+ for(len = 1; len <= *l1; len++)
if(l1[len] != l2[len]) return 0;
// get new labels
l1 += *l1 + 1;
l2 += *l2 + 1;
-
+
// at the end, all matched
if(*l1 == 0 && *l2 == 0) return 1;
-
+
// try next labels
return _lmatch(m,l1,l2);
}
rr[i].known.srv.weight = net2short(bufp);
rr[i].known.srv.port = net2short(bufp);
_label(m, bufp, &(rr[i].known.srv.name));
- break;
+ break;
default:
*bufp += rr[i].rdlength;
}
{
unsigned char *buf;
int i;
-
+
if(packet == 0 || m == 0) return;
// keep all our mem in one (aligned) block for easy freeing
// internal variables
unsigned char *_buf, *_labels[20];
int _len, _label;
-
+
// packet acts as padding, easier mem management
unsigned char _packet[MAX_PACKET_LEN];
};
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))
*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;
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;
// outgoing messge to be delivered to host, returns >0 if one was returned and m/ip/port set
int mdnsd_out(mdnsd d, struct message *m, unsigned long int *ip, unsigned short int *port);
//
-// returns the max wait-time until mdnsd_out() needs to be called again
+// returns the max wait-time until mdnsd_out() needs to be called again
struct timeval *mdnsd_sleep(mdnsd d);
//
////////////
///////////
// Q/A functions
-//
+//
// register a new query
// answer(record, arg) is called whenever one is found/changes/expires (immediate or anytime after, mdnsda valid until ->ttl==0)
// either answer returns -1, or another mdnsd_query with a NULL answer will remove/unregister this query
// conflict(arg) called at any point when one is detected and unable to recover
// after the first data is set_*(), any future changes effectively expire the old one and attempt to create a new unique record
mdnsdr mdnsd_unique(mdnsd d, char *host, int type, long int ttl, void (*conflict)(char *host, int type, void *arg), void *arg);
-//
+//
// create a new shared record
mdnsdr mdnsd_shared(mdnsd d, char *host, int type, long int ttl);
//
mc.imr_multiaddr.s_addr = inet_addr("224.0.0.251");
mc.imr_interface.s_addr = htonl(INADDR_ANY);
- setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mc, sizeof(mc));
+ setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mc, sizeof(mc));
setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl));
setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &ittl, sizeof(ittl));
mc.imr_multiaddr.s_addr = inet_addr("224.0.0.251");
mc.imr_interface.s_addr = htonl(INADDR_ANY);
- setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mc, sizeof(mc));
+ setsockopt(s, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mc, sizeof(mc));
setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl));
setsockopt(s, IPPROTO_IP, IP_MULTICAST_TTL, &ittl, sizeof(ittl));
};
/* Generates a hash code for a string.
- * This function uses the ELF hashing algorithm as reprinted in
+ * This function uses the ELF hashing algorithm as reprinted in
* Andrew Binstock, "Hashing Rehashed," Dr. Dobb's Journal, April 1996.
*/
int _xhter(const char *s)