public static System.Net.IPAddress ToIPAddress(InAddr address)
        {
            var bytes = new byte[4];

            address.CopyTo(bytes, 0);
            return(new System.Net.IPAddress(bytes));
        }
Exemple #2
0
        private unsafe static void Connect(IntPtr socket, IPEndPoint ipEndPoint)
        {
            var endPointAddressBytes = ipEndPoint.Address.GetAddressBytes();
            var inAddress            = new InAddr(endPointAddressBytes);

            var sa = new SockaddrIn
            {
                sin_family = AddressFamilies.AF_INET,
                sin_port   = WinSock.htons((ushort)ipEndPoint.Port),
                sin_addr   = inAddress
            };

            var errorCode = WinSock.connect(socket, ref sa, sizeof(SockaddrIn));

            if (errorCode == WinSock.Consts.SOCKET_ERROR)
            {
                WinSock.ThrowLastWsaError();
            }
        }
Exemple #3
0
        private static unsafe bool Bind(IntPtr listeningSocket, int listeningPort)
        {
            var endPointAddressBytes = IPAddress.Any.GetAddressBytes();
            var inAddress            = new InAddr(endPointAddressBytes);

            var sa = new SockaddrIn
            {
                sin_family = AddressFamilies.AF_INET,
                sin_port   = WinSock.htons((ushort)listeningPort),
                sin_addr   = inAddress
            };

            var errorCode = WinSock.bind(listeningSocket, ref sa, sizeof(SockaddrIn));

            if (errorCode == WinSock.Consts.SOCKET_ERROR)
            {
                WinSock.ThrowLastWsaError();
                return(false);
            }

            return(true);
        }
Exemple #4
0
		public static System.Net.IPAddress ToIPAddress (InAddr address)
		{
			var bytes = new byte[4];
			address.CopyTo (bytes, 0);
			return new System.Net.IPAddress (bytes);
		}
Exemple #5
0
		public static bool TryCopy (IntPtr source, out InAddr destination)
		{
			return ToInAddr (source, out destination) == 0;
		}
Exemple #6
0
		private static extern int ToInAddr (IntPtr source, out InAddr destination);
Exemple #7
0
		public static bool TryCopy (ref InAddr source, IntPtr destination)
		{
			return FromInAddr (ref source, destination) == 0;
		}
Exemple #8
0
		private static extern int FromInAddr (ref InAddr source, IntPtr destination);
 public static bool TryCopy(IntPtr source, out InAddr destination)
 {
     return(ToInAddr(source, out destination) == 0);
 }
Exemple #10
0
 private static extern int ToInAddr(IntPtr source, out InAddr destination);
Exemple #11
0
 public static bool TryCopy(ref InAddr source, IntPtr destination)
 {
     return(FromInAddr(ref source, destination) == 0);
 }
Exemple #12
0
 private static extern int FromInAddr(ref InAddr source, IntPtr destination);