Well, if you have a master server that you're registering your server with, you can have it simply send back the IP address that it thinks its sending data to.  Then the local server checks for the address among its local interfaces.  Here's a stupid bit of code to print out all of your local IP addresses:

        char hostname[255];
        HOSTENT *hostent;
        int num_adapters = 0;
        gethostname ( hostname, sizeof ( hostname ));

        hostent = gethostbyname ( hostname );
        if ( !hostent )
                {
                printf ( "Couldn't resolve local host\n" );

                abort ();
                }

        printf ( "Adapters:\n" );

        for ( num_adapters = 0; hostent->h_addr_list[num_adapters]; num_adapters++ )
                {
                printf ( "%d: %s\n", num_adapters + 1, inet_ntoa ( *((in_addr *) (hostent->h_addr_list[num_adapters])) ) );

                }

Hope this helps.

Jack

-----Original Message-----
From: Tom Hubina [mailto:tomh@3dgamedev.com]
Sent: Wednesday, January 31, 2001 2:21 PM
To: gdalgorithms-list@lists.sourceforge.net
Subject: [Algorithms] Detecting a NAT


In our games we use WinSock for all networking. I was wondering if someone
knows of a good way to detect that a server is being run behind a NAT so I
can warn the user that the game won't work properly unless the NAT is
configured to forward packets (either through DMZ or port forwarding) to
the server machine (we have a lobby server running that can aid in the
checks). I guess what I want to know is, how do I get return the address of
the packet, and how do I get the IP address of the local interface being
used (so I can compare them and warn if they're different). How do others
deal with this?

Tom


_______________________________________________
GDAlgorithms-list mailing list
GDAlgorithms-list@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/gdalgorithms-list