]> git.karo-electronics.de Git - mdnsd.git/blob - mdnsd.h
Applied Simons initial checkin, first slightly modifications
[mdnsd.git] / mdnsd.h
1 #ifndef mdnsd_h
2 #define mdnsd_h
3 #include "1035.h"
4 #include <sys/time.h>
5
6 typedef struct mdnsd_struct *mdnsd; // main daemon data
7 typedef struct mdnsdr_struct *mdnsdr; // record entry
8 // answer data
9 typedef struct mdnsda_struct
10 {
11     unsigned char *name;
12     unsigned short int type;
13     unsigned long int ttl;
14     unsigned short int rdlen;
15     unsigned char *rdata;
16     unsigned long int ip; // A
17     unsigned char *rdname; // NS/CNAME/PTR/SRV
18     struct { unsigned short int priority, weight, port; } srv; // SRV
19 } *mdnsda;
20
21 ///////////
22 // Global functions
23 //
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);
26 //
27 // gracefully shutdown the daemon, use mdnsd_out() to get the last packets
28 void mdnsd_shutdown(mdnsd d);
29 //
30 // flush all cached records (network/interface changed)
31 void mdnsd_flush(mdnsd d);
32 //
33 // free given mdnsd (should have used mdnsd_shutdown() first!)
34 void mdnsd_free(mdnsd d);
35 //
36 ///////////
37
38 ///////////
39 // I/O functions
40 //
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);
43 //
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);
46 //
47 // returns the max wait-time until mdnsd_out() needs to be called again
48 struct timeval *mdnsd_sleep(mdnsd d);
49 //
50 ////////////
51
52 ///////////
53 // Q/A functions
54 //
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);
59 //
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);
63 //
64 ///////////
65
66 ///////////
67 // Publishing functions
68 //
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);
73 //
74 // create a new shared record
75 mdnsdr mdnsd_shared(mdnsd d, char *host, int type, long int ttl);
76 //
77 // de-list the given record
78 void mdnsd_done(mdnsd d, mdnsdr r);
79 //
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);
85 //
86 ///////////
87
88
89 #endif