Unix to Windows Porting Dictionary for HPC

Links

Function List

gethostname


Unix

header file: unistd.h

int gethostname(char *name, size_t namelen);

Windows

header file: Winsock2.h

 int gethostname( __out char *name, __in int namelen);

Purpose

This function gets the standard host name for the local computer, and stores it in the name parameter.

Discussion

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.");
  
blog comments powered by Disqus