Ok, so where do you fill in the value of myIPaddress? =)
Oh, sorry, that part is trivial
myIPaddress.host = NULL;
myIPaddress.port = 69;
The trick is to call SDLNet_ResolveIP() with host NULL to
get your network name, which you feed back into SDLNet_ResolveHost()
to convert that network name to an IP.
Warning: if you have multiple network adapters, you’re on a LAN or wireless
or both, I have no idea which IP you’ll get back.
What I did is have comp1 connect to comp2,
and comp2 tells comp1 what it sees
comp1’s IP as. ( GetPeerAddress() )
Cheers!On 10/06/07, Christopher Larsen <christopherleelarsen gmail.com> wrote:
Yes you can…
// Check what my real IP is first
BUG("Check what my real IP is: ");
const char* tempstr = SDLNet_ResolveIP(&myIPaddress); // Get
the network name of this computer
if (tempstr) BUG(“tempstr is valid”);
if (strlen(tempstr) > 79) ERROR(“ERR: Filename too long!”);
strcpy(myNetworkName, tempstr);
fprintf(stdout,"myNetworkName is: “);
fprintf(stdout, " %s \n”, myNetworkName); fflush(stdout);
SDLNet_ResolveHost(&myIPaddress, myNetworkName, FOUNDATION_PORT);
// Fill up an ip with my network name
iterator = (Uint8*) &myIPaddress.host; // This simple
elegant code reads the host Uint32 member into a readable IP
fprintf(stdout, “%d.”, *iterator++); //
fprintf(stdout, “%d.”, *iterator++); //
fprintf(stdout, “%d.”, *iterator++); //
fprintf(stdout, "%d ", *iterator); //
fprintf(stdout,"myIPaddress.port is: “);
fprintf(stdout, " %d \n”, myIPaddress.port);
fflush(stdout);