Technical Support
On-Line Manuals
RL-ARM User's Guide (MDK v4)
#include <rtl.h> HOSTENT *gethostbyname ( const char *name, /* Pointer to host name */ int *err); /* Pointer to return error code */
The gethostbyname function retrieves host information corresponding to a host name from a host database.
The argument name is a pointer to the null-terminated name of the host to resolve.
The argument err is a pointer to the return error code.
The gethostbyname function is in the RL-TCPnet library. The prototype is defined in rtl.h.
note
The gethostbyname function returns the HOSTENT structure result. On error a NULL is returned.
If err is not NULL, it points to the returned error code:
getpeername, getsockname
#include <rtl.h> static const char *hosts[] = { "www.google.com", "www.keil.com", "www.microsoft.com", "www.yahoo.com", NULL }; __task void dns_task (void) { int i,j,err; HOSTENT *host; IN_ADDR *addr; for (i = 0; ; i++) { if (!hosts[i]) i = 0; printf ("Host: %s\n",hosts[i]); host = gethostbyname (hosts[i], &err); if (host == NULL) { if (err == SCK_ENONAME) { printf ("Hostname does not exist\n"); } } else if (host->h_addrtype == AF_INET) { for (j = 0; host->h_addr_list[j]; j++) { addr = (IN_ADDR *)host->h_addr_list[j]; printf("IP Address: %d.%d.%d.%d\n",addr->s_b1, addr->s_b2, addr->s_b3, addr->s_b4); } } os_dly_wait (300); } }
Cookie Settings | Terms of Use | Privacy | Accessibility | Trademarks | Contact Us | Feedback
Copyright © 2005-2019 Arm Limited (or its affiliates). All rights reserved.
This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.
Change Settings
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers of your data.