WinSock and NATs

Started by
20 comments, last by Evil Bill 21 years, 9 months ago
if you use ICS, its quite possible that its treating even your pc as the one behind the NAT. make sure you use your internet address (ie external) not your lan address (internal). since you have 2 nics your app may be listenning on the wrong ip address. i assume 2 nics since thats how most nats get setup. 1 for the internet and one for th lan connected to the hub/switch. you may wish to use INADDR_ANY as the ip address (its a constant) which tells winsock to listen on ALL ip addresses that the machine has (local and external).

basiclly you never have to deal with NATs specially in your code beyond allowing the user to choose the ip and port they wish to listen to (and by default possible use INADDR_ANY). your method (ie gethostname(NULL)) is most likly picking the nic which is for the lan.

use gethostname(arrayForHostname, SIZE_OF_ARRAY) to get the hostname for the pc. then gethostbyname() and go through the entire list of ips returned (there can be more then one).

warning the hostname returned may not be the internet hostname, please check the docs for more info.
Advertisement
Yup, ive got 2 addresses.
I already use INADDR_ANY.
Setting it to my real IP doesn''t help
I use gethostbyname() to build a list of IPs to display to the user so they can say "Yeah, my IP is a.b.c.d, connect in 5 mins" or whatever.

Cheers, Steve

Steve
DirectX Programmer
Soon to be the new Bill Gates
Member of the Unban Mindwipe Society (UMWS)

This topic is closed to new replies.

Advertisement