(I’m running linux, so I can’t test this, but give it a try):
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
char *getComputerName() {
system( “echo %COMPUTERNAME% > cname.txt” );
FILE *handle = fopen( “cname.txt”, “r” );
char cname[33];
fread( cname, 1, 32, handle );
fclose( handle );
int len = strlen( cname ) + 1;
char *ret = (char *)alloc( 1, sizeof( char ) * len );
memset( ret, ‘\0’, len );
memcpy( cname, ret, len-1 );
return ret;
}
void printIP( IPAddress *ip ) {
Uint8 parts[4] = (Uint8 *)ip->host;
printf( “%i.%i.%i.%i”, (int)parts[3], (int)parts[2], (int)parts[1],
(int)parts[0] );
}
int main( int argc, char *argv ) {
// Blah blah blah init SDL and SDL_net() and whatever
int port = 12345;
char *computer = getComputerName();
IPAddress ip;
SDLNet_ResolveHost( &ip, computer, port );
free( computer );
printIP( &ip );
// Blah blah blah
}
I hope this helps,
-AlexOn Mon, Nov 29, 2010 at 6:35 AM, Phuoc Can Hua wrote:
Hi there,
After I figured out how to broadcast from Win7, now have got another
problem. The broadcast works on W7 when I set the host with 3 bytes matching
my local network (e.g. 192.168.1.x) where x is to be set to 255. That means
I have to retrieve the 3 bytes of the localhost. When I used
SDLNet_ResolveHost() I got the values 127.0.0.1. How can I retrieve the IP
address of the localhost?
Thanks
Phuoc
SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org