Advertisement

DNS

Started by March 06, 2003 12:58 PM
1 comment, last by Evil Bill 21 years, 11 months ago
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.
Member of the Unban Mindwipe Society (UMWS)
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
Advertisement
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.

Member of the Unban Mindwipe Society (UMWS)

This topic is closed to new replies.

Advertisement