diff --git a/src/main.c b/src/main.c index 1090707..0238bd5 100644 --- a/src/main.c +++ b/src/main.c @@ -17,8 +17,6 @@ void usage(void) { } int main(int argc, char **argv) { - int ret = 0; - if (argc < 4) { usage(); return -1; @@ -35,42 +33,30 @@ int main(int argc, char **argv) { char *addr = argv[2]; char *port = argv[3]; + if (direction != 'c' && direction != 's') { + usage(); + return -1; + } + + int result = 0; net_t n; crypt_session_t s; crypt_key_t ok, rk; - if (crypt_key_gen(&ok) == -1) { - ret = -1; + if ((result = crypt_key_gen(&ok)) == -1) goto cleanup; - } - if (direction == 'c') { - if (net_client_init(&n, addr, port) == -1) { - ret = -1; - goto cleanup; - } + (direction == 'c') ? + (result = net_client_init(&n, addr, port)) + : (result = net_server_init(&n, addr, port)); + if (result != 0) + goto cleanup; - int res = client_handshake(&n, &s, &ok, &rk); - - if (res != 0) { - ret = res; - goto cleanup; - } - } else if (direction == 's') { - if (net_server_init(&n, addr, port) == -1) { - ret = -1; - goto cleanup; - } - - int res = server_handshake(&n, &s, &ok, &rk); - - if (res != 0) { - ret = -1; - goto cleanup; - } - } else { - usage(); - } + (direction == 'c') ? + (result = client_handshake(&n, &s, &ok, &rk)) + : (result = server_handshake(&n, &s, &ok, &rk)); + if (result != 0) + goto cleanup; fprintf(stderr, "A connection established!\n"); @@ -84,7 +70,7 @@ cleanup: // if (audio_terminate_soundsystem() == -1) // return -1; - return ret; + return result; } int handshake(const unsigned char * hello, const char * remote_hello, crypt_session_t *const s, crypt_key_t *const ok, crypt_key_t *const rk) {