mDNS

Dependents:   OS

This is a mDNS server.

mDNSResponder.h

Committer:
JBRYU
Date:
2015-08-11
Revision:
0:0df3300689d2
Child:
2:2b00b659497a

File content as of revision 0:0df3300689d2:

/*
    Made by JB RYU, KOR - 2015
    
    class mDNSResponder
*/

#ifndef MDNS_RESPONDER_H
#define MDNS_RESPONDER_H

#include "lwip/opt.h"
#include "mbed.h"
#include "EthernetInterface.h"
#include "dns-sd.h"

#if LWIP_DNS /* don't build if not configured for use in lwipopts.h */

#include "mbed.h"
#include "mem.h"
#include "memp.h"
#include "dns.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

#ifndef MDNS_QCACHE
#define MDNS_QCACHE 1
#endif

#ifndef MDNS_MAXCACHEDNSLABELS
#define MDNS_MAXCACHEDNSLABELS (10)
#endif

class mDNSResponder
{
public:
    mDNSResponder();
    virtual ~mDNSResponder();
    void close();
    void announce(char* ip);
    void MDNS_process(void const *args);
  
private:
  void IPstringToByte(char* IPstr);
    char* skip_name(char* query);
    void query_domain(void);
    void register_service(char* number);
    char* decode_name(char* query, char* packet);
    void send_dns_ans(struct dns_hdr* hdr);

    /*static objs from my uip-mdns */
    static MY_SD_DOMAINS SD_domains;
    static char PTR_query_name[PTR_QUERY_NAME_LEN];
    static struct dns_hdr SD_res_hdr;

    static char query_buf[1500];
    static QR_MAP g_queries;
    /* end - from my dns */
    
  char* IP_str;
  uint8_t IP_byte[4];
    
  UDPSocket mdns_sock;
    Endpoint rcv_endpt; //initial value := ip addr any
    Endpoint send_endpt;
};

#endif

#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

#endif