本文整理汇总了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;
}