Dirk-Willem van Gulik (NXP/mbed)
/
Bonjour
Bonjour/Zerconf library
Diff: services/mDNS/mDNSResponder.h
- Revision:
- 4:d9f5c4abc5f8
- Parent:
- 2:816cbd922d3e
--- a/services/mDNS/mDNSResponder.h Tue Jul 27 17:22:17 2010 +0000 +++ b/services/mDNS/mDNSResponder.h Sat Jul 31 14:30:45 2010 +0000 @@ -34,23 +34,103 @@ #define MDNS_INTERVAL ( MDNS_TTL * 2 / 3 ) #endif +#ifndef MDNS_QCACHE +#define MDNS_QCACHE 1 +#endif + +#ifndef MDNS_MAXCACHEDNSLABELS +#define MDNS_MAXCACHEDNSLABELS (10) +#endif + class mDNSResponder : protected NetService { public: mDNSResponder(); virtual ~mDNSResponder(); void close(); -void mDNSResponder::announce(IpAddr ip, const char * ldn, const char * proto, uint16_t port, const char * name, char ** txts); + void announce(IpAddr ip, const char * ldn, const char * proto, uint16_t port, const char * name, char ** txts); protected: virtual void poll(); //Called by NetServices - not actually needed. private: - void process(); //Main state-machine + void process(); // Needed for timer, to fire off regular updates. + + // Main inbound packet handler void onUDPSocketEvent(UDPSocketEvent e); - void sendReply(uint16_t Qtype,uint16_t tid, Host dst); // temp + + // 3 functions to keep a QName chace. If enabled with MDNS_QCACHE + void initLabelCache(char * off); + uint16_t checkLabelCache(char * name); + void addLabelCache(char * p, char * name); + + // Handing functions + char * breakname(char *p, char *name); // Break FQDNs at the dots, understanding QCaching. + + // reply building functions; see RFC for names/defintion. + char * mRR(char *p, char * name, uint16_t tpe, uint16_t cls, uint32_t ttl); + char * mRRLABEL(char *p, char * name, uint16_t tpe, char ** rr); + char * mPTR(char *p, char * name, char * r); + char * mTXT(char *p, char * name, char ** rr); + char * mARR(char *p, char * name, IpAddr ip); + char * mSRV(char *p, char * name, uint16_t port, char * rr); + char * qANY(char *p, char * name, uint16_t tpe, uint16_t cls); + + // build query part of a reply. + char * qPTR(char *p, char *name); + char * qA(char *p, char *name); + char * qSRV(char *p, char *name); + + // Sent out the actual DNS packet. + void sendReply(uint16_t t, uint16_t tid, Host dst); + // Decode the query part of a DNS inbound packet. + char * decodeQBlock(char * udp, int len, char *p, char * fqdn, int fqdn_size, uint32_t *Qclass, uint32_t *Qtype); + +PACK_STRUCT_BEGIN +struct DNSPacket + { + PACK_STRUCT_FIELD(uint16_t tid); + PACK_STRUCT_FIELD(uint16_t flags); + PACK_STRUCT_FIELD(uint16_t question_count); + PACK_STRUCT_FIELD(uint16_t answer_count); + PACK_STRUCT_FIELD(uint16_t a_count); + PACK_STRUCT_FIELD(uint16_t aa_count); + PACK_STRUCT_FIELD(char answers); + } PACK_STRUCT_STRUCT; +PACK_STRUCT_END + + // Services + char ** moi_txt; /* Null terminated list */ + + // Endpoint + uint16_t moi_port; + IpAddr moi_ip; + + // Local name construction. + const char * moi_name, * moi_proto; + char * moi_local_proto, * moi_local_name, * moi_local_pglue; + + Timer announcer; + + UDPSocket* m_pUDPSocket; + + // For the QCache +#ifdef MDNS_QCACHE + int labelCacheCnt; + char * labelCacheOffset; + + uint16_t _cache_off[MDNS_MAXCACHEDNSLABELS]; + char * _cache_och[MDNS_MAXCACHEDNSLABELS]; +#endif +}; + + + +#endif + // Just in case - there is prolly some nice ARM6 assembler already linked in. +// #ifndef htons #define htons( x ) ( (( x << 8 ) & 0xFF00) | (( x >> 8 ) & 0x00FF) ) #define ntohs( x ) (htons(x)) @@ -64,26 +144,4 @@ #define ntohl( x ) (htonl(x)) #endif - __packed struct DNSPacket - { - uint16_t tid; - uint16_t flags; - uint16_t question_count; - uint16_t answer_count; - uint16_t a_count; - uint16_t aa_count; - char answers; - }; - const char * moi_name, * moi_proto; - char ** moi_txt; /* Null terminated list */ - char * moi_local_proto, * moi_local_name, * moi_local_pglue; - uint16_t moi_port; - IpAddr moi_ip; - - Timer announcer; - - UDPSocket* m_pUDPSocket; -}; - #endif -#endif