|
| 1 | +/* client.c |
| 2 | + * |
| 3 | + * Copyright (C) 2022 wolfSSL Inc. |
| 4 | + * |
| 5 | + * This file is part of wolfSSL. |
| 6 | + * |
| 7 | + * wolfSSL is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 2 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * wolfSSL is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program; if not, write to the Free Software |
| 19 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 20 | + */ |
| 21 | + |
| 22 | +#include "common.h" |
| 23 | + |
| 24 | +extern volatile int keep_running; |
| 25 | + |
| 26 | +int main(int argc, char *argv[]) |
| 27 | +{ |
| 28 | + WOLFSSL_CTX *ctx = NULL; |
| 29 | + WOLFSSL_METHOD* method = NULL; |
| 30 | + WOLFSSL* ssl = NULL; |
| 31 | + int ret; |
| 32 | + uint8_t local; |
| 33 | + uint8_t remote; |
| 34 | + |
| 35 | + if (argc != 4) { |
| 36 | + printf("Usage: ./client <CAN interface> <local ID> <remote ID>\n"); |
| 37 | + return -1; |
| 38 | + } |
| 39 | + |
| 40 | + local = strtoul(argv[2], NULL, 16); |
| 41 | + remote = strtoul(argv[3], NULL, 16); |
| 42 | + |
| 43 | + sentry_init(local, remote); |
| 44 | + ret = setup_connection(argv[1], local, remote); |
| 45 | + if (ret) { |
| 46 | + return ret; |
| 47 | + } |
| 48 | + |
| 49 | + ret = setup_ssl(SERVICE_TYPE_CLIENT, &ctx, &method, &ssl); |
| 50 | + if (ret) { |
| 51 | + return ret; |
| 52 | + } |
| 53 | + |
| 54 | + while(keep_running) { |
| 55 | + char *line = NULL; |
| 56 | + size_t len = 0; |
| 57 | + ssize_t line_size = 0; |
| 58 | + line_size = getline(&line, &len, stdin); |
| 59 | + if (line_size > 0) { |
| 60 | + printf("Sending: %s\n", line); |
| 61 | + wolfSSL_send(ssl, line, line_size, 0); |
| 62 | + printf("Message sent\n"); |
| 63 | + } |
| 64 | + free(line); |
| 65 | + } |
| 66 | + |
| 67 | + close_ssl(ctx, ssl); |
| 68 | + |
| 69 | + return 0; |
| 70 | +} |
0 commit comments