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

Q: How to get the local hostname?

A:

#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();
Note: Most of the material in this article is taken from codeguru.com
Recommended Reading :





Secured Loan - Loans - United Specialties - Mortgage Calculator