Get domain IP address in C

 Get domain IP address in C

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>

int main(int argc, char *argv[])
    struct hostent *dns_record = NULL;
    char *domai_nname = "";

    while (1) {
        dns_record = gethostbyname(domai_nname);
        if (NULL == dns_record) {
            return -1;
        printf("ipaddress: %s\n", inet_ntoa(*((struct in_addr *)dns_record->h_addr)));

    return 0;


Popular posts from this blog

Python Receiving and parse JSON Data via UDP protocol

ubus lua client method and event registration code demo/example