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

            address.CopyTo(bytes, 0);
            return(new System.Net.IPAddress(bytes));
        }
示例#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();
            }
        }
示例#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);
        }
示例#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);
		}
示例#5
0
		public static bool TryCopy (IntPtr source, out InAddr destination)
		{
			return ToInAddr (source, out destination) == 0;
		}
示例#6
0
		private static extern int ToInAddr (IntPtr source, out InAddr destination);
示例#7
0
		public static bool TryCopy (ref InAddr source, IntPtr destination)
		{
			return FromInAddr (ref source, destination) == 0;
		}
示例#8
0
		private static extern int FromInAddr (ref InAddr source, IntPtr destination);
示例#9
0
 public static bool TryCopy(IntPtr source, out InAddr destination)
 {
     return(ToInAddr(source, out destination) == 0);
 }
示例#10
0
 private static extern int ToInAddr(IntPtr source, out InAddr destination);
示例#11
0
 public static bool TryCopy(ref InAddr source, IntPtr destination)
 {
     return(FromInAddr(ref source, destination) == 0);
 }
示例#12
0
 private static extern int FromInAddr(ref InAddr source, IntPtr destination);