diff options
Diffstat (limited to 'src/net_unix')
| -rw-r--r-- | src/net_unix/Makefile | 5 | ||||
| -rw-r--r-- | src/net_unix/dns.c | 19 | ||||
| -rw-r--r-- | src/net_unix/dns.h | 8 |
3 files changed, 31 insertions, 1 deletions
diff --git a/src/net_unix/Makefile b/src/net_unix/Makefile index 648ca88..d13af8e 100644 --- a/src/net_unix/Makefile +++ b/src/net_unix/Makefile @@ -1,6 +1,9 @@ -all: udp.o +all: udp.o dns.o + +dns.o: dns.c dns.h + $(CC) $(CFLAGS) -o dns.o -c dns.c udp.o: udp.c udp.h $(CC) $(CFLAGS) -o udp.o -c udp.c diff --git a/src/net_unix/dns.c b/src/net_unix/dns.c new file mode 100644 index 0000000..f4036a2 --- /dev/null +++ b/src/net_unix/dns.c @@ -0,0 +1,19 @@ + +#include <netdb.h> +#include <string.h> + +#include "base/main.h" + +char* getIPFormDNS(char *domain) +{ + struct hostent *host; + + host = gethostbyname(domain); + + if( host == NULL || host->h_addr_list[0] == NULL ) + { + return NULL; + } + + return strdup( inet_ntoa( * ( (struct in_addr *) host->h_addr_list[0] ) ) ); +} diff --git a/src/net_unix/dns.h b/src/net_unix/dns.h new file mode 100644 index 0000000..ae92c35 --- /dev/null +++ b/src/net_unix/dns.h @@ -0,0 +1,8 @@ + +#ifndef DNS_H + +#define DNS_H + +extern char* getIPFormDNS(char *domain); + +#endif |