Skip to content

Commit 9b657b6

Browse files
fix to use DNS struct
1 parent 4dcaef3 commit 9b657b6

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

examples/mqttnet.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,6 @@ static int NetRead(void *context, byte* buf, int buf_len,
383383
/* -------------------------------------------------------------------------- */
384384
#elif defined(HAVE_NETX)
385385

386-
#ifndef WOLFMQTT_NO_NETX_DNS
387-
/* include the NetX DNS addon header */
388-
#include "nxd_dns.h"
389-
#endif
390-
391386
static int NetDisconnect(void *context)
392387
{
393388
SocketContext *sock = (SocketContext*)context;
@@ -419,8 +414,13 @@ static int NetConnect(void *context, const char* host, word16 port,
419414
"Use TLS %d", host, port, timeout_ms, mqttCtx->use_tls);
420415
}
421416
#ifndef WOLFMQTT_NO_NETX_DNS
417+
if (sock->dnsPtr == NULL) {
418+
PRINTF("DNS pointer was NULL and needs set, sock->dnsPtr");
419+
return MQTT_CODE_ERROR_NETWORK;
420+
}
421+
422422
/* Convert hostname to IP address using NETX DUO DNS */
423-
status = nxd_dns_host_by_name_get(sock->ipPtr, (UCHAR *)host,
423+
status = nxd_dns_host_by_name_get(sock->dnsPtr, (UCHAR *)host,
424424
&ipAddress, timeout_ms);
425425
if (status != NX_SUCCESS) {
426426
PRINTF("DNS lookup failed: %d", status);

examples/mqttnet.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
#include "examples/mqttexample.h"
3434
#include "examples/mqttport.h"
3535

36+
#if defined(HAVE_NETX) && !defined(WOLFMQTT_NO_NETX_DNS)
37+
/* include the NetX DNS addon header */
38+
#include "nxd_dns.h"
39+
#endif
40+
41+
3642
/* Local context for Net callbacks */
3743
typedef enum {
3844
SOCK_BEGIN = 0,
@@ -57,6 +63,9 @@ typedef struct _SocketContext {
5763
void* websocket_ctx;
5864
#endif
5965
#ifdef HAVE_NETX
66+
#ifndef WOLFMQTT_NO_NETX_DNS
67+
NX_DNS *dnsPtr;
68+
#endif
6069
NX_IP *ipPtr;
6170
NX_PACKET *nxPacket;
6271
ULONG nxOffset;

0 commit comments

Comments
 (0)