From: Thadeu Lima de Souza Cascardo Date: Fri, 7 Jun 2013 22:04:15 +0000 (-0300) Subject: Create a function for the first handshake. X-Git-Tag: v0.1~39 X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Flibreceita.git;a=commitdiff_plain;h=ecbbb31cea8177d7012e18f523cafa2166b1d5c3 Create a function for the first handshake. --- diff --git a/rnetclient.c b/rnetclient.c index e4c7638..f93f386 100644 --- a/rnetclient.c +++ b/rnetclient.c @@ -149,6 +149,22 @@ static int connect_rnet(int *c) return 0; } +static int handshake(int c) +{ + char buffer[16]; + int r; + buffer[0] = 1; + write(c, buffer, 1); + write(c, "00000000000000", 14); + r = read(c, buffer, 1); + if (r != 1 && buffer[0] != 'E') + return -1; + r = read(c, buffer, 14); + if (r != 14) + return -1; + return 0; +} + int main(int argc, char **argv) { int c; @@ -166,15 +182,10 @@ int main(int argc, char **argv) exit(1); } gnutls_transport_set_ptr(session, (gnutls_transport_ptr_t) c); - buffer[0] = 1; - write(c, buffer, 1); - write(c, "00000000000000", 14); - r = read(c, buffer, 1); - if (r != 1 && buffer[0] != 'E') - exit(1); - r = read(c, buffer, 14); - if (r != 14) + r = handshake(c); + if (r < 0) { exit(1); + } if ((r = gnutls_handshake(session)) < 0) fprintf(stderr, "error in handshake: %s\n", gnutls_strerror(r));