6 typedef struct mdnsd_struct *mdnsd; // main daemon data
7 typedef struct mdnsdr_struct *mdnsdr; // record entry
9 typedef struct mdnsda_struct
12 unsigned short int type;
13 unsigned long int ttl;
14 unsigned short int rdlen;
16 unsigned long int ip; // A
17 unsigned char *rdname; // NS/CNAME/PTR/SRV
18 struct { unsigned short int priority, weight, port; } srv; // SRV
24 // create a new mdns daemon for the given class of names (usually 1) and maximum frame size
25 mdnsd mdnsd_new(int class, int frame);
27 // gracefully shutdown the daemon, use mdnsd_out() to get the last packets
28 void mdnsd_shutdown(mdnsd d);
30 // flush all cached records (network/interface changed)
31 void mdnsd_flush(mdnsd d);
33 // free given mdnsd (should have used mdnsd_shutdown() first!)
34 void mdnsd_free(mdnsd d);
41 // incoming message from host (to be cached/processed)
42 void mdnsd_in(mdnsd d, struct message *m, unsigned long int ip, unsigned short int port);
44 // outgoing messge to be delivered to host, returns >0 if one was returned and m/ip/port set
45 int mdnsd_out(mdnsd d, struct message *m, unsigned long int *ip, unsigned short int *port);
47 // returns the max wait-time until mdnsd_out() needs to be called again
48 struct timeval *mdnsd_sleep(mdnsd d);
55 // register a new query
56 // answer(record, arg) is called whenever one is found/changes/expires (immediate or anytime after, mdnsda valid until ->ttl==0)
57 // either answer returns -1, or another mdnsd_query with a NULL answer will remove/unregister this query
58 void mdnsd_query(mdnsd d, char *host, int type, int (*answer)(mdnsda a, void *arg), void *arg);
60 // returns the first (if last == NULL) or next answer after last from the cache
61 // mdnsda only valid until an I/O function is called
62 mdnsda mdnsd_list(mdnsd d, char *host, int type, mdnsda last);
67 // Publishing functions
69 // create a new unique record (try mdnsda_list first to make sure it's not used)
70 // conflict(arg) called at any point when one is detected and unable to recover
71 // after the first data is set_*(), any future changes effectively expire the old one and attempt to create a new unique record
72 mdnsdr mdnsd_unique(mdnsd d, char *host, int type, long int ttl, void (*conflict)(char *host, int type, void *arg), void *arg);
74 // create a new shared record
75 mdnsdr mdnsd_shared(mdnsd d, char *host, int type, long int ttl);
77 // de-list the given record
78 void mdnsd_done(mdnsd d, mdnsdr r);
80 // these all set/update the data for the given record, nothing is published until they are called
81 void mdnsd_set_raw(mdnsd d, mdnsdr r, char *data, int len);
82 void mdnsd_set_host(mdnsd d, mdnsdr r, char *name);
83 void mdnsd_set_ip(mdnsd d, mdnsdr r, unsigned long int ip);
84 void mdnsd_set_srv(mdnsd d, mdnsdr r, int priority, int weight, int port, char *name);