WE310F5  39.00.000
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,
  M2MB_DNS_SERVER_MAX_SUPPORTED
}
 MACROs used to signify the server IDs for SET/GET DNS server details. More...
 
enum  M2MB_DNSC_CONF_ID {
  M2MB_DNSC_CONF_INVALID = 0,
  M2MB_DNSC_CONF_SET_SRV_ADD = 1,
  M2MB_DNSC_CONF_SET_SRV_DEL = 2,
  M2MB_DNSC_CONF_GET_IS_STARTED = 3,
  M2MB_DNSC_CONF_GET_SERVER_LIST = 4
}
 DNS client GET/SET Configuration enumeration. More...
 
typedef enum M2MB_DNS_SERVER_ID M2MB_DNS_SERVER_ID_E
 MACROs used to signify the server IDs for SET/GET DNS server details. More...
 
typedef enum M2MB_DNSC_CONF_ID M2MB_DNSC_CONF_ID_E
 DNS client GET/SET Configuration enumeration. More...
 
typedef struct M2MB_HOST_NAME_TO_IP M2MB_HOST_NAME_TO_IP_T
 Structure to get IP address from host name. More...
 
typedef struct M2MB_DNSC_SRV_ADD_INFO M2MB_DNSC_SRV_ADD_INFO_T
 Structure is used by the Configuration ID M2MB_DNSC_CONF_SET_SRV_ADD to configure the given dns server information. More...
 
typedef struct M2MB_HOST_NAME_TO_IP_INFO M2MB_HOST_NAME_TO_IP_INFO_T
 Structure is used by the CONF IDs M2MB_DNSC_CONF_GET_HOST_BY_NAME and M2MB_DNSC_CONF_GET_HOST_BY_NAME2 to get IP address from host name. More...
 
M2MB_STATUS_T m2mb_dns_client_init (HANDLE *handle)
 Initialize DNS client. More...
 
M2MB_STATUS_T m2mb_dns_client_set_cfg (HANDLE handle, M2MB_DNSC_CONF_ID_E conf_id, M2MB_DNSC_CONF_PARAMS_T *conf_params)
 SET the dns client configuration parameters. More...
 
M2MB_STATUS_T m2mb_dns_client_get_cfg (HANDLE handle, M2MB_DNSC_CONF_ID_E conf_id, M2MB_DNSC_CONF_PARAMS_T *conf_params)
 GET the dns client configuration parameters. 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_deinit (HANDLE handle)
 De-initialize DNS client module. 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

MACROs used to signify the server IDs for SET/GET DNS server details.

◆ M2MB_DNSC_CONF_ID_E

DNS client GET/SET Configuration enumeration.

This enum defines macros for various GET/SET Configuration for DNS client.

◆ M2MB_DNSC_SRV_ADD_INFO_T

Structure is used by the Configuration ID M2MB_DNSC_CONF_SET_SRV_ADD to configure the given dns server information.

Structure is used by the Configuration ID M2MB_DNSC_CONF_SET_SRV_ADD to configure the given dns server ip address at the server id.

◆ M2MB_HOST_NAME_TO_IP_INFO_T

Structure is used by the CONF IDs M2MB_DNSC_CONF_GET_HOST_BY_NAME and M2MB_DNSC_CONF_GET_HOST_BY_NAME2 to get IP address from host name.

M2MB_HOST_NAME_TO_IP_T is the same as the UNIX struct hostent{}.

◆ 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

MACROs used to signify the server IDs for SET/GET DNS server details.

Enumerator
M2MB_DNS_SERVER_PRIMARY 

MACRO to set primary server details

M2MB_DNS_SERVER_SECONDARY 

MACRO to set secondary server details

M2MB_DNS_SERVER_MAX_SUPPORTED 

Definition at line 65 of file m2mb_dns_client.h.

◆ M2MB_DNSC_CONF_ID

DNS client GET/SET Configuration enumeration.

This enum defines macros for various GET/SET Configuration for DNS client.

Enumerator
M2MB_DNSC_CONF_INVALID 
M2MB_DNSC_CONF_SET_SRV_ADD 

ONLY SET CONF, calls to add server API

M2MB_DNSC_CONF_SET_SRV_DEL 

ONLY SET CONF, calls to delete the server API

M2MB_DNSC_CONF_GET_IS_STARTED 

ONLY GET CONF, checks the dns client module is started

M2MB_DNSC_CONF_GET_SERVER_LIST 

ONLY GET CONF, gives the list of the servers

Definition at line 80 of file m2mb_dns_client.h.

Function Documentation

◆ m2mb_dns_client_deinit()

M2MB_STATUS_T m2mb_dns_client_deinit ( HANDLE  handle)

De-initialize DNS client module.

This API de-initializes the DNS client module.

Parameters
[in]handleSpecifies the context handle initialized by m2mb_dns_init API.
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( handle );

int main()
{
HANDLE handle = NULL;
...
status = m2mb_dns_client_init( &handle );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
...
status = m2mb_dns_client_deinit( handle );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
}

◆ m2mb_dns_client_get_cfg()

M2MB_STATUS_T m2mb_dns_client_get_cfg ( HANDLE  handle,
M2MB_DNSC_CONF_ID_E  conf_id,
M2MB_DNSC_CONF_PARAMS_T conf_params 
)

GET the dns client configuration parameters.

This API is called to GET the configuration of the dns client based on the conf IDs.

