private void setMulticastOption(SocketOptionName optionName, MulticastOption MR) { IPMulticastRequest ipmr = new IPMulticastRequest(); ipmr.MulticastAddress = unchecked((int)MR.Group.m_Address); if(MR.LocalAddress != null){ ipmr.InterfaceAddress = unchecked((int)MR.LocalAddress.m_Address); } else { //this structure works w/ interfaces as well int ifIndex =IPAddress.HostToNetworkOrder(MR.InterfaceIndex); ipmr.InterfaceAddress = unchecked((int)ifIndex); } #if BIGENDIAN ipmr.MulticastAddress = (int) (((uint) ipmr.MulticastAddress << 24) | (((uint) ipmr.MulticastAddress & 0x0000FF00) << 8) | (((uint) ipmr.MulticastAddress >> 8) & 0x0000FF00) | ((uint) ipmr.MulticastAddress >> 24)); if(MR.LocalAddress != null){ ipmr.InterfaceAddress = (int) (((uint) ipmr.InterfaceAddress << 24) | (((uint) ipmr.InterfaceAddress & 0x0000FF00) << 8) | (((uint) ipmr.InterfaceAddress >> 8) & 0x0000FF00) | ((uint) ipmr.InterfaceAddress >> 24)); } #endif // BIGENDIAN GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::setMulticastOption(): optionName:" + optionName.ToString() + " MR:" + MR.ToString() + " ipmr:" + ipmr.ToString() + " IPMulticastRequest.Size:" + IPMulticastRequest.Size.ToString()); // This can throw ObjectDisposedException. SocketError errorCode = UnsafeNclNativeMethods.OSSOCK.setsockopt( m_Handle, SocketOptionLevel.IP, optionName, ref ipmr, IPMulticastRequest.Size); GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::setMulticastOption() 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, "setMulticastOption", socketException); throw socketException; } }
private void setMulticastOption(SocketOptionName optionName, MulticastOption MR) { IPMulticastRequest ipmr = new IPMulticastRequest(); ipmr.MulticastAddress = unchecked((int)MR.Group.Address); ipmr.InterfaceAddress = unchecked((int)MR.LocalAddress.Address); #if BIGENDIAN ipmr.MulticastAddress = (int) (((uint) ipmr.MulticastAddress << 24) | (((uint) ipmr.MulticastAddress & 0x0000FF00) << 8) | (((uint) ipmr.MulticastAddress >> 8) & 0x0000FF00) | ((uint) ipmr.MulticastAddress >> 24)); ipmr.InterfaceAddress = (int) (((uint) ipmr.InterfaceAddress << 24) | (((uint) ipmr.InterfaceAddress & 0x0000FF00) << 8) | (((uint) ipmr.InterfaceAddress >> 8) & 0x0000FF00) | ((uint) ipmr.InterfaceAddress >> 24)); #endif // BIGENDIAN GlobalLog.Print("Socket#" + ValidationHelper.HashString(this) + "::setMulticastOption(): optionName:" + optionName.ToString() + " MR:" + MR.ToString() + " ipmr:" + ipmr.ToString() + " IPMulticastRequest.Size:" + IPMulticastRequest.Size.ToString()); int errorCode = UnsafeNclNativeMethods.OSSOCK.setsockopt( m_Handle, SocketOptionLevel.IP, optionName, ref ipmr, IPMulticastRequest.Size ); // // if the native call fails we'll throw a SocketException // if (errorCode==SocketErrors.SocketError) { // // update our internal state after this socket error and throw // SocketException socketException = new SocketException(); UpdateStatusAfterSocketError(); throw socketException; } }