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.
views:
1523answers:
4
+1
A:
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:
Dave Rigby
2009-07-14 22:38:24
+3
A:
If a blocking (synchronous) query is ok, just use res_query()
, and link your program with -lresolv.
len = res_query(host, C_IN, T_MX, &answer, sizeof(answer));
mark4o
2009-07-15 04:49:28
A:
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.
caf
2009-07-15 07:38:17