public static System.Net.IPAddress ToIPAddress(InAddr address) { var bytes = new byte[4]; address.CopyTo(bytes, 0); return(new System.Net.IPAddress(bytes)); }
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(); } }
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); }
public static System.Net.IPAddress ToIPAddress (InAddr address) { var bytes = new byte[4]; address.CopyTo (bytes, 0); return new System.Net.IPAddress (bytes); }
public static bool TryCopy (IntPtr source, out InAddr destination) { return ToInAddr (source, out destination) == 0; }
private static extern int ToInAddr (IntPtr source, out InAddr destination);
public static bool TryCopy (ref InAddr source, IntPtr destination) { return FromInAddr (ref source, destination) == 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); }
private static extern int ToInAddr(IntPtr source, out InAddr destination);
public static bool TryCopy(ref InAddr source, IntPtr destination) { return(FromInAddr(ref source, destination) == 0); }
private static extern int FromInAddr(ref InAddr source, IntPtr destination);