2022-07-15 14:16:58 +00:00
|
|
|
|
/*
|
|
|
|
|
* address.c
|
|
|
|
|
*
|
|
|
|
|
* Created on: 15 июл. 2022 г.
|
|
|
|
|
* Author: alexander
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "address.h"
|
|
|
|
|
|
|
|
|
|
#include <netdb.h>
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
|
|
char *getHostIP(char *dnsName)
|
|
|
|
|
{
|
|
|
|
|
char *result = NULL;
|
|
|
|
|
struct hostent *he = gethostbyname(dnsName);
|
|
|
|
|
if (he)
|
|
|
|
|
{
|
|
|
|
|
char *ip = inet_ntoa(*(struct in_addr*)he->h_addr);
|
2022-07-19 10:13:57 +00:00
|
|
|
|
size_t size = strlen(ip) + 1;
|
|
|
|
|
result = (char *)malloc(sizeof(char) * size);
|
|
|
|
|
strncpy(result, ip, size);
|
2022-07-15 14:16:58 +00:00
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|