CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2002
    Location
    Virginia
    Posts
    35

    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

  2. #2
    Join Date
    May 2002
    Posts
    15
    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;
    }

  3. #3
    Join Date
    Sep 2001
    Location
    San Diego
    Posts
    2,147
    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
  •  





Click Here to Expand Forum to Full Width

Featured