X-Git-Url: http://git.cascardo.eti.br/?p=cascardo%2Frnetproxy.git;a=blobdiff_plain;f=rnetclient.c;fp=rnetclient.c;h=f01e2488eda2de2586229ecc5c5880367396b713;hp=0000000000000000000000000000000000000000;hb=85e649cd4dafd0ec8954e02fc544b801e7409b9d;hpb=c480aa1818fc7dc0000694ab254f934cfc6820a0 diff --git a/rnetclient.c b/rnetclient.c new file mode 100644 index 0000000..f01e248 --- /dev/null +++ b/rnetclient.c @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2011 Thadeu Lima de Souza Cascardo + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static void session_new(gnutls_session_t *session) +{ + static void *cred; + gnutls_init(session, GNUTLS_CLIENT); + gnutls_set_default_priority(*session); +} + +int main(int argc, char **argv) +{ + struct sockaddr_in saddr; + int c; + int r; + char buffer[256]; + gnutls_session_t session; + gnutls_global_init(); + session_new(&session); + c = socket(PF_INET, SOCK_STREAM, 0); + saddr.sin_family = AF_INET; + saddr.sin_port = htons(3456); + saddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + connect(c, (struct sockaddr *) &saddr, sizeof(saddr)); + gnutls_transport_set_ptr(session, (gnutls_transport_ptr_t) c); + buffer[0] = 1; + write(c, buffer, 1); + r = read(c, buffer, 1); + if (r != 1 && buffer[0] != 'E') + exit(1); + write(c, "00000000000000", 14); + r = read(c, buffer, 14); + if (r != 14) + exit(1); + if ((r = gnutls_handshake(session)) < 0) + fprintf(stderr, "error in handshake: %s\n", + gnutls_strerror(r)); + else + fprintf(stderr, "handshake ok\n"); + buffer[0] = 0x40; + gnutls_record_send(session, buffer, 1); + while ((r = gnutls_record_recv(session, buffer, sizeof(buffer))) > 0) + write(1, buffer, r); + close(c); + gnutls_global_deinit(); + return 0; +}