public static string GetHostName()
{
//
// note that we could cache the result ourselves since you
// wouldn't expect the hostname of the machine to change during
// execution, but this might still happen and we would want to
// react to that change.
//
StringBuilder sb = new StringBuilder(HostNameBufferLength);
SocketError errorCode =
Interop.Winsock.gethostname(
sb,
HostNameBufferLength);
//
// if the call failed throw a SocketException()
//
if (errorCode != SocketError.Success)
{
throw new SocketException();
}
return sb.ToString();
}