本文整理汇总了C#中System.Net.Sockets.IPv6MulticastOption类的典型用法代码示例。如果您正苦于以下问题:C# IPv6MulticastOption类的具体用法?C# IPv6MulticastOption怎么用?C# IPv6MulticastOption使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IPv6MulticastOption类属于System.Net.Sockets命名空间,在下文中一共展示了IPv6MulticastOption类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Constructor1
[Test] // .ctor (IPAddress)
public void Constructor1 ()
{
IPv6MulticastOption option;
IPAddress group;
group = IPAddress.Parse ("ff02::1");
option = new IPv6MulticastOption (group);
Assert.AreSame (group, option.Group, "#A:Group");
Assert.AreEqual (0, option.InterfaceIndex, "#A:InterfaceIndex");
group = IPAddress.Parse ("224.0.0.23");
option = new IPv6MulticastOption (group);
Assert.AreSame (group, option.Group, "#B:Group");
Assert.AreEqual (0, option.InterfaceIndex, "#B:InterfaceIndex");
}
示例2: Constructor2
[Test] // .ctor (IPAddress, Int64)
public void Constructor2 ()
{
IPv6MulticastOption option;
IPAddress group;
long interfaceIndex;
group = IPAddress.Parse ("239.255.255.250");
interfaceIndex = 0;
option = new IPv6MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#A:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#A:InterfaceIndex");
group = IPAddress.Parse ("ff02::1");
interfaceIndex = 0;
option = new IPv6MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#B:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#B:InterfaceIndex");
group = IPAddress.Parse ("239.255.255.250");
interfaceIndex = 124;
option = new IPv6MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#C:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#C:InterfaceIndex");
group = IPAddress.Parse ("ff02::1");
interfaceIndex = 124;
option = new IPv6MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#D:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#D:InterfaceIndex");
group = IPAddress.Parse ("239.255.255.250");
interfaceIndex = 0xFFFFFFFF;
option = new IPv6MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#E:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#E:InterfaceIndex");
group = IPAddress.Parse ("ff02::1");
interfaceIndex = 0xFFFFFFFF;
option = new IPv6MulticastOption (group, interfaceIndex);
Assert.AreSame (group, option.Group, "#F:Group");
Assert.AreEqual (interfaceIndex, option.InterfaceIndex, "#F:InterfaceIndex");
}
示例3: InterfaceIndex_Value_OutOfRange
public void InterfaceIndex_Value_OutOfRange ()
{
IPAddress group = IPAddress.Parse ("239.255.255.250");
IPv6MulticastOption option = new IPv6MulticastOption (group, 10);
try {
option.InterfaceIndex = -1;
Assert.Fail ("#A1");
} catch (ArgumentOutOfRangeException ex) {
// Specified argument was out of the range of valid values
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#A3");
Assert.IsNotNull (ex.Message, "#A4");
Assert.AreEqual ("value", ex.ParamName, "#A5");
}
try {
option.InterfaceIndex = 0x100000000;
Assert.Fail ("#B1");
} catch (ArgumentOutOfRangeException ex) {
// Specified argument was out of the range of valid values
Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
Assert.IsNull (ex.InnerException, "#B3");
Assert.IsNotNull (ex.Message, "#B4");
Assert.AreEqual ("value", ex.ParamName, "#B5");
}
// ensure original value was retained
Assert.AreEqual (10, option.InterfaceIndex, "#C");
}
示例4: SetSocketOption
[Test] // SetSocketOption (SocketOptionLevel, SocketOptionName, Object)
public void SetSocketOption3_DropMembershipIPv6_IPv6MulticastOption ()
{
if (!Socket.OSSupportsIPv6)
Assert.Ignore ("IPv6 not enabled.");
using (Socket s = new Socket (AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Udp)) {
IPv6MulticastOption option = new IPv6MulticastOption (
IPAddress.Parse ("ff02::1"));
s.Bind (new IPEndPoint (IPAddress.IPv6Any, 1902));
s.SetSocketOption (SocketOptionLevel.IPv6, SocketOptionName.AddMembership,
option);
s.SetSocketOption (SocketOptionLevel.IPv6, SocketOptionName.DropMembership,
option);
}
}
示例5: ReleaseSocket
//.........这里部分代码省略.........
// if (externalInterface == null)
// {
// // Pri3: Do something more helpful here
// throw new Exception(Strings.UnableToFindLocalRoutingInterface);
// }
// if (Utility.IsMulticast(endPoint.Address))
// {
// // Allow multiple binds to this socket, as it will still function properly
// // (this is only the case if it is a multicast socket. Unicast sockets fail to
// // receive all data on all sockets)
// sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, -1);
// // We don't join the multicast group here, because we may not want to listen
// // to our own data (halfing our throughput). jasonv - 10/28/2004
// }
// // Add the socket to the hashtable
// SockInterfacePair sip = new SockInterfacePair(sock, externalInterface);
// socks.Add(endPoint, sip);
// // Increase the socket's reference count
// ++sock.refCount;
// return sip;
// }
// }
//}
//internal static void ReleaseSharedSocket(IPEndPoint endPoint, UdpSocket sock)
//{
// object sockObj = socks[endPoint];
// if (sockObj == null)
// throw new InvalidOperationException(Strings.SockDoesNotExistAsASharedSocket);
// lock (socks)
// {
// if (--sock.refCount <= 0)
// {
// // Leave the multicast group
// if (Utility.IsMulticast(endPoint.Address))
// {
// try
// {
// if (endPoint.AddressFamily == AddressFamily.InterNetworkV6)
// {
// IPv6MulticastOption mo = new IPv6MulticastOption(endPoint.Address);
// sock.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.DropMembership, mo);
// }
// else
// {
// MulticastOption mo = new MulticastOption(endPoint.Address);
// sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.DropMembership, mo);
// }
// }
// catch { } // The user of the socket *may* not have joined the multicast group (?)
// }
// // Remove ourselves from the shared pool
// socks.Remove(endPoint);
// // Close the socket
// try
// {
// sock.Close();
// }
// catch (ObjectDisposedException) { }
// }
// }
//}
internal static void ReleaseSocket(IPEndPoint endPoint, UdpSocket sock)
{
// Leave the multicast group
if (Utility.IsMulticast(endPoint.Address))
{
try
{
if (endPoint.AddressFamily == AddressFamily.InterNetworkV6)
{
IPv6MulticastOption mo = new IPv6MulticastOption(endPoint.Address);
sock.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.DropMembership, mo);
}
else
{
MulticastOption mo = new MulticastOption(endPoint.Address);
sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.DropMembership, mo);
}
}
catch { } // The user of the socket *may* not have joined the multicast group (?)
}
// Close the socket
try
{
sock.Close();
}
catch (ObjectDisposedException) { }
}
示例6: SetIPv6MulticastOption
public static unsafe SocketError SetIPv6MulticastOption(SafeCloseSocket handle, SocketOptionName optionName, IPv6MulticastOption optionValue)
{
Debug.Assert(optionName == SocketOptionName.AddMembership || optionName == SocketOptionName.DropMembership);
Interop.Sys.MulticastOption optName = optionName == SocketOptionName.AddMembership ?
Interop.Sys.MulticastOption.MULTICAST_ADD :
Interop.Sys.MulticastOption.MULTICAST_DROP;
var opt = new Interop.Sys.IPv6MulticastOption {
Address = optionValue.Group.GetNativeIPAddress(),
InterfaceIndex = (int)optionValue.InterfaceIndex
};
Interop.Error err = Interop.Sys.SetIPv6MulticastOption(handle.FileDescriptor, optName, &opt);
return err == Interop.Error.SUCCESS ? SocketError.Success : GetSocketErrorForErrorCode(err);
}
示例7: SetIPv6MulticastOption
public static unsafe SocketError SetIPv6MulticastOption(SafeCloseSocket handle, SocketOptionName optionName, IPv6MulticastOption optionValue)
{
int optLevel, optName;
GetPlatformOptionInfo(SocketOptionLevel.IPv6, optionName, out optLevel, out optName);
var mreq = new Interop.libc.ipv6_mreq {
// TODO: what is the endianness of ipv6mr_ifindex?
ipv6mr_ifindex = checked((int)optionValue.InterfaceIndex)
};
byte[] multicastAddress = optionValue.Group.GetAddressBytes();
Debug.Assert(multicastAddress.Length == sizeof(Interop.libc.in6_addr));
for (int i = 0; i < multicastAddress.Length; i++)
{
mreq.ipv6mr_multiaddr.s6_addr[i] = multicastAddress[i];
}
int err = Interop.libc.setsockopt(handle.FileDescriptor, optLevel, optName, &mreq, (uint)sizeof(Interop.libc.ipv6_mreq));
return err == -1 ? GetLastSocketError() : SocketError.Success;
}
示例8: setIPv6MulticastOption
/// <devdoc>
/// <para>
/// IPv6 setsockopt for JOIN / LEAVE multicast group
/// </para>
/// </devdoc>
private void setIPv6MulticastOption(SocketOptionName optionName, IPv6MulticastOption MR) {
IPv6MulticastRequest ipmr = new IPv6MulticastRequest();
ipmr.MulticastAddress = MR.Group.GetAddressBytes();
ipmr.InterfaceIndex = unchecked((int)MR.InterfaceIndex);
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::setIPv6MulticastOption(): optionName:" + optionName.ToString() + " MR:" + MR.ToString() + " ipmr:" + ipmr.ToString() + " IPv6MulticastRequest.Size:" + IPv6MulticastRequest.Size.ToString());
// This can throw ObjectDisposedException.
SocketError errorCode = UnsafeNclNativeMethods.OSSOCK.setsockopt(
m_Handle,
SocketOptionLevel.IPv6,
optionName,
ref ipmr,
IPv6MulticastRequest.Size);
GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::setIPv6MulticastOption() UnsafeNclNativeMethods.OSSOCK.setsockopt returns errorCode:" + errorCode);
//
// if the native call fails we'll throw a SocketException
//
if (errorCode==SocketError.SocketError) {
//
// update our internal state after this socket error and throw
//
SocketException socketException = new SocketException();
UpdateStatusAfterSocketError(socketException);
if(s_LoggingEnabled)Logging.Exception(Logging.Sockets, this, "setIPv6MulticastOption", socketException);
throw socketException;
}
}
示例9: ProcessJoinRequest
private static RegisterMessage ProcessJoinRequest(RegisterMessage joinRequestMessage, IPAddress senderIP)
{
try
{
// If the senderIP already exists, remove it by following the rule - the last one wins
if (clientRegTable.ContainsKey(senderIP))
{
lock (clientRegTable.SyncRoot)
{
clientRegTable.Remove(senderIP);
}
}
// Insert the new entry
Random rnd = new Random();
int confirmNumber = rnd.Next(1, Int32.MaxValue);
lock (clientRegTable.SyncRoot)
{
clientRegTable.Add(senderIP, new ClientEntry(senderIP, new IPEndPoint(joinRequestMessage.groupIP,
joinRequestMessage.groupPort), DateTime.Now, confirmNumber, DateTime.Now));
ReflectorMgr.PC[ReflectorPC.ID.TotalParticipants]++;
ReflectorMgr.PC[ReflectorPC.ID.CurrentParticipats] = clientRegTable.Count;
}
joinRequestMessage.msgType = MessageType.Confirm;
joinRequestMessage.confirmNumber = confirmNumber;
joinRequestMessage.unicastPort = ReflectorMgr.ReflectorUnicastRTPListenPort;
if (joinRequestMessage.groupIP.AddressFamily == AddressFamily.InterNetwork)
{
MulticastOption mo = new MulticastOption(joinRequestMessage.groupIP,ReflectorMgr.MulticastInterfaceIP);
ReflectorMgr.Sockets.SockMCv4RTP.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, mo);
ReflectorMgr.Sockets.SockMCv4RTCP.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, mo);
}
else
{
IPv6MulticastOption mo = new IPv6MulticastOption(joinRequestMessage.groupIP);
ReflectorMgr.Sockets.SockMCv6RTP.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.AddMembership, mo);
ReflectorMgr.Sockets.SockMCv6RTCP.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.AddMembership, mo);
}
}
catch
{
joinRequestMessage.msgType = MessageType.UnknownError;
}
return joinRequestMessage;
}
示例10: SetIPv6MulticastOption
private void SetIPv6MulticastOption(SocketOptionName optionName, IPv6MulticastOption mr)
{
var optionValue = new IPv6MulticastRequest()
{
MulticastAddress = mr.Group.GetAddressBytes(),
InterfaceIndex = (int)mr.InterfaceIndex
};
if (UnsafeMethods.setsockopt(Handle, SocketOptionLevel.IPv6, optionName, ref optionValue, IPv6MulticastRequest.Size) ==
SocketError.SocketError)
{
throw new SocketException();
}
}
示例11: JoinMulticastGroup
/// <devdoc>
/// <para>
/// Joins an IPv6 multicast address group.
/// </para>
/// </devdoc>
public void JoinMulticastGroup(int ifindex,IPAddress multicastAddr) {
//
// parameter validation
//
if ( m_CleanedUp ){
throw new ObjectDisposedException(this.GetType().FullName);
}
if ( multicastAddr==null ) {
throw new ArgumentNullException("multicastAddr");
}
if ( ifindex < 0 ) {
throw new ArgumentException(SR.GetString(SR.net_value_cannot_be_negative), "ifindex");
}
//
// Ensure that this is an IPv6 client, otherwise throw WinSock
// Operation not supported socked exception.
//
if ( m_Family != AddressFamily.InterNetworkV6 ) {
throw new SocketException(SocketError.OperationNotSupported);
}
IPv6MulticastOption mcOpt = new IPv6MulticastOption(multicastAddr,ifindex);
Client.SetSocketOption(
SocketOptionLevel.IPv6,
SocketOptionName.AddMembership,
mcOpt );
}
示例12: setIPv6MulticastOption
private void setIPv6MulticastOption(SocketOptionName optionName, IPv6MulticastOption MR)
{
if (UnsafeNclNativeMethods.OSSOCK.setsockopt(this.m_Handle, SocketOptionLevel.IPv6, optionName, ref new IPv6MulticastRequest()
{
MulticastAddress = MR.Group.GetAddressBytes(),
InterfaceIndex = (int) MR.InterfaceIndex
}, IPv6MulticastRequest.Size) != SocketError.SocketError)
return;
SocketException socketException = new SocketException();
this.UpdateStatusAfterSocketError(socketException);
if (Socket.s_LoggingEnabled)
Logging.Exception(Logging.Sockets, (object) this, "setIPv6MulticastOption", (Exception) socketException);
throw socketException;
}
示例13: SetIPv6MulticastOption
// IPv6 setsockopt for JOIN / LEAVE multicast group.
private void SetIPv6MulticastOption(SocketOptionName optionName, IPv6MulticastOption MR)
{
SocketError errorCode = SocketPal.SetIPv6MulticastOption(_handle, optionName, MR);
if (NetEventSource.IsEnabled) NetEventSource.Info(this, $"Interop.Winsock.setsockopt returns errorCode:{errorCode}");
// Throw an appropriate SocketException if the native call fails.
if (errorCode != SocketError.Success)
{
// Update the internal state of this socket according to the error before throwing.
SocketException socketException = new SocketException((int)errorCode);
UpdateStatusAfterSocketError(socketException);
if (NetEventSource.IsEnabled) NetEventSource.Error(this, socketException);
throw socketException;
}
}
示例14: DropMulticastGroup
// Leaves a multicast address group.
public void DropMulticastGroup(IPAddress multicastAddr)
{
// Validate input parameters.
if (_cleanedUp)
{
throw new ObjectDisposedException(this.GetType().FullName);
}
if (multicastAddr == null)
{
throw new ArgumentNullException("multicastAddr");
}
// IPv6 Changes: we need to create the correct MulticastOption and
// must also check for address family compatibility.
if (multicastAddr.AddressFamily != _family)
{
throw new ArgumentException(SR.Format(SR.net_protocol_invalid_multicast_family, "UDP"), "multicastAddr");
}
if (_family == AddressFamily.InterNetwork)
{
MulticastOption mcOpt = new MulticastOption(multicastAddr);
_clientSocket.SetSocketOption(
SocketOptionLevel.IP,
SocketOptionName.DropMembership,
mcOpt);
}
else
{
IPv6MulticastOption mcOpt = new IPv6MulticastOption(multicastAddr);
_clientSocket.SetSocketOption(
SocketOptionLevel.IPv6,
SocketOptionName.DropMembership,
mcOpt);
}
}
示例15: DropMulticastGroup
public void DropMulticastGroup(IPAddress address)
{
Assert.AreEqual(address.AddressFamily, this.LocalEp.AddressFamily, "address.AddressFamily");
if (this.LocalEp.AddressFamily == AddressFamily.InterNetwork)
{
var option1 = new MulticastOption(address);
this._client.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.DropMembership, option1);
}
else
{
var option2 = new IPv6MulticastOption(address);
this._client.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.DropMembership, option2);
}
}