Minor tidy
This commit is contained in:
parent
4b1b2a5cc3
commit
6eb7ce9385
2 changed files with 627 additions and 633 deletions
|
|
@ -1,7 +1,16 @@
|
|||
/*
|
||||
* Basic multicast DNS responder
|
||||
*
|
||||
* Advertises the IP address, port, and characteristics of a service to other devices using multicast DNS on the same LAN,
|
||||
* so they can find devices with addresses dynamically allocated by DHCP. See avahi, Bonjour, etc
|
||||
* See RFC6762, RFC6763
|
||||
*
|
||||
* This sample code is in the public domain.
|
||||
*
|
||||
* by M J A Hamel 2016
|
||||
*/
|
||||
|
||||
|
||||
#include <espressif/esp_common.h>
|
||||
#include <espressif/esp_wifi.h>
|
||||
|
||||
|
|
@ -22,7 +31,7 @@
|
|||
|
||||
#include "mdnsresponder.h"
|
||||
|
||||
//#define qDebugLog // Log activity generally
|
||||
#define qDebugLog // Log activity generally
|
||||
//#define qLogIncoming // Log all arriving multicast packets
|
||||
//#define qLogAllTraffic // Log and decode all mDNS packets
|
||||
|
||||
|
|
@ -31,37 +40,6 @@
|
|||
#define DNS_MULTICAST_ADDRESS "224.0.0.251" // RFC 6762
|
||||
#define DNS_MDNS_PORT 5353 // RFC 6762
|
||||
|
||||
/** DNS field TYPE used for "Resource Records" */
|
||||
#define DNS_RRTYPE_A 1 /* a host address */
|
||||
#define DNS_RRTYPE_NS 2 /* an authoritative name server */
|
||||
#define DNS_RRTYPE_MD 3 /* a mail destination (Obsolete - use MX) */
|
||||
#define DNS_RRTYPE_MF 4 /* a mail forwarder (Obsolete - use MX) */
|
||||
#define DNS_RRTYPE_CNAME 5 /* the canonical name for an alias */
|
||||
#define DNS_RRTYPE_SOA 6 /* marks the start of a zone of authority */
|
||||
#define DNS_RRTYPE_WKS 11 /* a well known service description */
|
||||
#define DNS_RRTYPE_PTR 12 /* a domain name pointer */
|
||||
#define DNS_RRTYPE_HINFO 13 /* host information */
|
||||
#define DNS_RRTYPE_MINFO 14 /* mailbox or mail list information */
|
||||
#define DNS_RRTYPE_MX 15 /* mail exchange */
|
||||
#define DNS_RRTYPE_TXT 16 /* text strings */
|
||||
#define DNS_RRTYPE_AAAA 28 /* IPv6 host address */
|
||||
#define DNS_RRTYPE_SRV 33 /* Service record */
|
||||
#define DNS_RRTYPE_OPT 41 /* EDNS0 OPT record */
|
||||
#define DNS_RRTYPE_NSEC 47 /* NSEC record */
|
||||
#define DNS_RRTYPE_TSIG 250 /* Transaction Signature */
|
||||
#define DNS_RRTYPE_ANY 255 /* Not a DNS type, but a DNS query type, meaning "all types"*/
|
||||
|
||||
/* DNS field CLASS used for "Resource Records" */
|
||||
#define DNS_RRCLASS_IN 1 /* the Internet */
|
||||
#define DNS_RRCLASS_ANY 255 /* Any class (q) */
|
||||
|
||||
#define DNS_FLAG1_RESP 0x80
|
||||
#define DNS_FLAG1_OPMASK 0x78
|
||||
#define DNS_FLAG1_AUTH 0x04
|
||||
#define DNS_FLAG1_TRUNC 0x02
|
||||
#define DNS_FLAG1_RD 0x01
|
||||
#define DNS_FLAG2_RA 0x80
|
||||
#define DNS_FLAG2_RESMASK 0x0F
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#ifdef PACK_STRUCT_USE_INCLUDES
|
||||
|
|
@ -123,9 +101,6 @@ PACK_STRUCT_END
|
|||
# include "arch/epstruct.h"
|
||||
#endif
|
||||
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
#define vTaskDelayMs(ms) vTaskDelay((ms)/portTICK_PERIOD_MS)
|
||||
#define UNUSED_ARG(x) (void)x
|
||||
#define kDummyDataSize 8 // arbitrary, dynamically resized
|
||||
|
|
@ -143,13 +118,32 @@ typedef struct mdns_rsrc {
|
|||
} mdns_rsrc;
|
||||
|
||||
static struct udp_pcb* gMDNS_pcb = NULL;
|
||||
static ip_addr_t gMulticastAddr;
|
||||
static ip_addr_t gMulticastAddr; // == DNS_MULTICAST_ADDRESS
|
||||
static mdns_rsrc* gDictP = NULL; // RR database, linked list
|
||||
|
||||
//---------------------- Debug/logging utilities -------------------------
|
||||
|
||||
#ifdef qDebugLog
|
||||
|
||||
// DNS field TYPE used for "Resource Records", some additions
|
||||
#define DNS_RRTYPE_AAAA 28 /* IPv6 host address */
|
||||
#define DNS_RRTYPE_SRV 33 /* Service record */
|
||||
#define DNS_RRTYPE_OPT 41 /* EDNS0 OPT record */
|
||||
#define DNS_RRTYPE_NSEC 47 /* NSEC record */
|
||||
#define DNS_RRTYPE_TSIG 250 /* Transaction Signature */
|
||||
#define DNS_RRTYPE_ANY 255 /* Not a DNS type, but a DNS query type, meaning "all types"*/
|
||||
|
||||
// DNS field CLASS used for "Resource Records"
|
||||
#define DNS_RRCLASS_ANY 255 /* Any class (q) */
|
||||
|
||||
#define DNS_FLAG1_RESP 0x80
|
||||
#define DNS_FLAG1_OPMASK 0x78
|
||||
#define DNS_FLAG1_AUTH 0x04
|
||||
#define DNS_FLAG1_TRUNC 0x02
|
||||
#define DNS_FLAG1_RD 0x01
|
||||
#define DNS_FLAG2_RA 0x80
|
||||
#define DNS_FLAG2_RESMASK 0x0F
|
||||
|
||||
static char qstr[12];
|
||||
|
||||
static char* mdns_qrtype(uint16_t typ)
|
||||
|
|
@ -363,7 +357,7 @@ static u8_t* mdns_labels2str(u8_t* hdrP, u8_t* p, char* qStr)
|
|||
mdns_labels2str( hdrP, hdrP + n, qStr);
|
||||
return p;
|
||||
} else if (n & 0xC0) {
|
||||
printf(">>> error,label $%X?",n);
|
||||
printf(">>> mdns_labels2str,label $%X?",n);
|
||||
return p;
|
||||
} else {
|
||||
for (i=0; i<n; i++)
|
||||
|
|
@ -499,7 +493,7 @@ void mdns_add_facility( const char* instanceName, // Friendly name, need not b
|
|||
u32_t ttl // seconds
|
||||
)
|
||||
{
|
||||
char key[96];
|
||||
char key[64];
|
||||
char fullName[128];
|
||||
char devName[96];
|
||||
struct ip_info ipInfo;
|
||||
|
|
@ -718,12 +712,12 @@ static void mdns_start()
|
|||
err_t err;
|
||||
|
||||
if (sdk_wifi_get_opmode() != STATION_MODE) {
|
||||
printf(">>> mDNS start: wifi opmode not station\n");
|
||||
printf(">>> mDNS_start: wifi opmode not station\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!sdk_wifi_get_ip_info(STATION_IF,&ipInfo)) {
|
||||
printf(">>> mDNS start: no IP addr\n");
|
||||
printf(">>> mDNS_start: no IP addr\n");
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -737,7 +731,7 @@ static void mdns_start()
|
|||
nfp->flags |= NETIF_FLAG_IGMP;
|
||||
err = igmp_start(nfp);
|
||||
if (err != ERR_OK) {
|
||||
printf(">>> igmp_start on %c%c failed %d\n",nfp->name[0], nfp->name[1],err);
|
||||
printf(">>> mDNS_start: igmp_start on %c%c failed %d\n",nfp->name[0], nfp->name[1],err);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -747,17 +741,17 @@ static void mdns_start()
|
|||
|
||||
gMDNS_pcb = udp_new();
|
||||
if (!gMDNS_pcb) {
|
||||
printf(">>> udp_new failed\n");
|
||||
printf(">>> mDNS_start: udp_new failed\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if ((err=igmp_joingroup(&ipInfo.ip, &gMulticastAddr)) != ERR_OK) {
|
||||
printf(">>> igmp_join failed %d\n",err);
|
||||
printf(">>> mDNS_start: igmp_join failed %d\n",err);
|
||||
return;
|
||||
}
|
||||
|
||||
if ((err=udp_bind(gMDNS_pcb, IP_ADDR_ANY, DNS_MDNS_PORT)) != ERR_OK) {
|
||||
printf(">>> udp_bind failed %d\n",err);
|
||||
printf(">>> mDNS_start: udp_bind failed %d\n",err);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@
|
|||
* Basic multicast DNS responder
|
||||
*
|
||||
* Advertises the IP address, port, and characteristics of a service to other devices using multicast DNS on the same LAN,
|
||||
* so they can find devices with addresses dynamically allocated by DHCP. See avahi/Bonjour, etc
|
||||
* so they can find devices with addresses dynamically allocated by DHCP. See avahi, Bonjour, etc
|
||||
* See RFC6762, RFC6763
|
||||
*
|
||||
* This sample code is in the public domain.
|
||||
*
|
||||
* M J A Hamel 2016
|
||||
* by M J A Hamel 2016
|
||||
*/
|
||||
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ void mdns_init();
|
|||
typedef enum {
|
||||
mdns_TCP,
|
||||
mdns_UDP,
|
||||
mdns_Browsable // RFC6763:11 - adds a standard record that lets browsers find the service without needing to know its name
|
||||
mdns_Browsable // see RFC6763:11 - adds a standard record that lets browsers find the service without needing to know its name
|
||||
} mdns_flags;
|
||||
|
||||
void mdns_add_facility( const char* instanceName, // Short user-friendly instance name, should NOT include serial number/MAC/etc
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue