sethostname
A version of this page is also available for
4/8/2010
This function is used to register the host name on a network with the Windows Internet Naming Service (WINS). This function also sets HKEY_LOCAL_MACHINE\Ident\Name and registers the name with DNS and LLMNR.
Note
DHCP Option 12 behavior is affected in the following manner when HKEY_LOCAL_MACHINE\Ident\Name is not equal to HKEY_LOCAL_MACHINE\Ident\OrigName. If the device has a unique name, where Name is not equal to OrigName, then the device will send DHCP Option 12. If the device does not have a unique name, or if both Name and OrigName do not exist under the Ident key, then the device will not send DHCP Option 12.
Syntax
int sethostname(
char* pName,
int cName
);
Parameters
- pName
[in] Pointer to the host name.
- cName
[in] Length of the host name.
Return Value
If no error occurs, this function returns zero. If an error occurs, this function returns a value of SOCKET_ERROR, and retrieves a specific error code by calling WSAGetLastError.
The following table shows possible error codes for this function.
Error code | Description |
---|---|
WSAEFAULT |
The name parameter is not a valid part of the user address space, or the buffer size specified by the cName parameter is too small to hold the complete host name. |
WSAEINVAL |
One of the parameters is invalid. |
WSAENETDOWN |
The network subsystem failed. |
WSAEALREADY |
The host already is the name specified. |
Remarks
SetHostName performs the following actions.
1. Verifies that the name follows WINS rules.
2. Updates the registry keys.
3. Signals notification_event_machine_name_change.
4. Informs the 3 following name registration facilities
Netbios/WINS
LLMNR
DNS
Requirements
Header | winsock2.h |
Library | Ws2.lib |
Windows Embedded CE | Windows CE 1.0 and later |
Windows Mobile | Windows Mobile Version 5.0 and later |