mirror of
https://github.com/DCC-EX/CommandStation-EX.git
synced 2024-12-23 21:01:25 +01:00
Fixes for Mega, HTONS/L macro
This commit is contained in:
parent
9602c32ea7
commit
6b0dc272ea
21
EXmDNS.cpp
21
EXmDNS.cpp
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* © 2024 Harald Barth
|
* © 2024 Harald Barth
|
||||||
|
* © 2024 Paul M. Antoine
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This file is part of CommandStation-EX
|
* This file is part of CommandStation-EX
|
||||||
@ -87,6 +88,7 @@ int MDNS::begin(const IPAddress& ip, char* name) {
|
|||||||
|
|
||||||
int MDNS::addServiceRecord(const char* name, uint16_t port, MDNSServiceProtocol_t proto) {
|
int MDNS::addServiceRecord(const char* name, uint16_t port, MDNSServiceProtocol_t proto) {
|
||||||
// we ignore proto, assume TCP
|
// we ignore proto, assume TCP
|
||||||
|
(void)proto;
|
||||||
_serviceName = (char *)malloc(strlen(name) + 2);
|
_serviceName = (char *)malloc(strlen(name) + 2);
|
||||||
byte n;
|
byte n;
|
||||||
for(n = 0; n<strlen(name); n++)
|
for(n = 0; n<strlen(name); n++)
|
||||||
@ -125,13 +127,14 @@ void MDNS::run() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lastrun = now;
|
lastrun = now;
|
||||||
DNSHeader_t dnsHeader = { 0 };
|
DNSHeader_t dnsHeader = {0, 0, 0, 0, 0, 0};
|
||||||
|
// DNSHeader_t dnsHeader = { 0 };
|
||||||
|
|
||||||
_udp->beginPacket(mdnsMulticastIPAddr, MDNS_SERVER_PORT);
|
_udp->beginPacket(mdnsMulticastIPAddr, MDNS_SERVER_PORT);
|
||||||
|
|
||||||
// dns header
|
// dns header
|
||||||
dnsHeader.flags = lwip_htons(0x8400); // Response, authorative
|
dnsHeader.flags = HTONS((uint16_t)0x8400); // Response, authorative
|
||||||
dnsHeader.answerCount = lwip_htons(4 /*5 if TXT but we do not do that */);
|
dnsHeader.answerCount = HTONS(4 /*5 if TXT but we do not do that */);
|
||||||
_udp->write((uint8_t*)&dnsHeader, sizeof(DNSHeader_t));
|
_udp->write((uint8_t*)&dnsHeader, sizeof(DNSHeader_t));
|
||||||
|
|
||||||
// rr #1, the PTR record from generic _services.x.local to service.x.local
|
// rr #1, the PTR record from generic _services.x.local to service.x.local
|
||||||
@ -142,8 +145,8 @@ void MDNS::run() {
|
|||||||
buf[1] = 0x0c; //PTR
|
buf[1] = 0x0c; //PTR
|
||||||
buf[2] = 0x00;
|
buf[2] = 0x00;
|
||||||
buf[3] = 0x01; //IN
|
buf[3] = 0x01; //IN
|
||||||
*((uint32_t*)(buf+4)) = lwip_htonl(120); //TTL in sec
|
*((uint32_t*)(buf+4)) = HTONL(120); //TTL in sec
|
||||||
*((uint16_t*)(buf+8)) = lwip_htons( _serviceProto[0] + 1 + strlen(dns_rr_tcplocal) + 1);
|
*((uint16_t*)(buf+8)) = HTONS( _serviceProto[0] + 1 + strlen(dns_rr_tcplocal) + 1);
|
||||||
_udp->write(buf, 10);
|
_udp->write(buf, 10);
|
||||||
|
|
||||||
_udp->write(_serviceProto,_serviceProto[0]+1);
|
_udp->write(_serviceProto,_serviceProto[0]+1);
|
||||||
@ -152,7 +155,7 @@ void MDNS::run() {
|
|||||||
// rr #2, the PTR record from proto.x to name.proto.x
|
// rr #2, the PTR record from proto.x to name.proto.x
|
||||||
_udp->write(_serviceProto,_serviceProto[0]+1);
|
_udp->write(_serviceProto,_serviceProto[0]+1);
|
||||||
_udp->write(dns_rr_tcplocal, strlen(dns_rr_tcplocal)+1);
|
_udp->write(dns_rr_tcplocal, strlen(dns_rr_tcplocal)+1);
|
||||||
*((uint16_t*)(buf+8)) = lwip_htons(strlen(_serviceName) + strlen(dns_rr_tcplocal) + 1); // recycle most of buf
|
*((uint16_t*)(buf+8)) = HTONS(strlen(_serviceName) + strlen(dns_rr_tcplocal) + 1); // recycle most of buf
|
||||||
_udp->write(buf, 10);
|
_udp->write(buf, 10);
|
||||||
|
|
||||||
_udp->write(_serviceName, strlen(_serviceName));
|
_udp->write(_serviceName, strlen(_serviceName));
|
||||||
@ -163,14 +166,14 @@ void MDNS::run() {
|
|||||||
|
|
||||||
buf[1] = 0x21; // recycle most of buf but here SRV
|
buf[1] = 0x21; // recycle most of buf but here SRV
|
||||||
buf[2] = 0x80; // cache flush
|
buf[2] = 0x80; // cache flush
|
||||||
*((uint16_t*)(buf+8)) = lwip_htons(strlen(_name) + strlen(dns_rr_local) + 1 + 6);
|
*((uint16_t*)(buf+8)) = HTONS(strlen(_name) + strlen(dns_rr_local) + 1 + 6);
|
||||||
_udp->write(buf, 10);
|
_udp->write(buf, 10);
|
||||||
|
|
||||||
byte srv[6];
|
byte srv[6];
|
||||||
// priority and weight
|
// priority and weight
|
||||||
srv[0] = srv[1] = srv[2] = srv[3] = 0;
|
srv[0] = srv[1] = srv[2] = srv[3] = 0;
|
||||||
// port
|
// port
|
||||||
*((uint16_t*)(srv+4)) = lwip_htons(_servicePort);
|
*((uint16_t*)(srv+4)) = HTONS(_servicePort);
|
||||||
_udp->write(srv, 6);
|
_udp->write(srv, 6);
|
||||||
// target
|
// target
|
||||||
_udp->write(_name, _name[0]+1);
|
_udp->write(_name, _name[0]+1);
|
||||||
@ -181,7 +184,7 @@ void MDNS::run() {
|
|||||||
_udp->write(dns_rr_local, strlen(dns_rr_local)+1);
|
_udp->write(dns_rr_local, strlen(dns_rr_local)+1);
|
||||||
|
|
||||||
buf[1] = 0x01; // recycle most of buf but here A
|
buf[1] = 0x01; // recycle most of buf but here A
|
||||||
*((uint16_t*)(buf+8)) = lwip_htons(4);
|
*((uint16_t*)(buf+8)) = HTONS(4);
|
||||||
_udp->write(buf, 10);
|
_udp->write(buf, 10);
|
||||||
byte ip[4];
|
byte ip[4];
|
||||||
ip[0] = _ipAddress[0];
|
ip[0] = _ipAddress[0];
|
||||||
|
6
EXmDNS.h
6
EXmDNS.h
@ -1,5 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* © 2024 Harald Barth
|
* © 2024 Harald Barth
|
||||||
|
* © 2024 Paul M. Antoine
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* This file is part of CommandStation-EX
|
* This file is part of CommandStation-EX
|
||||||
@ -20,6 +21,11 @@
|
|||||||
#ifdef DO_MDNS
|
#ifdef DO_MDNS
|
||||||
#define BROADCASTTIME 15 //seconds
|
#define BROADCASTTIME 15 //seconds
|
||||||
|
|
||||||
|
// We do this ourselves because every library is different and/or broken...
|
||||||
|
#define HTONS(x) ((uint16_t)(((x) << 8) | (((x) >> 8) & 0xFF)))
|
||||||
|
#define HTONL(x) ( ((uint32_t)(x) << 24) | (((uint32_t)(x) << 8) & 0xFF0000) | \
|
||||||
|
(((uint32_t)(x) >> 8) & 0xFF00) | ((uint32_t)(x) >> 24) )
|
||||||
|
|
||||||
typedef enum _MDNSServiceProtocol_t
|
typedef enum _MDNSServiceProtocol_t
|
||||||
{
|
{
|
||||||
MDNSServiceTCP,
|
MDNSServiceTCP,
|
||||||
|
@ -116,7 +116,7 @@ void EthernetInterface::setup()
|
|||||||
outboundRing=new RingStream(OUTBOUND_RING_SIZE);
|
outboundRing=new RingStream(OUTBOUND_RING_SIZE);
|
||||||
#ifdef DO_MDNS
|
#ifdef DO_MDNS
|
||||||
if (!mdns.begin(Ethernet.localIP(), (char *)WIFI_HOSTNAME))
|
if (!mdns.begin(Ethernet.localIP(), (char *)WIFI_HOSTNAME))
|
||||||
DIAG("mdns.begin fail"); // hostname
|
DIAG(F("mdns.begin fail")); // hostname
|
||||||
mdns.addServiceRecord(WIFI_HOSTNAME "._withrottle", IP_PORT, MDNSServiceTCP);
|
mdns.addServiceRecord(WIFI_HOSTNAME "._withrottle", IP_PORT, MDNSServiceTCP);
|
||||||
mdns.run(); // run it right away to get out info ASAP
|
mdns.run(); // run it right away to get out info ASAP
|
||||||
#endif
|
#endif
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
* © 2021 Neil McKechnie
|
* © 2021 Neil McKechnie
|
||||||
* © 2021 Mike S
|
* © 2021 Mike S
|
||||||
* © 2021 Fred Decker
|
* © 2021 Fred Decker
|
||||||
* © 2020-2022 Harald Barth
|
* © 2020-2024 Harald Barth
|
||||||
* © 2020-2024 Chris Harlow
|
* © 2020-2024 Chris Harlow
|
||||||
* © 2020 Gregor Baues
|
* © 2020 Gregor Baues
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
@ -41,9 +41,10 @@
|
|||||||
#ifndef MAX_SOCK_NUM
|
#ifndef MAX_SOCK_NUM
|
||||||
#define MAX_SOCK_NUM 4
|
#define MAX_SOCK_NUM 4
|
||||||
#endif
|
#endif
|
||||||
|
// can't use our MDNS because of a namespace clash with Teensy's NativeEthernet library!
|
||||||
|
// #define DO_MDNS
|
||||||
#elif defined (ARDUINO_NUCLEO_F429ZI) || defined (ARDUINO_NUCLEO_F439ZI) || defined (ARDUINO_NUCLEO_F4X9ZI)
|
#elif defined (ARDUINO_NUCLEO_F429ZI) || defined (ARDUINO_NUCLEO_F439ZI) || defined (ARDUINO_NUCLEO_F4X9ZI)
|
||||||
#include <LwIP.h>
|
#include <LwIP.h>
|
||||||
// #include "STM32lwipopts.h"
|
|
||||||
#include <STM32Ethernet.h>
|
#include <STM32Ethernet.h>
|
||||||
#include <lwip/netif.h>
|
#include <lwip/netif.h>
|
||||||
extern "C" struct netif gnetif;
|
extern "C" struct netif gnetif;
|
||||||
@ -52,7 +53,10 @@
|
|||||||
#define DO_MDNS
|
#define DO_MDNS
|
||||||
#else
|
#else
|
||||||
#include "Ethernet.h"
|
#include "Ethernet.h"
|
||||||
|
#define DO_MDNS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "RingStream.h"
|
#include "RingStream.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user