30 lines
550 B
C
30 lines
550 B
C
/*
|
||
* 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);
|
||
size_t size = strlen(ip) + 1;
|
||
result = (char *)malloc(sizeof(char) * size);
|
||
strncpy(result, ip, size);
|
||
}
|
||
return result;
|
||
}
|