WL865E4-P  36.07.001
M2MB DNS CLIENT

This section describes the M2MB APIs to perform various Domain Name System (DNS) client operations. More...

enum  M2MB_DNS_SERVER_ID {
  M2MB_DNS_SERVER_PRIMARY,
  M2MB_DNS_SERVER_SECONDARY
}
 
typedef enum M2MB_DNS_SERVER_ID M2MB_DNS_SERVER_ID_E
 
typedef struct M2MB_HOST_NAME_TO_IP M2MB_HOST_NAME_TO_IP_T
 Structure to get IP address from host name. More...
 
M2MB_STATUS_T m2mb_dns_client_init (VOID)
 Initialize DNS client. More...
 
M2MB_STATUS_T m2mb_dns_client_is_started (VOID)
 Check the status of DNS client. More...
 
M2MB_STATUS_T m2mb_dns_client_deinit (VOID)
 De-initialize DNS client module. More...
 
M2MB_STATUS_T m2mb_dns_client_svr_add (UINT8 *ipAddr, M2MB_DNS_SERVER_ID_E serverID)
 Add a DNS server. More...
 
M2MB_STATUS_T m2mb_dns_client_svr_delete (M2MB_DNS_SERVER_ID_E serverID)
 Delete the DNS server details. More...
 
M2MB_HOST_NAME_TO_IP_Tm2mb_dns_client_get_host_by_name (UINT8 *name)
 Get IP address of host name. More...
 
M2MB_HOST_NAME_TO_IP_Tm2mb_dns_client_get_host_by_name2 (UINT8 *name, INT32 af)
 Get the IP address from the host name of the server. More...
 
M2MB_STATUS_T m2mb_dns_client_resolve_host (UINT8 *hostname, M2MB_IP46_ADDR_T *ipaddr)
 Resolve the URL details. More...
 
M2MB_STATUS_T m2mb_dns_client_get_server_list (M2MB_NWIF_DNS_SERVER_LIST_T *srv_list)
 Get the DNS server list. More...
 

Detailed Description

This section describes the M2MB APIs to perform various Domain Name System (DNS) client operations.

Typedef Documentation

◆ M2MB_DNS_SERVER_ID_E

◆ M2MB_HOST_NAME_TO_IP_T

Structure to get IP address from host name.

This data structure is used to get the IP address of a given host name.
This is the same as the UNIX struct hostent{}.

Enumeration Type Documentation

◆ M2MB_DNS_SERVER_ID

Enumerator
M2MB_DNS_SERVER_PRIMARY 

MACRO to set primary server details

M2MB_DNS_SERVER_SECONDARY 

MACRO to set secondary server details

Definition at line 55 of file m2mb_dns_client.h.

Function Documentation

◆ m2mb_dns_client_deinit()

M2MB_STATUS_T m2mb_dns_client_deinit ( VOID  )

De-initialize DNS client module.

This API de-initializes the DNS client module.

Returns
Returns M2MB_OK on success, M2MB_ERROR on failure.
Note
This API has to be called if the DNS client is already initialized.

m2mb_dns_client_deinit();

int main()
{
...
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
...
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
}

◆ m2mb_dns_client_get_host_by_name()

M2MB_HOST_NAME_TO_IP_T* m2mb_dns_client_get_host_by_name ( UINT8 name)

Get IP address of host name.

This API initiates DNS resolution to get the IP address from the given host name.

Implements a standard Unix version of gethostbyname().

The returned structure should not be freed by the caller.

Parameters
[in]nameEither a hostname or an IPv4 address in standard dot notation.
Returns
On success, a pointer to a M2MB_HOST_NAME_TO_IP_T structure.
On error, NULL is returned.
Note
This API has to be called after m2mb_dns_clinet_init API is called. User has to make sure to add at least one DNS server by calling m2mb_dns_client_svr_add before calling this API.

Example

int main()
{
...
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
...
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
...
pEntry = m2mb_dns_client_get_host_by_name("www.google.com");
if( pEntry != NULL )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
}

◆ m2mb_dns_client_get_host_by_name2()

M2MB_HOST_NAME_TO_IP_T* m2mb_dns_client_get_host_by_name2 ( UINT8 name,
INT32  af 
)

Get the IP address from the host name of the server.

m2mb_dns_client_get_host_by_name2 initiates DNS resolution to get the IP address from the given host name.

Implements a standard Unix version of gethostbyname2().

The returned M2MB_HOST_NAME_TO_IP_T structure is not thread safe. It can be freed by internal DNS client routines if the entry ages out or if the table becomes full and space is needed for another entry.

