Archived

This topic is now archived and is closed to further replies.

Evil Bill

DNS

Recommended Posts

Evil Bill    126
Hi, i''m writing a mail program, and i need to do a DNS lookup for MX. I know DNS is UDP port 53, but is there a way to make it more reliable? At the moment it dies at recvfrom() sometimes, it just freezes. I''ve never used UDP before, and i''m using someone elses code. I''m guessing that it freezes because the data is never recieved (because UDP is unreliable). Do i have to setup winsock to only wait for a short time (10 seconds or so) before re-sending the DNS request, or am i able to cheat somehow (is there an equivalent for gethostbyname() for MX records, or can i use TCP/IP)? Thanks for any replies.

Share this post


Link to post
Share on other sites
Zoomby    122
gethostbyname() uses DNS too. If you want to get MX records you have to do it yourself.
UDP in fact is sometimes unreliable. but only a small number of the packets don''t recieve their destination (my experience).

use the setsockopt function to set a timeout, so if you don''t receive anything, "recvfrom" returns and you can try it again.

unsigned int nMillis = 5000; //try 5 seconds then return
setsockopt(sckSock, SOL_SOCKET, SO_RCVTIMEO, (char *) &nMillis, sizeof(nMillis))

by the way. here is a good dns (and others) tutorial: http://www.vijaymukhi.com/vmis/roll.htm.
it''s very interesting. try to program your own dns lookup. :-)

ciao
chris

Share this post


Link to post
Share on other sites
Evil Bill    126
Cool, thanks for the link! I''ve got it sorted in a similar way, but i''ll change it to that code i think. At the moment, if i don''t recieve data in 2 seconds, i resend the request, but your way looks cleaner.

Share this post


Link to post
Share on other sites