如何通过 dnsmasq 调用 dns 查询操作

问题描述

我正在编写一个程序来使用 dnsmasq 作为执行 dns 查询的工具。

我能够编写一些类似的函数:

void writeConfiguration(string a stringValue){
//open etc/dnsmasq.conf
//write a string with keywords such as listening_address = 127.0.0.1 to setup dnsmasq
}
void writeResolve(string a stringCommand){
//open etc/dnsmasq.conf
//write a string with keywords such as nameserver= 127.0.0.1 to setup dnsmasq to look up local cache first
}

在 Linux 终端上,我可以运行一些命令,例如 dig stackoverflow、托管 facebook.com,或者使用网络浏览器来实际执行 dns 查询并检查我的 dnsmasq 设置是否有效。

但是,我想从代码中调用操作 DNS 查询。该函数使用 dnsmasq 并且必须以数组整数或某些数据结构返回主机名的 IP 地址。

我的想法是,通过将字符串传递给 Posix api(例如 run_cmd),我可以在我的函数中包装一个 linux 命令。

代码可能是这样的:

#include "utils/PosixCmd.h"       //include this to use run_cmd
std::string tmpCmd;
(void)tmpCmd.append("dig facebook.com ");
(void)run_cmd(const_cast<char*>(tmpCmd.c_str()));

但是,“did”不会返回预期的输出。有谁知道运行 dns 查询并返回简单 IP 地址的 Linux 命令?此外,该命令必须使用 etc/resolve.conf 中的名称服务器。

或者如果它不在 etc/resolve.conf 中查找 dns 服务器,那么更改查找文件的选项是什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...