本文整理匯總了C#中AddressFamily.ToString方法的典型用法代碼示例。如果您正苦於以下問題:C# AddressFamily.ToString方法的具體用法?C# AddressFamily.ToString怎麽用?C# AddressFamily.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類AddressFamily
的用法示例。
在下文中一共展示了AddressFamily.ToString方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: IsProtocolSupported
private static bool IsProtocolSupported(AddressFamily af)
{
int family;
switch (af)
{
case AddressFamily.InterNetwork:
family = Interop.libc.AF_INET;
break;
case AddressFamily.InterNetworkV6:
family = Interop.libc.AF_INET6;
break;
default:
Debug.Fail("Invalid address family: " + af.ToString());
throw new ArgumentException("af");
}
int socket = -1;
try
{
socket = Interop.libc.socket(family, Interop.libc.SOCK_DGRAM, 0);
if (socket == -1)
{
return Interop.Sys.GetLastError() != Interop.Error.EAFNOSUPPORT;
}
return true;
}
finally
{
if (socket != -1)
{
Interop.Sys.Close(socket);
}
}
}
示例2: IsProtocolSupported
private static bool IsProtocolSupported(AddressFamily af)
{
SocketError errorCode;
IntPtr s = IntPtr.Zero;
bool ret = true;
try
{
s = Interop.Winsock.WSASocketW(af, SocketType.Dgram, 0, IntPtr.Zero, 0, 0);
if (s == IntPtr.Zero)
{
errorCode = (SocketError)Marshal.GetLastWin32Error();
if (errorCode == SocketError.AddressFamilyNotSupported)
{
ret = false;
}
}
}
finally
{
if (s != IntPtr.Zero)
{
SocketError closeResult = Interop.Winsock.closesocket(s);
#if DEBUG
if (closeResult != SocketError.Success)
{
errorCode = (SocketError)Marshal.GetLastWin32Error();
Debug.Fail("Failed to detect " + af.ToString() + " protocol: " + errorCode.ToString());
}
#endif
}
}
return ret;
}