header file: unistd.h
int gethostname(char *name, size_t namelen);
header file: Winsock2.h
int gethostname( __out char *name, __in int namelen);
This function gets the standard host name for the local
computer, and stores it in the name parameter.
Since this function has a one-to-one correspondence with the
same function in Windows, there should not be any other changes
required other than including the needed header file. However, note
that this function is a C++ function limited to Windows 2000
Professional, Windows 2000 Server, or above.
Example of Use in Windows
#include <Winsock2.h>
char* buffer[256];
if (gethostname(buffer, 256) == 0)
printf("The local host name is %s.", buffer);
else
printf("gethostname error.");