开发者

Best way to resolve a DNS TXT record on Linux/Unix/Posix/BSD type systems?

I want to write some portable (as possible) C code to look up DNS TXT records. I woul开发者_如何学Pythond also prefer not to have dependencies on libraries that don't ship with the machine.

What is the best way to do this on Unix-like machines using standard libraries?

I found some sample code that works using libresolv, but it's not reentrant (not thread safe) and is very ugly. Is there a better way?

Also, what about Windows? If there were a way that worked there too that would be perfect.


you can use res_query which uses the standard libresolv.

There's an example here from clamav:

if((len = res_query(domain, C_IN, T_TXT, answer, PACKETSZ)) < 0) {
  mprintf("@Can't query %s\n", domain);
  return NULL;
}


This is a FAQ. See Code to do a direct DNS lookup or How might I perform DNS lookups using C/C++ on Linux?.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