Fix mdnsresponder compilation issues (#481)
This commit is contained in:
parent
f67495f4f0
commit
6faf7c569d
2 changed files with 72 additions and 69 deletions
|
@ -25,6 +25,7 @@
|
|||
#include <lwip/sys.h>
|
||||
#include <lwip/netdb.h>
|
||||
#include <lwip/dns.h>
|
||||
#include <lwip/prot/dns.h>
|
||||
#include <lwip/udp.h>
|
||||
#include <lwip/igmp.h>
|
||||
#include <lwip/netif.h>
|
||||
|
@ -39,6 +40,7 @@
|
|||
|
||||
#define DNS_MULTICAST_ADDRESS "224.0.0.251" // RFC 6762
|
||||
#define DNS_MDNS_PORT 5353 // RFC 6762
|
||||
#define DNS_MSG_SIZE 512
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
|
@ -480,17 +482,17 @@ void mdns_add_TXT(const char* rKey, u32_t ttl, const char* txStr)
|
|||
}
|
||||
}
|
||||
|
||||
void mdns_add_A(const char* rKey, u32_t ttl, struct ip_addr addr)
|
||||
void mdns_add_A(const char* rKey, u32_t ttl, ip_addr_t addr)
|
||||
{
|
||||
mdns_add_response(rKey, DNS_RRTYPE_A, ttl, &addr, sizeof(addr));
|
||||
}
|
||||
|
||||
void mdns_add_facility( const char* instanceName, // Friendly name, need not be unique
|
||||
const char* serviceName, // Must be _name
|
||||
const char* serviceName, // Must be "name", e.g. "hap" or "http"
|
||||
const char* addText, // Must be <key>=<value>
|
||||
mdns_flags flags, // TCP or UDP
|
||||
u16_t onPort, // port number
|
||||
u32_t ttl // seconds
|
||||
mdns_flags flags, // TCP or UDP
|
||||
u16_t onPort, // port number
|
||||
u32_t ttl // seconds
|
||||
)
|
||||
{
|
||||
char key[64];
|
||||
|
@ -500,26 +502,25 @@ void mdns_add_facility( const char* instanceName, // Friendly name, need not b
|
|||
|
||||
#ifdef qDebugLog
|
||||
printf("\nmDNS advertising instance %s protocol %s text %s on port %d %s TTL %d secs\n",
|
||||
instanceName,serviceName,addText,onPort,(flags & mdns_UDP) ? "UDP" : "TCP", ttl);
|
||||
instanceName, serviceName, addText, onPort, (flags & mdns_UDP) ? "UDP" : "TCP", ttl);
|
||||
#endif
|
||||
|
||||
snprintf(key,sizeof(key),"%s.%s.local.",serviceName,(flags & mdns_UDP) ? "_udp" :"_tcp");
|
||||
snprintf(fullName,sizeof(fullName),"%s.%s",instanceName,key);
|
||||
snprintf(devName,sizeof(devName),"%s.local.",instanceName);
|
||||
snprintf(key, sizeof(key), "%s.%s.local.", serviceName, (flags & mdns_UDP) ? "_udp" :"_tcp");
|
||||
snprintf(fullName, sizeof(fullName), "%s.%s", instanceName, key);
|
||||
snprintf(devName, sizeof(devName), "%s.local.", instanceName);
|
||||
|
||||
if (!sdk_wifi_get_ip_info(STATION_IF,&ipInfo))
|
||||
ipInfo.ip.addr = IPADDR_NONE;
|
||||
|
||||
// Order has significance for extraRR feature
|
||||
mdns_add_TXT(fullName,ttl,addText);
|
||||
mdns_add_A(devName,ttl,ipInfo.ip);
|
||||
mdns_add_SRV(fullName,ttl,onPort,devName);
|
||||
mdns_add_PTR(key,ttl,fullName);
|
||||
mdns_add_TXT(fullName, ttl, addText);
|
||||
mdns_add_A(devName, ttl, ipInfo.ip);
|
||||
mdns_add_SRV(fullName, ttl, onPort, devName);
|
||||
mdns_add_PTR(key, ttl, fullName);
|
||||
|
||||
// Optional, makes us browsable
|
||||
if (flags & mdns_Browsable)
|
||||
mdns_add_PTR("_services._dns-sd._udp.local.",ttl,key);
|
||||
|
||||
}
|
||||
|
||||
static void mdns_update_ipaddr(struct ip_info* ipInfo)
|
||||
|
@ -639,7 +640,7 @@ static void mdns_reply(struct mdns_hdr* hdrP)
|
|||
|
||||
qp = mdns_get_question(qBase, qp, qStr, &qClass, &qType, &qUnicast);
|
||||
if (qClass==DNS_RRCLASS_IN || qClass==DNS_RRCLASS_ANY) {
|
||||
rsrcP = mdns_match(qStr,qType);
|
||||
rsrcP = mdns_match(qStr, qType);
|
||||
if (rsrcP) {
|
||||
respLen = mdns_add_to_answer(rsrcP, mdns_response, respLen);
|
||||
rHdr->numanswers = htons( htons(rHdr->numanswers) + 1 );
|
||||
|
@ -661,12 +662,12 @@ static void mdns_reply(struct mdns_hdr* hdrP)
|
|||
respLen = mdns_add_to_answer(extra, mdns_response, respLen);
|
||||
rHdr->numextrarr = htons( htons(rHdr->numextrarr) + 1 );
|
||||
}
|
||||
mdns_send_mcast(mdns_response,respLen);
|
||||
mdns_send_mcast(mdns_response, respLen);
|
||||
}
|
||||
free(mdns_response);
|
||||
}
|
||||
|
||||
static void mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, struct ip_addr *addr, u16_t port)
|
||||
static void mdns_recv(void *arg, struct udp_pcb *pcb, struct pbuf *p, ip_addr_t *addr, u16_t port)
|
||||
// Callback from udp_recv
|
||||
{
|
||||
UNUSED_ARG(pcb);
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef __MDNSRESPONDER_H__
|
||||
#define __MDNSRESPONDER_H__
|
||||
|
||||
#include <lwip/ip_addr.h>
|
||||
|
||||
/*
|
||||
* Basic multicast DNS responder
|
||||
*
|
||||
|
@ -40,7 +42,7 @@ void mdns_add_facility( const char* instanceName, // Short user-friendly insta
|
|||
void mdns_add_PTR(const char* rKey, u32_t ttl, const char* nameStr);
|
||||
void mdns_add_SRV(const char* rKey, u32_t ttl, u16_t rPort, const char* targname);
|
||||
void mdns_add_TXT(const char* rKey, u32_t ttl, const char* txtStr);
|
||||
void mdns_add_A (const char* rKey, u32_t ttl, struct ip_addr addr);
|
||||
void mdns_add_A (const char* rKey, u32_t ttl, ip_addr_t addr);
|
||||
|
||||
/* Sample usage, advertising a secure web service
|
||||
|
||||
|
|
Loading…
Reference in a new issue