How might I perform DNS lookups using C/C++ on Linux?

后端 未结 7 1655
太阳男子
太阳男子 2020-12-19 01:57

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 gi

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-19 02:44

    I don't think there is a function in the C standard library for this, but many scripting languages do have this functionality 'built in'. For example, Perl has the Net::DNS package:

    use Net::DNS;
    my @mx = mx("example.com");
    foreach $host (@mx) {
      print $host;
    }
    

    If you need to do this in C, a quick google shows up a few C libraries out there which you can use:

    • adns
    • udns
    • dns.c
    • FireDNS (as mentioned by ko-dos)

提交回复
热议问题