Reorganised the main() func.
This commit is contained in:
parent
de1d4085b9
commit
9e9b0ba047
46
src/main.c
46
src/main.c
@ -17,8 +17,6 @@ void usage(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
int ret = 0;
|
|
||||||
|
|
||||||
if (argc < 4) {
|
if (argc < 4) {
|
||||||
usage();
|
usage();
|
||||||
return -1;
|
return -1;
|
||||||
@ -35,42 +33,30 @@ int main(int argc, char **argv) {
|
|||||||
char *addr = argv[2];
|
char *addr = argv[2];
|
||||||
char *port = argv[3];
|
char *port = argv[3];
|
||||||
|
|
||||||
|
if (direction != 'c' && direction != 's') {
|
||||||
|
usage();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int result = 0;
|
||||||
net_t n;
|
net_t n;
|
||||||
crypt_session_t s;
|
crypt_session_t s;
|
||||||
crypt_key_t ok, rk;
|
crypt_key_t ok, rk;
|
||||||
|
|
||||||
if (crypt_key_gen(&ok) == -1) {
|
if ((result = crypt_key_gen(&ok)) == -1)
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (direction == 'c') {
|
(direction == 'c') ?
|
||||||
if (net_client_init(&n, addr, port) == -1) {
|
(result = net_client_init(&n, addr, port))
|
||||||
ret = -1;
|
: (result = net_server_init(&n, addr, port));
|
||||||
|
if (result != 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
int res = client_handshake(&n, &s, &ok, &rk);
|
(direction == 'c') ?
|
||||||
|
(result = client_handshake(&n, &s, &ok, &rk))
|
||||||
if (res != 0) {
|
: (result = server_handshake(&n, &s, &ok, &rk));
|
||||||
ret = res;
|
if (result != 0)
|
||||||
goto cleanup;
|
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
fprintf(stderr, "A connection established!\n");
|
fprintf(stderr, "A connection established!\n");
|
||||||
|
|
||||||
@ -84,7 +70,7 @@ cleanup:
|
|||||||
// if (audio_terminate_soundsystem() == -1)
|
// if (audio_terminate_soundsystem() == -1)
|
||||||
// return -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) {
|
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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user