| 20 | |
| 21 | |
| 22 | int cServer::Init(short a_ListenPort, short a_ConnectPort) |
| 23 | { |
| 24 | m_ConnectPort = a_ConnectPort; |
| 25 | |
| 26 | #ifdef _WIN32 |
| 27 | WSAData wsa; |
| 28 | int res = WSAStartup(0x0202, &wsa); |
| 29 | if (res != 0) |
| 30 | { |
| 31 | printf("Cannot initialize WinSock: %d\n", res); |
| 32 | return res; |
| 33 | } |
| 34 | #endif // _WIN32 |
| 35 | |
| 36 | printf("Generating protocol encryption keypair...\n"); |
| 37 | m_PrivateKey.Generate(); |
| 38 | m_PublicKeyDER = m_PrivateKey.GetPubKeyDER(); |
| 39 | |
| 40 | m_ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); |
| 41 | sockaddr_in local; |
| 42 | memset(&local, 0, sizeof(local)); |
| 43 | local.sin_family = AF_INET; |
| 44 | local.sin_addr.s_addr = 0; // All interfaces |
| 45 | local.sin_port = htons(a_ListenPort); |
| 46 | bind(m_ListenSocket, (sockaddr *)&local, sizeof(local)); |
| 47 | listen(m_ListenSocket, 1); |
| 48 | |
| 49 | printf("Listening on port %d, connecting to localhost:%d\n", a_ListenPort, a_ConnectPort); |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | |
| 55 |
no test coverage detected