Visual C++ Network: How to get the local hostname?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: Visual C++ Network: How to get the local hostname?

Threaded View

  1. #1
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Visual C++ Network: How to get the local hostname?

    Q: How to get the local hostname?

    A:

    Code:
    #include <winsock2.h>
    
    // Add ws2_32.lib to your linker options
    
    WSADATA WSAData;
    
    // Initialize winsock dll
    if(::WSAStartup(MAKEWORD(1, 0), &WSAData) == FALSE)
      // Error handling
    
    // Get local host name
    char szHostName[128] = "";
    
    if(::gethostname(szHostName, sizeof(szHostName) - 1))
      // Error -> call 'WSAGetLastError()'
    
    // Cleanup
    WSACleanup();
    Last edited by Andreas Masur; July 25th, 2005 at 02:33 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center