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.
相关问题
- Multiple sockets for clients to connect to
- Is shmid returned by shmget() unique across proces
- What is the best way to do a search in a large fil
- Django & Amazon SES SMTP. Cannot send email
- glDrawElements only draws half a quad
And I would add, unless you're writing a mail relay you almost certainly shouldn't be looking up MX records - you should be passing the mail on to a user-configured mail relay instead.
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:If you need to do this in C, a quick google shows up a few C libraries out there which you can use:
If a blocking (synchronous) query is ok, just use
res_query()
, and link your program with -lresolv.I like adns because it allows for asynchronous requests
I'd suggest FireDNS. It's a very fast C library for all kinds of dns queries.
You can also try c-ares library https://c-ares.haxx.se/, which allows to send asynchronous DNS queries. It also comes with adig - its own version of dig utility for querying DNS. You can check it to see how to parse DNS reply: adig.c source