okay, so i have my little app set up and working good for me on my computer.
Code:
#include <winsock.h>
#include <windows.h>
#include <string.h>
#include <stdlib.h>
bool sendAdress(void);
char listServer[] = "localhost";
bool sendAdress(void)
{
//first get your own IP
char localName[256];
LPHOSTENT localMachine;
//geting host name for local 'puter
gethostname(localName, sizeof(localName));
//making a hostent with above name
localMachine = gethostbyname(localName);
//getting adresses
char localAddrs[256];
int i = 0;
while (true)
{
if (!localMachine->h_addr_list[i])
{
break;
}
else
{
strcat(localAddrs,inet_ntoa(*(struct in_addr *) localMachine->h_addr_list[i]));
strcat(localAddrs,"\n");
i++;
}
}
//char * addrList = inet_ntoa(*(struct in_addr *) localMachine->h_addr_list[0]);
//print IP (hopefuly)
MessageBox(NULL,localAddrs,"your adress is...",MB_OK);
}
int WINAPI WinMain(HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil)
{
//first initiate winsock
WORD winsockVersion = MAKEWORD(1,1);
WSADATA wsaData;
WSAStartup(winsockVersion, &wsaData);
//main program
sendAdress();
WSACleanup();
return 0;
}
it pops up correctly with my IP, then i sent it to my friend so he could try it for me (he has multiple IPs and i don't ) and he got
m\WSOCK32.DLL followed by his LAN ip, a line break, then his net IP.
second thing is i tried changing to winsock 2 (changed everything right in my source file) but when i compile i get a compile error like so:
D:\PROGRA~1\DEVC__~1\INCLUDE\winsock2.h:46: unbalanced `#endif'
does anyone know how i can fix this. using devc++ 4
thank you folks