37#include "sys/socket.h"
42#define DEFAULT_LOOKUP "www.morsemicro.com"
44#ifndef DNS_MAX_NAME_LENGTH
46#define DNS_MAX_NAME_LENGTH (256)
56static void dns_lookup(
const char *hostname,
int ai_family)
64 struct addrinfo hints = { 0 };
65 hints.ai_family = ai_family;
66 hints.ai_socktype = SOCK_STREAM;
67 hints.ai_protocol = IPPROTO_TCP;
69 struct addrinfo *addr_list, *cur;
70 int ret = getaddrinfo(hostname, NULL, &hints, &addr_list);
78 for (cur = addr_list; cur != NULL; cur = cur->ai_next)
93 const char *result = NULL;
95 if (cur->ai_family == AF_INET)
97#if MMIPAL_IPV4_ENABLED
98 const struct sockaddr_in *sockaddr = (
const struct sockaddr_in *)cur->ai_addr;
99 result = inet_ntop(cur->ai_family, &sockaddr->sin_addr,
100 addr_str,
sizeof(addr_str));
103#if MMIPAL_IPV6_ENABLED
104 else if (cur->ai_family == AF_INET6)
106 const struct sockaddr_in6 *sockaddr = (
const struct sockaddr_in6 *)cur->ai_addr;
107 result = inet_ntop(cur->ai_family, &sockaddr->sin6_addr,
108 addr_str,
sizeof(addr_str));
114 printf(
" %s\n", result);
118 printf(
"Error: Failed to convert IP address to string\n");
121 freeaddrinfo(addr_list);
125 const char *family_str;
141 printf(
"Could not resolve %s address for hostname %s! (Error code %d)\n",
142 family_str, hostname, ret);
155 printf(
"\n\nMorse DNS client Demo (Built " __DATE__
" " __TIME__
")\n\n");
165 printf(
"Hostname %s resolves to:\n", hostname);
#define DNS_MAX_NAME_LENGTH
Maximum supported length of hostname for DNS lookup.
static void dns_lookup(const char *hostname, int ai_family)
Perform a DNS lookup for the given hostname and print the results.
#define DEFAULT_LOOKUP
This is the default hostname to lookup if none are specified in config store.
void app_init(void)
Main entry point to the application.
int mmconfig_read_string(const char *key, char *buffer, int bufsize)
Returns the persistent store string value identified by the key.
#define MMIPAL_IPADDR_STR_MAXLEN
Maximum length of an IP address string, including null-terminator.
Morse Micro application helper routines for initializing/de-initializing the Wireless LAN interface a...
void app_wlan_stop(void)
Disconnects from Wi-Fi and de-initializes the WLAN interface.
void app_wlan_init(void)
Initializes the WLAN interface (and dependencies) using settings specified in the config store.
void app_wlan_start(void)
Starts the WLAN interface and connects to Wi-Fi using settings specified in the config store.