Parameters
[in]handleSpecifies the context handle initialized by m2mb_dns_init API.
[in]conf_idGET configuration ID from enum M2MB_DNSC_CONF_ID_E.
[in]conf_paramsconfiguration params to be passed according to the configuration required.
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()
{
HANDLE handle = NULL;
...
status = m2mb_dns_client_init( &handle );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
//To add the server
M2MB_DNSC_SRV_ADD_INFO_T server_info = {0};
server_info.ipAddr = "8.8.8.8";
M2MB_DNSC_CONF_PARAMS_T dnsc_conf = {0};
dnsc_conf.srv_info = &server_info;
status = m2mb_dns_client_set_cfg( handle, M2MB_DNSC_CONF_SET_SRV_ADD, &dnsc_conf );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
// GET the dns client is started status
status = m2mb_dns_client_get_cfg( handle, M2MB_DNSC_CONF_GET_IS_STARTED, &dnsc_conf );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
// Get the server list
M2MB_NWIF_DNS_SERVER_LIST_T srv_list = {0};
dnsc_conf.get_srv_list = &srv_list;
if( status == M2MB_ERROR )
{
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_dnsc_set_cfg to add the Server address with configuration ID 'M2MB_DNSC_CONF_SET_SRV_ADD' before calling this API.

Example

int main()
{
...
HANDLE handle = NULL;
...
status = m2mb_dns_client_init( &handle );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
...
//To add the server
M2MB_DNSC_SRV_ADD_INFO_T server_info = {0};
server_info.ipAddr = "8.8.8.8";
M2MB_DNSC_CONF_PARAMS_T dnsc_conf = {0};
dnsc_conf.srv_info = &server_info;
status = m2mb_dns_client_set_cfg( handle, M2MB_DNSC_CONF_SET_SRV_ADD, &dnsc_conf );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
...
pEntry = m2mb_dns_client_get_host_by_name("www.google.com");
if( status == M2MB_ERROR )
{
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_dnsc_set_cfg to add the Server address with configuration ID 'M2MB_DNSC_CONF_SET_SRV_ADD' before calling this API.

Example

int main()
{
HANDLE handle = NULL;
...
status = m2mb_dns_client_init( &handle );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
...
//To add the server
M2MB_DNSC_SRV_ADD_INFO_T server_info = {0};
server_info.ipAddr = "8.8.8.8";
M2MB_DNSC_CONF_PARAMS_T dnsc_conf = {0};
dnsc_conf.srv_info = &server_info;
status = m2mb_dns_client_set_cfg( handle, M2MB_DNSC_CONF_SET_SRV_ADD, &dnsc_conf );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
...
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
}

◆ m2mb_dns_client_init()

M2MB_STATUS_T m2mb_dns_client_init ( HANDLE handle)

Initialize DNS client.

This API initializes the DNS client module.

Parameters
[in]handleSpecifies the pointer to the context handle that can be used by other dns client APIs.
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( &handle );

int main()
{
HANDLE handle = NULL;
...
status = m2mb_dns_client_init( &handle );
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. after initializing the dns client module by calling m2mb_dns_client_init. And
  2. after adding dns server IP using m2mb_dnsc_set_cfg API with M2MB_DNSC_CONF_SET_SRV_ADD as configuration ID to add the dns server.

Example

int main()
{
M2MB_IP46_ADDR_T entry = { 0 };
HANDLE handle = NULL;
...
status = m2mb_dns_client_init( &handle );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
...
//To add the server
M2MB_DNSC_SRV_ADD_INFO_T server_info = {0};
server_info.ipAddr = "8.8.8.8";
M2MB_DNSC_CONF_PARAMS_T dnsc_conf = {0};
dnsc_conf.srv_info = &server_info;
status = m2mb_dns_client_set_cfg( handle, M2MB_DNSC_CONF_SET_SRV_ADD, &dnsc_conf );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
...
status = m2mb_dns_client_resolve_host( "www.google.com", &entry );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
}

◆ m2mb_dns_client_set_cfg()

M2MB_STATUS_T m2mb_dns_client_set_cfg ( HANDLE  handle,
M2MB_DNSC_CONF_ID_E  conf_id,
M2MB_DNSC_CONF_PARAMS_T conf_params 
)

SET the dns client configuration parameters.

This API is called to configure the dns client based on the conf IDs.

Parameters
[in]handleSpecifies the context handle initialized by m2mb_dns_init API.
[in]conf_idSET configuration ID from enum M2MB_DNSC_CONF_ID_E.
[in]conf_paramsconfiguration params to be passed according to the configuration to be done. To add the server, use conf ID M2MB_DNSC_CONF_SET_SRV_ADD with the server name and server ID with M2MB_DNSC_SRV_ADD_INFO_T *srv_info in the M2MB_DNSC_CONF_PARAMS_T. To delete the server, use conf ID M2MB_DNSC_CONF_SET_SRV_DEL and with the information of serverID in the M2MB_DNSC_CONF_PARAMS_T.
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()
{
HANDLE handle = NULL;
...
status = m2mb_dns_client_init( &handle );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
//To add the server
M2MB_DNSC_SRV_ADD_INFO_T server_info = {0};
server_info.ipAddr = "8.8.8.8";
M2MB_DNSC_CONF_PARAMS_T dnsc_conf = {0};
dnsc_conf.srv_info = &server_info;
status = m2mb_dns_client_set_cfg( handle, M2MB_DNSC_CONF_SET_SRV_ADD, &dnsc_conf );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
//To delete the server
status = m2mb_dns_client_set_cfg( handle, M2MB_DNSC_CONF_SET_SRV_DEL, &dnsc_conf );
if( status == M2MB_ERROR )
{
return M2MB_ERROR;
}
}