|
-
June 11th, 2002, 04:40 PM
#1
Getting Server IP using WinSock
I just started trying to learn WinSock, heh, just dove right in after reading creating a non-blocking server from gamedev.net, and I use that to write a simply non-blocking server. You can connect to it, and if you press certain buttons it will react. But one thing I want to do, is to get the server IP so that I can set up admin access for me without entering a username and password(Which I also want to set up, but don't know how to output from client, and input strings). First I want to find server ip.
I tried
char *ServerIP = inet_ntoa(Server_Address.sin.addr);
but it outputs 0.0.0.0
Wierd... please help
-
June 13th, 2002, 10:22 AM
#2
Try this function.
void GetNameAndIP(char *name, char* address)
{
IN_ADDR addr;
HOSTENT* phe;
if (gethostname(name, strlen(name)) == SOCKET_ERROR)
{
strcpy(name,"Unknown");
strcpy(address,"Unknown");
}
else
{
phe = gethostbyname(name);
if (phe == 0)
{
strcpy(address,"Unknown");
}
else
{
memcpy(&addr, phe->h_addr_list[0], sizeof(IN_ADDR));
strcpy(address,inet_ntoa(addr));
}
}
return;
}
-
June 13th, 2002, 10:44 AM
#3
Or this one
Hope this helps,
- Nigel
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|