Skip to content

Fix ESP8266NetBIOS to compile with lwip V2 #3823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Nov 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions libraries/ESP8266NetBIOS/ESP8266NetBIOS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ extern "C" {

#define NBNSQ_TYPE_NB (0x0020)
#define NBNSQ_CLASS_IN (0x0001)
#ifndef LWIP_PLATFORM_HTONS
#define LWIP_PLATFORM_HTONS(_n) ((u16_t)((((_n) & 0xff) << 8) | (((_n) >> 8) & 0xff)))
#endif
#ifndef LWIP_PLATFORM_HTONL
#define LWIP_PLATFORM_HTONL(_n) ((u32_t)( (((_n) & 0xff) << 24) | (((_n) & 0xff00) << 8) | (((_n) >> 8) & 0xff00) | (((_n) >> 24) & 0xff) ))
#endif

// Definice struktury NBNS dotazu (alespon veci, ktere jsem vypozoroval):
struct NBNSQUESTION {
Expand Down Expand Up @@ -140,7 +146,7 @@ bool ESP8266NetBIOS::begin(const char *name)
}

// presuneme jmeno zarizeni se soucasnou upravou na UPPER case
for (int i = 0; i < n; ++i) {
for (size_t i = 0; i < n; ++i) {
_name[i] = toupper(name[i]);
}
_name[n] = '\0';
Expand Down Expand Up @@ -168,8 +174,15 @@ void ESP8266NetBIOS::end()
}
}

void ESP8266NetBIOS::_recv(udp_pcb *upcb, pbuf *pb, ip_addr_t *addr, u16_t port)
#if LWIP_VERSION_MAJOR == 1
void ESP8266NetBIOS::_recv(udp_pcb *upcb, pbuf *pb, ip_addr_t *addr, uint16_t port)
#else
void ESP8266NetBIOS::_recv(udp_pcb *upcb, pbuf *pb, const ip_addr_t *addr, uint16_t port)
#endif
{
(void)upcb;
(void)addr;
(void)port;
while(pb != NULL) {
uint8_t * data = (uint8_t*)((pb)->payload);
size_t len = pb->len;
Expand Down Expand Up @@ -256,7 +269,11 @@ void ESP8266NetBIOS::_recv(udp_pcb *upcb, pbuf *pb, ip_addr_t *addr, u16_t port)
}
}

#if LWIP_VERSION_MAJOR == 1
void ESP8266NetBIOS::_s_recv(void *arg, udp_pcb *upcb, pbuf *p, struct ip_addr *addr, uint16_t port)
#else
void ESP8266NetBIOS::_s_recv(void *arg, udp_pcb *upcb, pbuf *p, const ip_addr_t *addr, uint16_t port)
#endif
{
reinterpret_cast<ESP8266NetBIOS*>(arg)->_recv(upcb, p, addr, port);
}
Expand Down
11 changes: 10 additions & 1 deletion libraries/ESP8266NetBIOS/ESP8266NetBIOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#ifndef __ESPNBNS_h__
#define __ESPNBNS_h__

extern "C" {
#include "lwip/init.h" // LWIP_VERSION_
#include <lwip/ip_addr.h>
}
#include <ESP8266WiFi.h>

#define NBNS_PORT 137
Expand All @@ -15,7 +19,6 @@

struct udp_pcb;
struct pbuf;
struct ip_addr;

class ESP8266NetBIOS
{
Expand All @@ -24,8 +27,14 @@ class ESP8266NetBIOS
char _name[NBNS_MAX_HOSTNAME_LEN + 1];
void _getnbname(char *nbname, char *name, uint8_t maxlen);
void _makenbname(char *name, char *nbname, uint8_t outlen);

#if LWIP_VERSION_MAJOR == 1
void _recv(udp_pcb *upcb, pbuf *pb, struct ip_addr *addr, uint16_t port);
static void _s_recv(void *arg, udp_pcb *upcb, pbuf *p, struct ip_addr *addr, uint16_t port);
#else
void _recv(udp_pcb *upcb, pbuf *pb, const ip_addr_t *addr, uint16_t port);
static void _s_recv(void *arg, udp_pcb *upcb, pbuf *p, const ip_addr_t *addr, uint16_t port);
#endif
public:
ESP8266NetBIOS();
~ESP8266NetBIOS();
Expand Down