diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2014-06-06 16:24:45 +0200 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2014-06-06 16:24:45 +0200 |
commit | ebb8003e8aeab50e9245d895d17e17f17ce7c175 (patch) | |
tree | c40c8d062f26141f202dd1cbb5ce8467892739e8 /tests/anonself.c | |
parent | ba0ef49f3432f0f79e21f7c0355089a4af5dacc5 (diff) | |
download | gnutls-ebb8003e8aeab50e9245d895d17e17f17ce7c175.tar.gz |
Adapted test to check gnutls_record_recv_packet().
Diffstat (limited to 'tests/anonself.c')
-rw-r--r-- | tests/anonself.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/tests/anonself.c b/tests/anonself.c index 5749e416de..330600ee72 100644 --- a/tests/anonself.c +++ b/tests/anonself.c @@ -30,6 +30,9 @@ #include <stdio.h> #include <stdlib.h> +/* This program tests anonymous authentication as well as the gnutls_record_recv_packet. + */ + #if defined(_WIN32) /* socketpair isn't supported on Win32. */ @@ -57,9 +60,6 @@ static void tls_log_func(int level, const char *str) fprintf(stderr, "|<%d>| %s", level, str); } -/* A very basic TLS client, with anonymous authentication. - */ - #define MAX_BUF 1024 #define MSG "Hello TLS" @@ -135,6 +135,12 @@ static void client(int sd) goto end; } + if (ret != strlen(MSG) || memcmp(buffer, MSG, ret) != 0) { + fail("client: received data of different size! (expected: %d, have: %d)\n", + (int)strlen(MSG), ret); + goto end; + } + if (debug) { printf("- Received %d bytes: ", ret); for (ii = 0; ii < ret; ii++) { @@ -208,6 +214,8 @@ int optval = 1; static void server(int sd) { + gnutls_packet_st packet; + /* this must be called once in the program */ global_init(); @@ -258,8 +266,7 @@ static void server(int sd) /* print_info(session); */ for (;;) { - memset(buffer, 0, MAX_BUF + 1); - ret = gnutls_record_recv(session, buffer, MAX_BUF); + ret = gnutls_record_recv_packet(session, &packet); if (ret == 0) { if (debug) @@ -272,9 +279,10 @@ static void server(int sd) } else if (ret > 0) { /* echo data back to the client */ - gnutls_record_send(session, buffer, - strlen(buffer)); + gnutls_record_send(session, packet.data.data, + packet.data.size); } + gnutls_packet_deinit(&packet); } /* do not wait for the peer to close the connection. */ |