如何在 Linux 上使用 C/C++ 执行 DNS 查找? [英] How might I perform DNS lookups using C/C++ on Linux?

查看:31
本文介绍了如何在 Linux 上使用 C/C++ 执行 DNS 查找?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 c api(或任何其他语言)获得与 host 命令类似的功能?我需要更多信息,而不仅仅是 gethostbyname() 给出的 IP 地址;特别是与 SMTP 相关的数据.

How do I get similar functionality to the host command using a c api (or any other language for that matter)? I need more information than just an IP address given by gethostbyname(); specifically, the SMTP-related data.

推荐答案

如果阻塞(同步)查询没问题,只需使用 res_query(),并使用 -lresolv 链接您的程序.

If a blocking (synchronous) query is ok, just use res_query(), and link your program with -lresolv.

 len = res_query(host, C_IN, T_MX, &answer, sizeof(answer));

这篇关于如何在 Linux 上使用 C/C++ 执行 DNS 查找?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