mDNS

Dependents:   OS

This is a mDNS server.

Committer:
sPymbed
Date:
Wed Sep 11 10:40:41 2019 +0000
Revision:
5:4b6323e78f58
Parent:
4:47d30d199ce0
improved

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JBRYU 0:0df3300689d2 1 /*
JBRYU 0:0df3300689d2 2 Made by JB RYU, KOR - 2015
JBRYU 0:0df3300689d2 3
JBRYU 0:0df3300689d2 4 class mDNSResponder
JBRYU 0:0df3300689d2 5 */
JBRYU 0:0df3300689d2 6
JBRYU 0:0df3300689d2 7 #ifndef MDNS_RESPONDER_H
JBRYU 0:0df3300689d2 8 #define MDNS_RESPONDER_H
JBRYU 0:0df3300689d2 9
JBRYU 0:0df3300689d2 10 #include "lwip/opt.h"
JBRYU 0:0df3300689d2 11 #include "mbed.h"
JBRYU 0:0df3300689d2 12 #include "EthernetInterface.h"
JBRYU 0:0df3300689d2 13 #include "dns-sd.h"
JBRYU 0:0df3300689d2 14
JBRYU 2:2b00b659497a 15 #if LWIP_DNS
JBRYU 0:0df3300689d2 16
JBRYU 0:0df3300689d2 17 #include "mbed.h"
JBRYU 0:0df3300689d2 18 #include "mem.h"
JBRYU 0:0df3300689d2 19 #include "memp.h"
JBRYU 0:0df3300689d2 20 #include "dns.h"
JBRYU 0:0df3300689d2 21
JBRYU 0:0df3300689d2 22 #define MDNS_PORT (5353)
JBRYU 0:0df3300689d2 23 #define MCAST "224.0.0.251"
JBRYU 0:0df3300689d2 24
JBRYU 0:0df3300689d2 25 class mDNSResponder
JBRYU 0:0df3300689d2 26 {
JBRYU 0:0df3300689d2 27 public:
sPymbed 4:47d30d199ce0 28 mDNSResponder(EthernetInterface);
JBRYU 0:0df3300689d2 29 virtual ~mDNSResponder();
JBRYU 0:0df3300689d2 30 void close();
sPymbed 4:47d30d199ce0 31 void announce(const char* ip);
sPymbed 4:47d30d199ce0 32 void MDNS_process();
JBRYU 0:0df3300689d2 33
JBRYU 0:0df3300689d2 34 private:
JBRYU 0:0df3300689d2 35 void IPstringToByte(char* IPstr);
JBRYU 0:0df3300689d2 36 char* skip_name(char* query);
JBRYU 0:0df3300689d2 37 void query_domain(void);
JBRYU 0:0df3300689d2 38 void register_service(char* number);
JBRYU 0:0df3300689d2 39 char* decode_name(char* query, char* packet);
JBRYU 0:0df3300689d2 40 void send_dns_ans(struct dns_hdr* hdr);
JBRYU 0:0df3300689d2 41
JBRYU 2:2b00b659497a 42 /*static objs */
JBRYU 0:0df3300689d2 43 static MY_SD_DOMAINS SD_domains;
JBRYU 0:0df3300689d2 44 static struct dns_hdr SD_res_hdr;
JBRYU 0:0df3300689d2 45
JBRYU 0:0df3300689d2 46 static char query_buf[1500];
JBRYU 0:0df3300689d2 47 static QR_MAP g_queries;
JBRYU 0:0df3300689d2 48
JBRYU 0:0df3300689d2 49 char* IP_str;
JBRYU 0:0df3300689d2 50 uint8_t IP_byte[4];
JBRYU 0:0df3300689d2 51
JBRYU 0:0df3300689d2 52 UDPSocket mdns_sock;
sPymbed 4:47d30d199ce0 53 SocketAddress rcv_endpt; //initial value := ip addr any
sPymbed 4:47d30d199ce0 54 SocketAddress send_endpt;
JBRYU 0:0df3300689d2 55 };
JBRYU 0:0df3300689d2 56
JBRYU 0:0df3300689d2 57 #endif
JBRYU 0:0df3300689d2 58
JBRYU 0:0df3300689d2 59 #ifndef htons
JBRYU 0:0df3300689d2 60 #define htons( x ) ( (( x << 8 ) & 0xFF00) | (( x >> 8 ) & 0x00FF) )
JBRYU 0:0df3300689d2 61 #define ntohs( x ) (htons(x))
JBRYU 0:0df3300689d2 62 #endif
JBRYU 0:0df3300689d2 63
JBRYU 0:0df3300689d2 64 #ifndef htonl
JBRYU 0:0df3300689d2 65 #define htonl( x ) ( (( x << 24 ) & 0xff000000) \
JBRYU 0:0df3300689d2 66 | (( x << 8 ) & 0x00ff0000) \
JBRYU 0:0df3300689d2 67 | (( x >> 8 ) & 0x0000ff00) \
JBRYU 0:0df3300689d2 68 | (( x >> 24 ) & 0x000000ff) )
JBRYU 0:0df3300689d2 69 #define ntohl( x ) (htonl(x))
JBRYU 0:0df3300689d2 70 #endif
JBRYU 0:0df3300689d2 71
JBRYU 0:0df3300689d2 72 #endif