小编gre*_*man的帖子

如何使用c-ares将IP解析为主机?

这就是我到目前为止所做的.它编译,但当我尝试运行它时会出现段错误.

#include <iostream>
#include <netdb.h>
#include <arpa/inet.h>
#include <ares.h>

void dns_callback (void* arg, int status, int timeouts, struct hostent* host)
  {
    std::cout << host->h_name << "\n";
  }

int main(int argc, char **argv)
  {
    struct in_addr ip;
    char *arg;
    inet_aton(argv[1], &ip);
    ares_channel channel;
    ares_gethostbyaddr(channel, &ip, 4, AF_INET, dns_callback, arg);
    sleep(15);
    return 0;
  }
Run Code Online (Sandbox Code Playgroud)

c++ linux dns c-ares

7
推荐指数
1
解决办法
4403
查看次数

标签 统计

c++ ×1

c-ares ×1

dns ×1

linux ×1