Main Page | Namespace List | Class List | File List | Class Members | Related Pages

src/c-api/mdnsd.h

00001 #ifndef mdnsd_h
00002 #define mdnsd_h
00003 #include "1035.h"
00004 #include <sys/time.h>
00005 
00006 #define SRV_PORT 6464
00007 
00008 #ifndef RECORD_MAX_TRIES
00009 #define RECORD_MAX_TRIES -1
00010 #endif
00011 
00012 #ifndef QUERY_MAX_TRIES
00013 #define QUERY_MAX_TRIES -1
00014 #endif
00015 
00016 typedef struct mdnsd_struct *mdnsd; // main daemon data
00017 typedef struct mdnsdr_struct *mdnsdr; // record entry
00018 // answer data
00019 typedef struct mdnsda_struct
00020 {
00021     unsigned char *name;
00022     unsigned short int type;
00023     unsigned long int ttl;
00024     unsigned short int rdlen;
00025     unsigned char *rdata;
00026     unsigned long int ip; // A
00027     unsigned char *rdname; // NS/CNAME/PTR/SRV
00028     struct { unsigned short int priority, weight, port; } srv; // SRV
00029 } *mdnsda;
00030 
00032 // Global functions
00033 //
00034 
00041 mdnsd mdnsd_new(int aClass, int frame);
00042 //
00043 // gracefully shutdown the daemon, use mdnsd_out() to get the last packets
00044 void mdnsd_shutdown(mdnsd d);
00045 //
00046 // flush all cached records (network/interface changed)
00047 void mdnsd_flush(mdnsd d);
00048 //
00049 // free given mdnsd (should have used mdnsd_shutdown() first!)
00050 void mdnsd_free(mdnsd d);
00051 //
00053 
00055 // I/O functions
00056 //
00057 // incoming message from host (to be cached/processed)
00058 void mdnsd_in(mdnsd d, struct message *m, unsigned long int ip, unsigned short int port);
00059 //
00060 // outgoing messge to be delivered to host, returns >0 if one was returned and m/ip/port set
00061 int mdnsd_out(mdnsd d, struct message *m, unsigned long int *ip, unsigned short int *port);
00062 
00069 struct timeval* mdnsd_sleep(mdnsd d);
00070 
00074 unsigned int mdnsd_sleep_millis(mdnsd);
00075 
00077 
00079 // Q/A functions
00080 // 
00081 // register a new query
00082 //   answer(record, arg) is called whenever one is found/changes/expires (immediate or anytime after, mdnsda valid until ->ttl==0)
00083 //   either answer returns -1, or another mdnsd_query with a NULL answer will remove/unregister this query
00084 void mdnsd_query(mdnsd d, 
00085                  char* host, 
00086                  int type, 
00087                  int (*answer)(mdnsda a, void *arg), 
00088                  void *arg);
00089 
00090 void _mdnsd_query(mdnsd d,
00091                   char *host,
00092                   int type,
00093                   int (*answer)(mdnsda a, void *arg),
00094                   void *arg,
00095                   char* target_host,
00096                   int target_port);
00097 //
00098 // returns the first (if last == NULL) or next answer after last from the cache
00099 //   mdnsda only valid until an I/O function is called
00100 mdnsda mdnsd_list(mdnsd d, char *host, int type, mdnsda last);
00101 //
00103 
00105 // Publishing functions
00106 //
00107 // create a new unique record (try mdnsda_list first to make sure it's not used)
00108 //   conflict(arg) called at any point when one is detected and unable to recover
00109 //   after the first data is set_*(), any future changes effectively expire the old one and attempt to create a new unique record
00110 mdnsdr mdnsd_unique(mdnsd d, char *host, int type, long int ttl, void (*conflict)(char *host, int type, void *arg), void *arg);
00111 
00112 mdnsdr _mdnsd_unique(mdnsd d,
00113                      char *host,
00114                      int type,
00115                      long int ttl,
00116                      void (*conflict)(char *host, int type, void *arg),
00117                      void *arg,
00118                      char* target_host,
00119                      int target_port);
00120 
00129 mdnsdr mdnsd_shared(mdnsd d, char *host, int type, long int ttl);
00130 
00131 mdnsdr _mdnsd_shared(mdnsd d,
00132                      char *host,
00133                      int type,
00134                      long int ttl,
00135                      char* target_host,
00136                      int target_port);
00137 //
00138 // de-list the given record
00139 void mdnsd_done(mdnsd d, mdnsdr r);
00140 //
00141 // these all set/update the data for the given record, nothing is published until they are called
00142 void mdnsd_set_raw(mdnsd d, mdnsdr r, unsigned char *data, int len);
00143 void mdnsd_set_host(mdnsd d, mdnsdr r, char *name);
00144 void mdnsd_set_ip(mdnsd d, mdnsdr r, unsigned long int ip);
00145 void mdnsd_set_srv(mdnsd d, mdnsdr r, int priority, int weight, int port, char *name);
00146 //
00148 
00149 #ifdef DEBUG
00150 #define INFO
00151 #endif
00152 
00153 #ifdef INFO
00154 #include "xht.h"
00155 
00156 void debug_walker(xht h, const char* key, void* val, void* arg);
00157 #endif
00158 
00159 #endif

Generated on Fri May 19 23:27:33 2006 for Tiny DNSSD by  doxygen 1.4.4