Bonjour/Zerconf library

Dependencies:   mbed

services/mDNS/mDNSResponder.h

Committer:
dirkx
Date:
2010-07-22
Revision:
1:59820ca5c83a
Parent:
0:355018f44c9f
Child:
2:816cbd922d3e

File content as of revision 1:59820ca5c83a:


#ifndef MDNS_RESPONDER_H
#define MDNS_RESPONDER_H

#include "if/net/net.h"
#include "api/UDPSocket.h"
#include "api/DNSRequest.h"
#include "mbed.h"

// As defined by IANA.
//
#define MDNS_PORT (5353)
#define MCAST 224,0,0,251

// How long we announce our IP and URLs to be valid. Should
// ideally be 1/3 or so of the DHCP lease time. But we do 
// not know that.
//
#define MDNS_TTL ( 100 )

// Rebroadcast our details more regularly than the TTL as 
// we otherwise get dropped.
//
#ifndef MDNS_INTERVAL
#define MDNS_INTERVAL ( MDNS_TTL * 2 / 3 )
#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);
  
protected:
  virtual void poll(); //Called by NetServices - not actually needed.
  
private:
  void process(); //Main state-machine
  void onUDPSocketEvent(UDPSocketEvent e);
  void sendReply(uint16_t tid, Host dst); // temp
  
// 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))
#endif

#ifndef htonl
#define htonl( x ) ( (( x << 24 ) & 0xff000000)  \
                   | (( x <<  8 ) & 0x00ff0000)  \
                   | (( x >>  8 ) & 0x0000ff00)  \
                   | (( x >> 24 ) & 0x000000ff)  )
#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