Need To Build Simple DNS Resolver in C [duplicate]

扶醉桌前 提交于 2019-12-19 09:53:53

问题


Possible Duplicate:
How to Build a custom simple DNS server in C/C++

As the title says I need to build a simple dns resolver in C...

Not in C++, I have looked on internet for some tutorials to help me get going but mostly find C++.

Wondering whether anyone knows of a tutorial to get me started or can give me a couple of tips on how to build my DNS request header in C...

Any help will be much appreciated.


回答1:


I have written a simple DNS resolver in C.

You can go about this one of three ways:

  1. learn BSD socks
  2. use DSNQuery
  3. use gethostbyname

This example uses BSD sockets: http://www.binarytides.com/blog/dns-query-code-in-c-with-winsock-and-linux-sockets/

The function DSNQuery() is available in windows. It might be overkill for what you're building. It returns all of the resource records returned by the DNS server. This example uses the function DSNQuery to resolve a host name: http://support.microsoft.com/kb/831226

This example uses gethostbyname: http://paulschreiber.com/blog/2005/10/28/simple-gethostbyname-example/

I'd strongly recommend using an API like DNSQuery() or gethostbyname()



来源:https://stackoverflow.com/questions/1819993/need-to-build-simple-dns-resolver-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!