Busybox: Upgrade to 1.21.1 (stable). lsof active.
[tomato.git] / release / src / router / matrixssl / examples / sslSocket.h
blobad383ef98ee80404954910c5ace70316b7e479cd
1 /*
2 * socketLayer.h
3 * Release $Name: MATRIXSSL_1_8_8_OPEN $
5 * Sample SSL socket layer header for MatrixSSL
6 */
7 /*
8 * Copyright (c) PeerSec Networks, 2002-2009. All Rights Reserved.
9 * The latest version of this code is available at http://www.matrixssl.org
11 * This software is open source; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This General Public License does NOT permit incorporating this software
17 * into proprietary programs. If you are unable to comply with the GPL, a
18 * commercial license for this software may be purchased from PeerSec Networks
19 * at http://www.peersec.com
21 * This program is distributed in WITHOUT ANY WARRANTY; without even the
22 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23 * See the GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * http://www.gnu.org/copyleft/gpl.html
30 /******************************************************************************/
32 #ifndef _h_SSLSOCKET
33 #define _h_SSLSOCKET
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
39 #include "../matrixSsl.h"
42 OS specific macros
44 #if WIN32 || WINCE
45 #include <windows.h>
46 #include <winsock.h>
47 #define fcntl(A, B, C)
48 #define MSG_NOSIGNAL 0
49 #define WOULD_BLOCK WSAEWOULDBLOCK
50 #define getSocketError() WSAGetLastError()
51 #elif LINUX
52 #include <sys/socket.h>
53 #include <netinet/in.h>
54 #include <netinet/tcp.h>
55 #include <arpa/inet.h>
56 #ifdef OSX
57 #include <sys/socket.h>
58 #define MSG_NOSIGNAL 0
59 #endif /* OSX */
60 #include <fcntl.h>
61 #include <unistd.h>
62 #include <string.h>
63 #include <errno.h>
64 #define SOCKET_ERROR -1
65 #define getSocketError() errno
66 #define WOULD_BLOCK EAGAIN
67 #define closesocket close
68 #define MAKEWORD(A, B)
69 #define WSAStartup(A, B)
70 #define WSACleanup()
71 #define INVALID_SOCKET -1
72 typedef int WSADATA;
73 typedef int SOCKET;
74 #elif VXWORKS
75 #include <types.h>
76 #include <socket.h>
77 #include <netinet/in.h>
78 #include <netinet/tcp.h>
79 #include <fcntl.h>
80 #include <errno.h>
81 #define fcntl(A, B, C) ioctl(A, B, C)
82 #define SOCKET_ERROR -1
83 #define getSocketError() errno
84 #define WOULD_BLOCK EAGAIN
85 #define closesocket close
86 #define MAKEWORD(A, B)
87 #define WSAStartup(A, B)
88 #define WSACleanup()
89 #define INVALID_SOCKET -1
90 #define MSG_NOSIGNAL 0
91 typedef int WSADATA;
92 typedef int SOCKET;
93 #endif /* OS macros */
95 extern void breakpoint();
96 #define socketAssert(C) if (C) ; else {printf("%s:%d sslAssert(%s)\n",\
97 __FILE__, __LINE__, #C); breakpoint(); }
98 #ifndef min
99 #define min(a,b) (((a) < (b)) ? (a) : (b))
100 #endif /* min */
103 sslRead and sslWrite status values
105 #define SSLSOCKET_EOF 0x1
106 #define SSLSOCKET_CLOSE_NOTIFY 0x2
109 Connection structure
111 typedef struct {
112 ssl_t *ssl;
113 sslBuf_t inbuf;
114 sslBuf_t insock;
115 sslBuf_t outsock;
116 int outBufferCount;
117 SOCKET fd;
118 } sslConn_t;
121 Secure Socket apis
123 extern int sslConnect(sslConn_t **cp, SOCKET fd, sslKeys_t *keys,
124 sslSessionId_t *id, short cipherSuite,
125 int (*certValidator)(sslCertInfo_t *t, void *arg));
126 extern int sslAccept(sslConn_t **cp, SOCKET fd, sslKeys_t *keys,
127 int (*certValidator)(sslCertInfo_t *t, void *arg), int flags);
128 extern void sslRehandshake(sslConn_t *cp);
129 extern sslConn_t *sslDoHandshake(sslConn_t *conn, short cipherSuite);
130 extern void sslFreeConnection(sslConn_t **cp);
131 extern void sslFreeConnectionBuffers(sslConn_t **cpp);
133 extern int sslRead(sslConn_t *cp, char *buf, int len, int *status);
134 extern int sslWrite(sslConn_t *cp, char *buf, int len, int *status);
135 extern void sslWriteClosureAlert(sslConn_t *cp);
138 Socket apis
140 extern SOCKET socketListen(short port, int *err);
141 extern SOCKET socketAccept(SOCKET listenfd, int *err);
142 extern SOCKET socketConnect(char *ip, short port, int *err);
143 extern void socketShutdown(SOCKET sock);
145 extern int psSocketRead(SOCKET sock, sslBuf_t **out, int *status);
146 extern int psSocketWrite(SOCKET sock, sslBuf_t *out);
148 extern void setSocketBlock(SOCKET sock);
149 extern void setSocketNonblock(SOCKET sock);
150 extern void setSocketNodelay(SOCKET sock);
152 #if WINCE || VXWORKS
153 extern void parseCmdLineArgs(char *args, int *pargc, char ***pargv);
154 #endif /* WINCE || VXWORKS */
156 #if WINCE
157 extern time_t time();
158 #endif /* WINCE */
160 #ifdef __cplusplus
162 #endif
164 #endif /* _h_SSLSOCKET */
166 /******************************************************************************/