public IPAddressRange(IPAddress lower, IPAddress upper) { // Assert that lower.AddressFamily == upper.AddressFamily this.addressFamily = lower.AddressFamily; this.lowerBytes = lower.GetAddressBytes(); this.upperBytes = upper.GetAddressBytes(); }
private Socket(SafeCloseSocket fd) { this.willBlock = true; this.willBlockInternal = true; this.m_CloseTimeout = -1; s_LoggingEnabled = Logging.On; if (s_LoggingEnabled) { Logging.Enter(Logging.Sockets, this, "Socket", (string) null); } InitializeSockets(); if ((fd == null) || fd.IsInvalid) { throw new ArgumentException(SR.GetString("net_InvalidSocketHandle")); } this.m_Handle = fd; this.addressFamily = System.Net.Sockets.AddressFamily.Unknown; this.socketType = System.Net.Sockets.SocketType.Unknown; this.protocolType = System.Net.Sockets.ProtocolType.Unknown; if (s_LoggingEnabled) { Logging.Exit(Logging.Sockets, this, "Socket", (string) null); } }
//function will return connection id for this connect request ///PopData with eventtype ConnectEvent will be signal that this slot is successfully connected ///exceptionConnectionId defines connectionId with exception tuning params (returned from AddConfigException) ///exceptionConnectionId==0 means default connection ///return connectionId if success 0 otherwise public static int ConnectEndPoint(int hostId, EndPoint endPoint, int exceptionConnectionId, out byte error) { error = 0; // This class is implemented in the Xbox One Plugins API const string kXboxOneEndPointClass = "UnityEngine.XboxOne.XboxOneEndPoint"; // XboxOneEndPoint validation constants byte[] XboxOneEndPointPacketSignature = new byte[] { 0x5f, 0x24, 0x13, 0xf6 }; // Our magic signature (it's a constant we randomly-generated) const int kXboxOneEndPointPacketSize = 2 + 4 + 8; // sizeof(AddressFamily) + XboxOneEndPointPacketSignature.Length + 8 bytes(64bit pointer) const int kSDASocketStorageOffset = 6; // sizeof(AddressFamily) + XboxOneEndPointPacketSignature.Length const int kSockAddrStorageLength = 128; // sizeof(sockaddr_storage) if (endPoint == null) // We require an XboxOneEndPoint to continue { throw new NullReferenceException("Null EndPoint provided"); } if ((endPoint.GetType().FullName != kXboxOneEndPointClass) && (endPoint.GetType().FullName != "UnityEngine.PS4.SceEndPoint") && (endPoint.GetType().FullName != "UnityEngine.PSVita.SceEndPoint")) { throw new ArgumentException("Endpoint of type XboxOneEndPoint or SceEndPoint required"); } if (endPoint.GetType().FullName == kXboxOneEndPointClass) { EndPoint xboxOneEndPoint = endPoint; if (xboxOneEndPoint.AddressFamily != System.Net.Sockets.AddressFamily.InterNetworkV6) { throw new ArgumentException("XboxOneEndPoint has an invalid family"); } // Okay, now serialise the endpoint, and convert it to a normal byte[] buffer SocketAddress src = xboxOneEndPoint.Serialize(); if (src.Size != kXboxOneEndPointPacketSize) // The specified socket is not an XboxEndPoint (wrong size!) { throw new ArgumentException("XboxOneEndPoint has an invalid size"); } if (src[0] != 0 || src[1] != 0) { throw new ArgumentException("XboxOneEndPoint has an invalid family signature"); } if (src[2] != XboxOneEndPointPacketSignature[0] || src[3] != XboxOneEndPointPacketSignature[1] || src[4] != XboxOneEndPointPacketSignature[2] || src[5] != XboxOneEndPointPacketSignature[3]) { throw new ArgumentException("XboxOneEndPoint has an invalid signature"); } // Okay, now extract the pointer to the SOCKET_STORAGE address to a byte array byte[] dst = new byte[8]; // 8 bytes (64bit pointer) for (int i = 0; i < dst.Length; ++i) { dst[i] = src[kSDASocketStorageOffset + i]; } // Convert the byte[] pointer to an IntPtr IntPtr st = new IntPtr(BitConverter.ToInt64(dst, 0)); if (st == IntPtr.Zero) { throw new ArgumentException("XboxOneEndPoint has an invalid SOCKET_STORAGE pointer"); } byte[] SocketAddressFamily = new byte[2]; // short System.Runtime.InteropServices.Marshal.Copy(st, SocketAddressFamily, 0, SocketAddressFamily.Length); System.Net.Sockets.AddressFamily a = (System.Net.Sockets.AddressFamily)((((int)SocketAddressFamily[1]) << 8) + (int)SocketAddressFamily[0]); if (a != System.Net.Sockets.AddressFamily.InterNetworkV6) { throw new ArgumentException("XboxOneEndPoint has corrupt or invalid SOCKET_STORAGE pointer"); } return(Internal_ConnectEndPoint(hostId, st, kSockAddrStorageLength, exceptionConnectionId, out error)); } else { const int kSceEndPointPacketSize = 16; const int kSceSockAddrSize = 16; const int kSCE_NET_AF_INET = 2; // from <socket.h> // Sony platforms network code SocketAddress src = endPoint.Serialize(); if (src.Size != kSceEndPointPacketSize) // The specified socket is not an XboxEndPoint (wrong size!) { throw new ArgumentException("EndPoint has an invalid size"); } if (src[0] != src.Size) { throw new ArgumentException("EndPoint has an invalid size value"); } if (src[1] != kSCE_NET_AF_INET) { throw new ArgumentException("EndPoint has an invalid family value"); } byte[] dst = new byte[kSceSockAddrSize]; for (int i = 0; i < dst.Length; ++i) { dst[i] = src[i]; } IntPtr unmanagedPointer = Marshal.AllocHGlobal(dst.Length); Marshal.Copy(dst, 0, unmanagedPointer, dst.Length); int result = Internal_ConnectEndPoint(hostId, unmanagedPointer, kSceSockAddrSize, exceptionConnectionId, out error); Marshal.FreeHGlobal(unmanagedPointer); return(result); } }
public unsafe Socket(SocketInformation socketInformation) { this.willBlock = true; this.willBlockInternal = true; this.m_CloseTimeout = -1; s_LoggingEnabled = Logging.On; if (s_LoggingEnabled) { Logging.Enter(Logging.Sockets, this, "Socket", this.addressFamily); } ExceptionHelper.UnrestrictedSocketPermission.Demand(); InitializeSockets(); if ((socketInformation.ProtocolInformation == null) || (socketInformation.ProtocolInformation.Length < protocolInformationSize)) { throw new ArgumentException(SR.GetString("net_sockets_invalid_socketinformation"), "socketInformation.ProtocolInformation"); } fixed (byte* numRef = socketInformation.ProtocolInformation) { this.m_Handle = SafeCloseSocket.CreateWSASocket(numRef); UnsafeNclNativeMethods.OSSOCK.WSAPROTOCOL_INFO wsaprotocol_info = (UnsafeNclNativeMethods.OSSOCK.WSAPROTOCOL_INFO) Marshal.PtrToStructure((IntPtr) numRef, typeof(UnsafeNclNativeMethods.OSSOCK.WSAPROTOCOL_INFO)); this.addressFamily = wsaprotocol_info.iAddressFamily; this.socketType = (System.Net.Sockets.SocketType) wsaprotocol_info.iSocketType; this.protocolType = (System.Net.Sockets.ProtocolType) wsaprotocol_info.iProtocol; } if (this.m_Handle.IsInvalid) { SocketException exception = new SocketException(); if (exception.ErrorCode == 0x2726) { throw new ArgumentException(SR.GetString("net_sockets_invalid_socketinformation"), "socketInformation"); } throw exception; } if ((this.addressFamily != System.Net.Sockets.AddressFamily.InterNetwork) && (this.addressFamily != System.Net.Sockets.AddressFamily.InterNetworkV6)) { throw new NotSupportedException(SR.GetString("net_invalidversion")); } this.m_IsConnected = socketInformation.IsConnected; this.willBlock = !socketInformation.IsNonBlocking; this.InternalSetBlocking(this.willBlock); this.isListening = socketInformation.IsListening; this.UseOnlyOverlappedIO = socketInformation.UseOnlyOverlappedIO; if (socketInformation.RemoteEndPoint != null) { this.m_RightEndPoint = socketInformation.RemoteEndPoint; this.m_RemoteEndPoint = socketInformation.RemoteEndPoint; } else { SocketError notSocket; EndPoint any = null; if (this.addressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { any = IPEndPoint.Any; } else if (this.addressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) { any = IPEndPoint.IPv6Any; } SocketAddress socketAddress = any.Serialize(); try { notSocket = UnsafeNclNativeMethods.OSSOCK.getsockname(this.m_Handle, socketAddress.m_Buffer, ref socketAddress.m_Size); } catch (ObjectDisposedException) { notSocket = SocketError.NotSocket; } if (notSocket == SocketError.Success) { try { this.m_RightEndPoint = any.Create(socketAddress); } catch { } } } if (s_LoggingEnabled) { Logging.Exit(Logging.Sockets, this, "Socket", (string) null); } }
public Socket(System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType) { this.willBlock = true; this.willBlockInternal = true; this.m_CloseTimeout = -1; s_LoggingEnabled = Logging.On; if (s_LoggingEnabled) { Logging.Enter(Logging.Sockets, this, "Socket", addressFamily); } InitializeSockets(); this.m_Handle = SafeCloseSocket.CreateWSASocket(addressFamily, socketType, protocolType); if (this.m_Handle.IsInvalid) { throw new SocketException(); } this.addressFamily = addressFamily; this.socketType = socketType; this.protocolType = protocolType; IPProtectionLevel iPProtectionLevel = SettingsSectionInternal.Section.IPProtectionLevel; if (iPProtectionLevel != IPProtectionLevel.Unspecified) { this.SetIPProtectionLevel(iPProtectionLevel); } if (s_LoggingEnabled) { Logging.Exit(Logging.Sockets, this, "Socket", (string) null); } }
public SocketAddress(System.Net.Sockets.AddressFamily family) { }
public SocketAddress(System.Net.Sockets.AddressFamily family, int size) { }
public DnsEndPoint(string host, int port, System.Net.Sockets.AddressFamily addressFamily) { }
public Socket(System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType) { }
public UdpClient(System.Net.Sockets.AddressFamily family) { }
public SocketAddress(System.Net.Sockets.AddressFamily family, int size) { Contract.Ensures(-1073741822 <= System.IntPtr.Size); }
public SocketAddress(System.Net.Sockets.AddressFamily family) { Contract.Ensures(-16 <= System.IntPtr.Size); Contract.Ensures(System.IntPtr.Size <= ((2147483615 / 2))); }