hostname to IP address (udp)

Blitz3D Forums/Blitz3D Programming/hostname to IP address (udp)

CakeMonitor(Posted 2005) [#1]
I'm looking for a way to convert a hostname (say, www.google.com) to it's IP address (integer or dotted) for a game which uses the UDP protocol.

I've looked at "Get integer IP from any hostname EG" by skn3[ac] in the code archives, but I don't have the libs and includes mentioned at the top of the code. (or even understand why they are commented out - I mean, the code doesn't compile without them... does it?)

I seem to remember someone saying I could accept a TCP connection soley for resolving the hostname, then use UDP for everything else... If someone could provide details on how to do this I'd appreciate it, but I would prefer to be able to do the whole thing using only UDP.

Thanks.


Yan(Posted 2005) [#2]
google = OpenTCPStream("google.com", 80)

Print DottedIP(TCPStreamIP(google))

CloseTCPStream google

WaitKey()
??


CakeMonitor(Posted 2005) [#3]
Thanks Pete, I'll try that for now.

I assume it is possible to do this using UDP alone, if anyone knows how - please help!

Thanks again.


octothorpe(Posted 2005) [#4]
To convert a hostname to an IP, you need to query a nameserver (DNS server). When your users set up their internet connections, they entered the IPs of their ISP's nameservers into their operating system's TCP layer. Unless you want your users to enter their ISP nameserver IPs into your program, you'll need to interface with their operating systems' TCP layer to get them. Then it's simply a matter of reinventing the DNS part of the TCP wheel. I think you'll need to establish a TCP connection to a DNS server though - and I'm not certain you can fake one with UDP.

The Unix and Internet Fundamentals HOWTO: How does the Internet work?

P.S. Just use TCP.


King Dave(Posted 2005) [#5]
UDP will only accept an integer IP (last I knew anyway), and theres no need to establish a TCP connection to get the IP (might not always be possible anyway):

Const HostName$="www.google.com"

a=CountHostIPs(HostName$)
Print HostName$+" has "+a+" IP addresses:"
For b=1 to a
	ip=HostIP(b)
	Print b+") "+DottedIP$(ip)+" or "+ip
Next

WaitKey
End



CakeMonitor(Posted 2005) [#6]
ALL HAIL THE DAVE!!!

Thankyou! exactly what I needed and so simple too :D


King Dave(Posted 2005) [#7]
:) glad to help