3 * Release $Name: MATRIXSSL_1_8_8_OPEN $
5 * Sample SSL socket layer header for MatrixSSL
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 /******************************************************************************/
39 #include "../matrixSsl.h"
47 #define fcntl(A, B, C)
48 #define MSG_NOSIGNAL 0
49 #define WOULD_BLOCK WSAEWOULDBLOCK
50 #define getSocketError() WSAGetLastError()
52 #include <sys/socket.h>
53 #include <netinet/in.h>
54 #include <netinet/tcp.h>
55 #include <arpa/inet.h>
57 #include <sys/socket.h>
58 #define MSG_NOSIGNAL 0
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)
71 #define INVALID_SOCKET -1
77 #include <netinet/in.h>
78 #include <netinet/tcp.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)
89 #define INVALID_SOCKET -1
90 #define MSG_NOSIGNAL 0
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(); }
99 #define min(a,b) (((a) < (b)) ? (a) : (b))
103 sslRead and sslWrite status values
105 #define SSLSOCKET_EOF 0x1
106 #define SSLSOCKET_CLOSE_NOTIFY 0x2
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
);
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
);
153 extern void parseCmdLineArgs(char *args
, int *pargc
, char ***pargv
);
154 #endif /* WINCE || VXWORKS */
157 extern time_t time();
164 #endif /* _h_SSLSOCKET */
166 /******************************************************************************/