Mikroelektronika MIKROE-724 データシート

ページ / 726
490
mikoBasic PRO for dsPIC30/33 and PIC24
MikroElektronika
SPI_Ethernet_dnsResolve
Prototype
sub function SPI_Ethernet_dnsResolve(dim byref host as string, dim tmax as 
byte) as word 
Description This is DNS module routine. It sends an DNS request for given host name and waits for DNS reply. If 
the requested host name was resolved, it’s IP address is stored in library global variable and a pointer 
containing this address is returned by the routine. UDP port 
53
 is used as DNS port.
Parameters 
host
: host name to be resolved. 
tmax
: time in seconds to wait for an reply. 
Returns
- pointer to the location holding the IP address - the requested host name was resolved. 
0
 - otherwise. 
Requires
Ethernet module has to be initialized. See SPI_Ethernet_Init.
Example
dim 
  remoteHostIpAddr as string 
‘ user host IP address buffer
  ...
  ‘ SNTP server:
  ‘  Zurich,  Switzerland:  Integrated  Systems  Lab,  Swiss  Fed.  Inst.  of 
Technology
  ‘ 129.132.2.21: swisstime.ethz.ch
  ‘ Service Area: Switzerland and Europe
 
  memcpy(remoteHostIpAddr, SPI_Ethernet_dnsResolve(“swisstime.ethz.ch”, 5), 
4)
Notes
The Ethernet services are not stopped while this routine waits for DNS reply. The incoming packets will 
be processed normaly during this time.
User should always copy the IP address from the RAM location returned by this routine into it’s own 
resolved host IP address buffer. These locations should not be altered by the user in any case!