24 #include <sys/types.h>
25 #include <sys/socket.h>
26 #include <netinet/in.h>
32 fatal_error(
const char* r)
41 printf(
"viotest-sslconnect: testing SSL virtual IO. Usage:\n");
42 printf(
"viotest-sslconnect key cert\n");
58 char ip[4] = {127, 0, 0, 1};
59 unsigned long addr = (
unsigned long)
60 ((
unsigned long)ip[0]<<24L)|
61 ((
unsigned long)ip[1]<<16L)|
62 ((
unsigned long)ip[2]<< 8L)|
63 ((
unsigned long)ip[3]);
64 int fd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
66 fatal_error(
"socket");
67 struct sockaddr_in sa;
68 sa.sin_family = AF_INET;
69 sa.sin_port=htons(4433);
70 sa.sin_addr.s_addr=htonl(addr);
71 int sa_size =
sizeof sa;
72 if (connect(fd, reinterpret_cast<const sockaddr*>(&sa), sa_size)==-1)
73 fatal_error(
"connect");
76 printf(
"Key : %s\n", key);
77 printf(
"Cert : %s\n", cert);
79 VIO_NS::VioSSLConnectorFd* ssl_connector =
new VIO_NS::VioSSLConnectorFd(cert, key,0,0);
81 VIO_NS::VioSSL* vio = ssl_connector->connect(fd);
84 int r = vio->read(xbuf,
sizeof(xbuf));
88 fatal_error(
"client:SSL_read");
91 printf(
"client:got %s\n", xbuf);