~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to vio/viotest-sslconnect.cc

  • Committer: Brian Aker
  • Date: 2008-07-01 23:57:12 UTC
  • Revision ID: brian@tangent.org-20080701235712-0673utj2hwrg0906
DeadĀ files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/* 
3
 
**  Virtual I/O library
4
 
**  Written by Andrei Errapart <andreie@no.spam.ee>
5
 
*/
6
 
 
7
 
#include        "all.h"
8
 
 
9
 
#include        <sys/types.h>
10
 
#include        <sys/socket.h>
11
 
#include        <netinet/in.h>
12
 
#include        <stdio.h>
13
 
#include        <unistd.h>
14
 
 
15
 
 
16
 
void
17
 
fatal_error(    const char*     r)
18
 
{
19
 
        perror(r);
20
 
        exit(0);
21
 
}
22
 
 
23
 
void
24
 
print_usage()
25
 
{
26
 
        printf("viotest-sslconnect: testing SSL virtual IO. Usage:\n");
27
 
        printf("viotest-sslconnect key cert\n");
28
 
}
29
 
 
30
 
int
31
 
main(   int     argc,
32
 
        char**  argv)
33
 
{
34
 
        char*   key = 0;
35
 
        char*   cert = 0;
36
 
 
37
 
        if (argc<3)
38
 
        {
39
 
                print_usage();
40
 
                return 1;
41
 
        }
42
 
 
43
 
        char            ip[4] = {127, 0, 0, 1};
44
 
        unsigned long   addr = (unsigned long)
45
 
                        ((unsigned long)ip[0]<<24L)|
46
 
                        ((unsigned long)ip[1]<<16L)|
47
 
                        ((unsigned long)ip[2]<< 8L)|
48
 
                        ((unsigned long)ip[3]);
49
 
        int     fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
50
 
        if (fd<0)
51
 
                fatal_error("socket");
52
 
        struct sockaddr_in      sa;
53
 
        sa.sin_family = AF_INET;
54
 
        sa.sin_port=htons(4433);
55
 
        sa.sin_addr.s_addr=htonl(addr);
56
 
        int     sa_size = sizeof sa;
57
 
        if (connect(fd, reinterpret_cast<const sockaddr*>(&sa), sa_size)==-1)
58
 
                fatal_error("connect");
59
 
        key = argv[1];
60
 
        cert = argv[2];
61
 
        printf("Key  : %s\n", key);
62
 
        printf("Cert : %s\n", cert);
63
 
 
64
 
        VIO_NS::VioSSLConnectorFd*      ssl_connector = new VIO_NS::VioSSLConnectorFd(cert, key,0,0);
65
 
 
66
 
        VIO_NS::VioSSL* vio = ssl_connector->connect(fd);
67
 
 
68
 
        char    xbuf[100];
69
 
        int     r = vio->read(xbuf, sizeof(xbuf));
70
 
        if (r<=0) {
71
 
                delete ssl_connector;
72
 
                delete vio;
73
 
                fatal_error("client:SSL_read");
74
 
        }
75
 
        xbuf[r] = 0;
76
 
        printf("client:got %s\n", xbuf);
77
 
        delete vio;
78
 
        delete ssl_connector;
79
 
        return 0;
80
 
}