Export (0) Print
Expand All
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

gethostname

Windows Mobile 6.5
A version of this page is also available for
4/8/2010

This function returns the standard host name for the local machine.


int gethostname(
  char FAR* name,
  int namelen
);

name

[out] Pointer to a buffer that receives the local host name.

namelen

[in] Length of the buffer.

If no error occurs, this function returns zero. If an error occurs, it returns SOCKET_ERROR, and a specific error code can be retrieved by calling WSAGetLastError.

The following table shows the possible error codes.

Error code Description

WSAEFAULT

The name parameter is not a valid part of the user address space, or the buffer size specified by the namelen parameter is too small to hold the complete host name.

WSANOTINITIALISED

A successful WSAStartup call must occur before using this function.

WSAENETDOWN

The network subsystem has failed.

WSAEINPROGRESS

A blocking Winsock call is in progress, or the service provider is still processing a callback function.

This function returns the name of the local host into the buffer specified by the name parameter. The host name is returned as a null-terminated string. The form of the host name is dependent on the Windows Sockets provider. It can be a simple host name or a fully qualified domain name. However, it is guaranteed that the name returned will be successfully parsed by gethostbyname or getaddrinfo.

Aa917140.note(en-us,MSDN.10).gifNote:
If no local host name has been configured, gethostname must succeed and return a token host name that gethostbyname or getaddrinfo can resolve.

Headerwinsock2.h
LibraryWs2.lib
Windows Embedded CEWindows CE 1.0 and later
Windows MobileWindows Mobile Version 5.0 and later

Community Additions

Show:
© 2015 Microsoft