🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Winsock problem

Started by
4 comments, last by RiAL 23 years, 2 months ago
Hello I''m using winsock for a FPS multiplayer game that is half complete. Everything seems to be working so far but I have come to a problem which I can''t solve. I''m using a cable modem and I have set up a Linux gateway so all my computers can use the Internet. Quake3 and other games seem to work fine (there is no firewall). However in my game, Winsock will only detect 192.168.0.3 which is my LAN IP. How can I get the actual IP address which I can use with the internet? Thanks for any help.
  
Code to get the local addresses:

	char ac[80];
	
    if (gethostname(ac, sizeof(ac)) == SOCKET_ERROR) 
		return false;
  
    struct hostent *phe = gethostbyname(ac);

    if (phe == 0)
		return false;
	
	// Enum all IP addresses

    for (int i = 0; phe->h_addr_list[i] != 0; ++i) 
	{
        struct in_addr addr;
        memcpy(&addr, phe->h_addr_list[i], sizeof(struct in_addr));
        		
		strcpy(strChosenIP,  inet_ntoa(addr) );
		break;		// TODO: Don''t stop after getting the first IP address

	}

  
Don''t worry about the TODO comment. It only finds one IP address I''m sure of that.
Advertisement
Actually Quake3 and other programs only detect 192.168.0.3 as well. Now my problem is how can I send data to another computer using UDP packets if they don''t know my internet address? When I connect to an server I have to send them my IP address so they know where to send? Or is there a way to get the IP address of the sent packet with UDP?


Thanks again.
Hmm, I don''t have the answer but I have a really cheap solution Fire up a tcp socket and connect it to the server and let it get your ip from there (inet_ntoa()).

"This album was written, recorded and edited at Gröndal, Stockholm in the year of 2000. At this point in time money still ruled the world. Capitalistic thoughts were wide spread. From the sky filled with the fumes of a billionarie''s cigar to the deepest abyss drenched in nuclear waste. A rich kid was a happy kid, oh..dirty, filthy times. Let this be a reminder."
- Fireside, taken from back of the Elite album
i agree with staffan


"I pity the fool, thug, or soul who tries to take over the world, then goes home crying to his momma."
- Mr. T
Actually it might not be so bad . As long as it works its pretty good. I thought about this and I couldn''t figure anything out. Thanks for that.
When you call recvmsg (which you have to use with UDP), you''ll have to pass a pointer to a struct sockaddr which will be filled with the source address of the packet.

You''ll have to use that anyway to identify the sender of ongoing packets, otherwise your game will be far too easy to hack.

cu,
Prefect

Resist Windows XP''s Invasive Production Activation Technology!
One line of sourcecode says more than a thousand words.
Widelands - laid back, free software strategy

This topic is closed to new replies.

Advertisement