private void Start(ushort port, byte address1, byte address2, byte address3, byte address4) { // BIND in_addr inAddress = new in_addr(); inAddress.s_b1 = address1; inAddress.s_b2 = address2; inAddress.s_b3 = address3; inAddress.s_b4 = address4; sockaddr_in sa = new sockaddr_in(); sa.sin_family = ADDRESS_FAMILIES.AF_INET; sa.sin_port = RIOImports.htons(port); sa.sin_addr = inAddress; int result; unsafe { var size = sizeof(sockaddr_in); result = RIOImports.bind(_socket, ref sa, size); } if (result == RIOImports.SOCKET_ERROR) { RIOImports.WSACleanup(); throw new Exception("bind failed"); } // LISTEN result = RIOImports.listen(_socket, 10); if (result == RIOImports.SOCKET_ERROR) { RIOImports.WSACleanup(); throw new Exception("listen failed"); } }
public static extern int bind(IntPtr s, ref sockaddr_in name, int namelen);