mDNS

Dependents:   OS

This is a mDNS server.

Committer:
sPymbed
Date:
Wed Nov 20 13:27:10 2019 +0000
Revision:
6:3bf9f4943d1a
Parent:
0:0df3300689d2
fixed: print line in screen

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JBRYU 0:0df3300689d2 1 /*
JBRYU 0:0df3300689d2 2 Edited by JB RYU, KOR - 2015
JBRYU 0:0df3300689d2 3
JBRYU 0:0df3300689d2 4 DNS-headers and values.
JBRYU 0:0df3300689d2 5
JBRYU 0:0df3300689d2 6 Actually, Defines for DNS-type-values are not necessary.
JBRYU 0:0df3300689d2 7 LWIP NETIF has defines for DNS formats already.
JBRYU 0:0df3300689d2 8 */
JBRYU 0:0df3300689d2 9
JBRYU 0:0df3300689d2 10 #ifndef DNS_SD_H_
JBRYU 0:0df3300689d2 11 #define DNS_SD_H_
JBRYU 0:0df3300689d2 12
JBRYU 0:0df3300689d2 13 #include <cstdint>
JBRYU 0:0df3300689d2 14
JBRYU 0:0df3300689d2 15 #ifdef __cplusplus
JBRYU 0:0df3300689d2 16 extern "C" {
JBRYU 0:0df3300689d2 17 #endif
JBRYU 0:0df3300689d2 18
JBRYU 0:0df3300689d2 19 #define UPPERBYTE(word)\
JBRYU 0:0df3300689d2 20 (unsigned char)(word >> 8)
JBRYU 0:0df3300689d2 21 #define LOWERBYTE(word)\
JBRYU 0:0df3300689d2 22 (unsigned char)(word)
JBRYU 0:0df3300689d2 23
JBRYU 0:0df3300689d2 24 /** \internal The DNS message header. */
JBRYU 0:0df3300689d2 25 #define DNS_FLAG1_RESPONSE 0x80
JBRYU 0:0df3300689d2 26 #define DNS_FLAG1_OPCODE_STATUS 0x10
JBRYU 0:0df3300689d2 27 #define DNS_FLAG1_OPCODE_INVERSE 0x08
JBRYU 0:0df3300689d2 28 #define DNS_FLAG1_OPCODE_STANDARD 0x00
JBRYU 0:0df3300689d2 29 #define DNS_FLAG1_AUTHORATIVE 0x04
JBRYU 0:0df3300689d2 30 #define DNS_FLAG1_TRUNC 0x02
JBRYU 0:0df3300689d2 31 #define DNS_FLAG1_RD 0x01
JBRYU 0:0df3300689d2 32 #define DNS_FLAG2_RA 0x80
JBRYU 0:0df3300689d2 33 #define DNS_FLAG2_ERR_MASK 0x0f
JBRYU 0:0df3300689d2 34 #define DNS_FLAG2_ERR_NONE 0x00
JBRYU 0:0df3300689d2 35 #define DNS_FLAG2_ERR_NAME 0x03
JBRYU 0:0df3300689d2 36
JBRYU 0:0df3300689d2 37 /** \internal The DNS question message structure. */
JBRYU 0:0df3300689d2 38 struct dns_question
JBRYU 0:0df3300689d2 39 {
JBRYU 0:0df3300689d2 40 uint16_t type;
JBRYU 0:0df3300689d2 41 uint16_t obj;
JBRYU 0:0df3300689d2 42 };
JBRYU 0:0df3300689d2 43
JBRYU 0:0df3300689d2 44 struct dns_hdr
JBRYU 0:0df3300689d2 45 {
JBRYU 0:0df3300689d2 46 uint16_t id;
JBRYU 0:0df3300689d2 47 uint8_t flags1, flags2;
JBRYU 0:0df3300689d2 48 uint16_t numquestions;
JBRYU 0:0df3300689d2 49 uint16_t numanswers;
JBRYU 0:0df3300689d2 50 uint16_t numauthrr;
JBRYU 0:0df3300689d2 51 uint16_t numextrarr;
JBRYU 0:0df3300689d2 52 };
JBRYU 0:0df3300689d2 53
JBRYU 0:0df3300689d2 54 /** \internal The DNS answer message structure. */
JBRYU 0:0df3300689d2 55 struct dns_answer
JBRYU 0:0df3300689d2 56 {
JBRYU 0:0df3300689d2 57 /* DNS answer record starts with either a domain name or a pointer
JBRYU 0:0df3300689d2 58 * to a name already present somewhere in the packet. */
JBRYU 0:0df3300689d2 59 uint16_t type;
JBRYU 0:0df3300689d2 60 uint16_t obj;
JBRYU 0:0df3300689d2 61 uint16_t ttl[2];
JBRYU 0:0df3300689d2 62 uint16_t len;
JBRYU 0:0df3300689d2 63 #if NET_IPV6
JBRYU 0:0df3300689d2 64 uint8_t ipaddr[16];
JBRYU 0:0df3300689d2 65 #else
JBRYU 0:0df3300689d2 66 uint8_t ipaddr[4];
JBRYU 0:0df3300689d2 67 #endif
JBRYU 0:0df3300689d2 68 };
JBRYU 0:0df3300689d2 69
JBRYU 0:0df3300689d2 70 #define DNS_TYPE_A 1
JBRYU 0:0df3300689d2 71 #define DNS_TYPE_CNAME 5
JBRYU 0:0df3300689d2 72 #define DNS_TYPE_PTR 12
JBRYU 0:0df3300689d2 73 #define DNS_TYPE_MX 15
JBRYU 0:0df3300689d2 74 #define DNS_TYPE_TXT 16
JBRYU 0:0df3300689d2 75 #define DNS_TYPE_AAAA 28
JBRYU 0:0df3300689d2 76 #define DNS_TYPE_SRV 33
JBRYU 0:0df3300689d2 77 #define DNS_TYPE_ANY 255
JBRYU 0:0df3300689d2 78 #define DNS_TYPE_NSEC 47
JBRYU 0:0df3300689d2 79
JBRYU 0:0df3300689d2 80 #if NET_IPV6
JBRYU 0:0df3300689d2 81 #define NATIVE_DNS_TYPE DNS_TYPE_AAAA /* IPv6 */
JBRYU 0:0df3300689d2 82 #else
JBRYU 0:0df3300689d2 83 #define NATIVE_DNS_TYPE DNS_TYPE_A /* IPv4 */
JBRYU 0:0df3300689d2 84 #endif
JBRYU 0:0df3300689d2 85
JBRYU 0:0df3300689d2 86 #define DNS_CLASS_IN 0x0001
JBRYU 0:0df3300689d2 87 #define DNS_CASH_FLUSH 0x8000
JBRYU 0:0df3300689d2 88 #define DNS_CLASS_ANY 0z00ff
JBRYU 0:0df3300689d2 89
JBRYU 0:0df3300689d2 90 /* all entities include its length */
JBRYU 0:0df3300689d2 91 #define MAX_DOMAIN_LEN 64
JBRYU 0:0df3300689d2 92 #define MAX_INSTANCE_NAME_LEN 64
JBRYU 0:0df3300689d2 93 #define MAX_SUBTYPE_NAME_LEN 69
JBRYU 0:0df3300689d2 94 #define MAX_SERVICE_NAME_LEN 22
JBRYU 0:0df3300689d2 95 #define MAX_SERVICE_DOMAIN_LEN 64
JBRYU 0:0df3300689d2 96 #define MAX_PARENT_DOMAIN_LEN 100 //.local so...
JBRYU 0:0df3300689d2 97 #define MDNS_P_DOMAIN_LEN 5
JBRYU 0:0df3300689d2 98
JBRYU 0:0df3300689d2 99 #define PTR_QUERY_NAME_LEN 18
JBRYU 0:0df3300689d2 100 #pragma pack (push, 1)
JBRYU 0:0df3300689d2 101 typedef struct
JBRYU 0:0df3300689d2 102 {
JBRYU 0:0df3300689d2 103 /* DNS answer record starts with either a domain name or a pointer
JBRYU 0:0df3300689d2 104 * to a name already present somewhere in the packet. */
JBRYU 0:0df3300689d2 105 uint16_t type;
JBRYU 0:0df3300689d2 106 uint16_t obj;
JBRYU 0:0df3300689d2 107 uint16_t ttl[2];
JBRYU 0:0df3300689d2 108 uint16_t len;
JBRYU 0:0df3300689d2 109 char name[MAX_INSTANCE_NAME_LEN
JBRYU 0:0df3300689d2 110 + MAX_SERVICE_NAME_LEN + MDNS_P_DOMAIN_LEN];
JBRYU 0:0df3300689d2 111 }PTR_ANS;
JBRYU 0:0df3300689d2 112
JBRYU 0:0df3300689d2 113 typedef struct
JBRYU 0:0df3300689d2 114 {
JBRYU 0:0df3300689d2 115 uint16_t type;
JBRYU 0:0df3300689d2 116 uint16_t obj;
JBRYU 0:0df3300689d2 117 uint16_t ttl[2];
JBRYU 0:0df3300689d2 118 uint16_t len;
JBRYU 0:0df3300689d2 119 uint16_t pri;
JBRYU 0:0df3300689d2 120 uint16_t wei;
JBRYU 0:0df3300689d2 121 uint16_t port;
JBRYU 0:0df3300689d2 122 char name[MAX_DOMAIN_LEN
JBRYU 0:0df3300689d2 123 + MDNS_P_DOMAIN_LEN];
JBRYU 0:0df3300689d2 124 }SRV_ANS;
JBRYU 0:0df3300689d2 125
JBRYU 0:0df3300689d2 126 typedef struct
JBRYU 0:0df3300689d2 127 {
JBRYU 0:0df3300689d2 128 uint16_t type;
JBRYU 0:0df3300689d2 129 uint16_t obj;
JBRYU 0:0df3300689d2 130 uint16_t ttl[2];
JBRYU 0:0df3300689d2 131 uint16_t len;
JBRYU 0:0df3300689d2 132 char txt[1024];
JBRYU 0:0df3300689d2 133 }TXT_ANS;
JBRYU 0:0df3300689d2 134
JBRYU 0:0df3300689d2 135 typedef struct
JBRYU 0:0df3300689d2 136 {
JBRYU 0:0df3300689d2 137 uint8_t len_txtvers;
JBRYU 0:0df3300689d2 138 char txtvers[10];
JBRYU 0:0df3300689d2 139 uint8_t len_dcap;
JBRYU 0:0df3300689d2 140 char dcap[10];
JBRYU 0:0df3300689d2 141 uint8_t len_path;
JBRYU 0:0df3300689d2 142 char path[10];
JBRYU 0:0df3300689d2 143 uint8_t len_https;
JBRYU 0:0df3300689d2 144 char https[10];
JBRYU 0:0df3300689d2 145 uint8_t len_level;
JBRYU 0:0df3300689d2 146 char level[10];
JBRYU 0:0df3300689d2 147 }__SEP_TXT;
JBRYU 0:0df3300689d2 148
JBRYU 0:0df3300689d2 149 typedef struct
JBRYU 0:0df3300689d2 150 {
JBRYU 0:0df3300689d2 151 uint8_t inst_len;
JBRYU 0:0df3300689d2 152 char instance[63]; //RYU-PC
JBRYU 0:0df3300689d2 153 uint8_t serv_len;
JBRYU 0:0df3300689d2 154 char service[16]; //_http
JBRYU 0:0df3300689d2 155 uint8_t trl_len;
JBRYU 0:0df3300689d2 156 char trl[4]; //_tcp
JBRYU 0:0df3300689d2 157 uint8_t domain_len;
JBRYU 0:0df3300689d2 158 char domain[5]; //local
JBRYU 0:0df3300689d2 159 __SEP_TXT txt;
JBRYU 0:0df3300689d2 160 }__SD_DOMAIN;
JBRYU 0:0df3300689d2 161 #pragma pack (pop)
JBRYU 0:0df3300689d2 162
JBRYU 0:0df3300689d2 163 #define N_CONTIKI_SERVICES 1
JBRYU 0:0df3300689d2 164 typedef struct
JBRYU 0:0df3300689d2 165 {
JBRYU 0:0df3300689d2 166 int numbers;
JBRYU 0:0df3300689d2 167 __SD_DOMAIN elements[N_CONTIKI_SERVICES];
JBRYU 0:0df3300689d2 168 }MY_SD_DOMAINS;
JBRYU 0:0df3300689d2 169
JBRYU 0:0df3300689d2 170 typedef struct
JBRYU 0:0df3300689d2 171 {
JBRYU 0:0df3300689d2 172 int numbers;
JBRYU 0:0df3300689d2 173 uint8_t reqs[10];
JBRYU 0:0df3300689d2 174 }QR_MAP;
JBRYU 0:0df3300689d2 175
JBRYU 0:0df3300689d2 176 #ifdef __cplusplus
JBRYU 0:0df3300689d2 177 }
JBRYU 0:0df3300689d2 178 #endif
JBRYU 0:0df3300689d2 179
JBRYU 0:0df3300689d2 180 #endif
JBRYU 0:0df3300689d2 181