You shouldn't need to connect a socket just to find out what your IP is.
I don't know what the portability situation with this is, but it works fine for me.Code:char name[256], * ip ; if (gethostname(name,255) == 0) { struct hostent * hp ; struct in_addr addr ; hp = gethostbyname (name) ; if (!hp) // error memcpy (&addr, hp->h_addr_list[0], hp->h_length) ; ip = inet_ntoa (addr) ; // code with this, etc } else // error