2 * Copyright (C) 2005 Jeremie Miller
3 * Copyright (C) 2005,2006 Justin Karneges
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 unsigned long int tv_sec
; /* seconds */
33 unsigned long int tv_usec
; /* microseconds */
36 typedef struct mdnsd_struct
*mdnsd
; // main daemon data
37 typedef struct mdnsdr_struct
*mdnsdr
; // record entry
39 typedef struct mdnsda_struct
42 unsigned short int type
;
43 unsigned long int ttl
;
44 unsigned long int real_ttl
;
45 unsigned short int rdlen
;
47 unsigned long int ip
; // A
48 unsigned char *rdname
; // NS/CNAME/PTR/SRV
49 struct { unsigned short int priority
, weight
, port
; } srv
; // SRV
55 // create a new mdns daemon for the given class of names (usually 1) and maximum frame size
56 mdnsd
mdnsd_new(int class, int frame
, int port
, int (*time_now
)(mdnsd d
, void *arg
), int (*rand_int
)(mdnsd d
, void *arg
), void *arg
);
58 // gracefully shutdown the daemon, use mdnsd_out() to get the last packets
59 void mdnsd_shutdown(mdnsd d
);
61 // flush all cached records (network/interface changed)
62 void mdnsd_flush(mdnsd d
);
64 // free given mdnsd (should have used mdnsd_shutdown() first!)
65 void mdnsd_free(mdnsd d
);
72 // incoming message from host (to be cached/processed)
73 void mdnsd_in(mdnsd d
, const jdns_packet_t
*m
, const jdns_response_t
*resp
, const jdns_address_t
*addr
, unsigned short int port
);
75 // outgoing messge to be delivered to host, returns >0 if one was returned and m/ip/port set
76 int mdnsd_out(mdnsd d
, jdns_packet_t
**m
, jdns_address_t
**addr
, unsigned short int *port
);
78 // returns the max wait-time until mdnsd_out() needs to be called again
79 struct mytimeval
*mdnsd_sleep(mdnsd d
);
86 // register a new query
87 // answer(record, arg) is called whenever one is found/changes/expires (immediate or anytime after, mdnsda valid until ->ttl==0)
88 // either answer returns -1, or another mdnsd_query with a NULL answer will remove/unregister this query
89 void mdnsd_query(mdnsd d
, char *host
, int type
, int (*answer
)(mdnsda a
, void *arg
), void *arg
);
91 // returns the first (if last == NULL) or next answer after last from the cache
92 // mdnsda only valid until an I/O function is called
93 mdnsda
mdnsd_list(mdnsd d
, char *host
, int type
, mdnsda last
);
98 // Publishing functions
100 // create a new unique record (try mdnsda_list first to make sure it's not used)
101 // conflict(arg) called at any point when one is detected and unable to recover
102 // after the first data is set_*(), any future changes effectively expire the old one and attempt to create a new unique record
103 mdnsdr
mdnsd_unique(mdnsd d
, char *host
, int type
, long int ttl
, void (*pubresult
)(int result
, char *host
, int type
, void *arg
), void *arg
);
105 // create a new shared record
106 mdnsdr
mdnsd_shared(mdnsd d
, char *host
, int type
, long int ttl
);
108 // de-list the given record
109 void mdnsd_done(mdnsd d
, mdnsdr r
);
111 // these all set/update the data for the given record, nothing is published until they are called
112 void mdnsd_set_raw(mdnsd d
, mdnsdr r
, char *data
, int len
);
113 void mdnsd_set_host(mdnsd d
, mdnsdr r
, char *name
);
114 void mdnsd_set_ip(mdnsd d
, mdnsdr r
, unsigned long int ip
);
115 void mdnsd_set_srv(mdnsd d
, mdnsdr r
, int priority
, int weight
, int port
, char *name
);