Parameters
[in]nameEither a hostname or an IPv4 address in standard dot notation.
[in]afAddress family; either M2MB_SOCKET_BSD_AF_INET or M2MB_SOCKET_BSD_AF_INET6.
Returns
On success, a pointer to a M2MB_HOST_NAME_TO_IP_T structure.
On error, NULL is returned.
Note
This API has to be called after m2mb_dns_clinet_init API is called. User has to make sure to add at least one DNS server by calling m2mb_dns_client_svr_add before calling this API. Example
int main()
{
...
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
...
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
...
pEntry = m2mb_dns_client_get_host_by_name2("www.google.com");
if( pEntry != NULL )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
}

◆ m2mb_dns_client_get_server_list()

M2MB_STATUS_T m2mb_dns_client_get_server_list ( M2MB_NWIF_DNS_SERVER_LIST_T srv_list)

Get the DNS server list.

This API gets the DNS server list.

Parameters
[out]srv_listPointer to DNS server list.
Returns
Returns M2MB_OK on success, M2MB_ERROR on failure.
Note
This API has to be called after m2mb_dns_client_init API is called.

Example

int main()
{
...
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
...
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
...
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
}

◆ m2mb_dns_client_init()

M2MB_STATUS_T m2mb_dns_client_init ( VOID  )

Initialize DNS client.

This API initializes the DNS client module.

Returns
Returns M2MB_OK on success, M2MB_ERROR on failure.
Note
This API has to be called before any other DNS client API is called.

m2mb_dns_client_init();

int main()
{
...
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
}

◆ m2mb_dns_client_is_started()

M2MB_STATUS_T m2mb_dns_client_is_started ( VOID  )

Check the status of DNS client.

This API checks whether the DNS client module is started or not.

Returns
Returns M2MB_OK on success, M2MB_ERROR on failure.
Note
This API has to be called before DNS server address set command is called. Example
int main()
{
...
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
}

◆ m2mb_dns_client_resolve_host()

M2MB_STATUS_T m2mb_dns_client_resolve_host ( UINT8 hostname,
M2MB_IP46_ADDR_T ipaddr 
)

Resolve the URL details.

This API resolves the URL details.

Parameters
[in]hostnameURL mentioned in a string format.
[out]ipaddrPointer to the URL's IP address structure (M2MB_IP46_ADDR_T *).
Returns
Returns M2MB_OK on success, M2MB_ERROR on failure.
Note
This API can be called,
  1. directly m2mb_dns_client_init.
  2. If user need to add different server then m2mb_dns_client_init, m2mb_dns_client_svr_add should be called before the API.

Example

int main()
{
M2MB_IP46_ADDR_T entry = { 0 };
...
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
...
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
...
status = m2mb_dns_client_resolve_host( "www.google.com", &entry );
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
}

◆ m2mb_dns_client_svr_add()

M2MB_STATUS_T m2mb_dns_client_svr_add ( UINT8 ipAddr,
M2MB_DNS_SERVER_ID_E  serverID 
)

Add a DNS server.

This API stores the DNS server address to resolve the host name. The server name has to be a valid IP address of DNS server.

Parameters
[in]ipAddrPointer to the IP address string of the server.
[in]serverIDUser is supposed to pass M2MB_DNS_SERVER_PRIMARY or M2MB_DNS_SERVER_SECONDARY to indicate whether the primary or secondary server has to be added.
Returns
Returns M2MB_OK on success, M2MB_ERROR on failure.
Note
This API has to be called after m2mb_dns_client_init API is called.

m2mb_dns_client_svr_add( "192.168.1.1", M2MB_DNS_SERVER_PRIMARY );

int main()
{
...
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
...
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
}

◆ m2mb_dns_client_svr_delete()

M2MB_STATUS_T m2mb_dns_client_svr_delete ( M2MB_DNS_SERVER_ID_E  serverID)

Delete the DNS server details.

This API deletes the DNS server details added to DNS client module.

Parameters
[in]serverIDUser is supposed to pass M2MB_DNS_SERVER_PRIMARY or M2MB_DNS_SERVER_SECONDARY to indicate whether the primary or secondary server has to be deleted.
Returns
Returns M2MB_OK on success, M2MB_ERROR on failure.
Note
This API has to be called after m2mb_dns_client_init API is called.

m2mb_dns_client_svr_delete( M2MB_DNS_SERVER_PRIMARY );

int main()
{
...
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
...
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
...
if( status == M2MB_OK )
{
return M2MB_OK;
}
else
{
return M2MB_ERROR;
}
}