| 40 | } |
| 41 | |
| 42 | int main(int argc, char **argv) |
| 43 | { |
| 44 | #ifdef WIN32 |
| 45 | WSADATA wsaData; |
| 46 | if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) |
| 47 | { |
| 48 | fprintf(stderr, "WSAStartup error\n"); |
| 49 | exit(EXIT_FAILURE); |
| 50 | } |
| 51 | #endif |
| 52 | |
| 53 | int sock = -1; |
| 54 | SSL_CTX *ctx; |
| 55 | SSL *ssl; |
| 56 | |
| 57 | // create SSL context |
| 58 | printf("\nCreating SSL context\n"); |
| 59 | ctx = create_context(); |
| 60 | SSL_CTX_set_ecdh_auto(ctx, 1); |
| 61 | |
| 62 | // create socket |
| 63 | sock = socket(AF_INET, SOCK_STREAM, 0); |
| 64 | if (sock == -1) |
| 65 | { |
| 66 | fprintf(stderr, "Socket creation failed\n"); |
| 67 | WSACleanup(); |
| 68 | exit(EXIT_FAILURE); |
| 69 | } |
| 70 | |
| 71 | // set up socket information |
| 72 | struct sockaddr_in serveraddr; |
| 73 | memset(&serveraddr, 0, sizeof(serveraddr)); |
| 74 | serveraddr.sin_family = AF_INET; |
| 75 | |
| 76 | if (argc == 3) |
| 77 | { |
| 78 | serveraddr.sin_port = htons(atoi(argv[2])); |
| 79 | inet_pton(AF_INET, argv[1], &(serveraddr.sin_addr)); |
| 80 | } |
| 81 | else |
| 82 | { |
| 83 | printf("Using compile definitions SERVER_HOST:%s SERVER_PORT:%s\n", SERVER_HOST, SERVER_PORT); |
| 84 | serveraddr.sin_port = htons(atoi(SERVER_PORT)); |
| 85 | inet_pton(AF_INET, SERVER_HOST, &(serveraddr.sin_addr)); |
| 86 | } |
| 87 | |
| 88 | // connect to the server |
| 89 | if (connect(sock, (struct sockaddr *)&serveraddr, sizeof(serveraddr)) == -1) |
| 90 | { |
| 91 | fprintf(stderr, "Connection failed\n"); |
| 92 | closesocket(sock); |
| 93 | WSACleanup(); |
| 94 | exit(EXIT_FAILURE); |
| 95 | } |
| 96 | |
| 97 | // create SSL object and bind to socket |
| 98 | printf("\nAttempting to initialize SSL\n"); |
| 99 | ssl = SSL_new(ctx); |
nothing calls this directly
no test coverage detected