82 #include <sys/types.h>
83 #include <sys/socket.h>
84 #include <netinet/in.h>
89 #define die_unless(x) assert(x)
103 fprintf(stderr,
"%s\n",szErr);
109 fprintf(stderr,
"Error %lx: %s\n",l,buf);
114 const char *szKeyFile)
146 const unsigned char *aucBuf,
int nBuf)
154 fprintf(stderr,
"%d bytes of encrypted data fed to state machine\n",n);
158 unsigned char *aucBuf,
int nBuf)
164 fprintf(stderr,
"Doing SSL_accept\n");
167 fprintf(stderr,
"SSL_accept returned zero\n");
174 fprintf(stderr,
"SSL_accept wants more data\n");
191 fprintf(stderr,
"SSL_read wants more data\n");
199 fprintf(stderr,
"%d bytes of decrypted data read from state machine\n",n);
207 fprintf(stderr,
"There is encrypted data available to write\n");
209 fprintf(stderr,
"There is no encrypted data available to write\n");
215 unsigned char *aucBuf,
int nBuf)
220 fprintf(stderr,
"%d bytes of encrypted data read from state machine\n",n);
225 const unsigned char *aucBuf,
int nBuf)
233 fprintf(stderr,
"%d bytes of unencrypted data fed to state machine\n",n);
239 struct sockaddr_in saServer;
240 struct sockaddr_in saClient;
246 nSocket=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
253 if(setsockopt(nSocket,SOL_SOCKET,SO_REUSEADDR,(
char *)&one,
sizeof one) < 0)
255 perror(
"setsockopt");
259 memset(&saServer,0,
sizeof saServer);
260 saServer.sin_family=AF_INET;
261 saServer.sin_port=htons(nPort);
262 nSize=
sizeof saServer;
263 if(bind(nSocket,(
struct sockaddr *)&saServer,nSize) < 0)
269 if(listen(nSocket,512) < 0)
275 nLen=
sizeof saClient;
276 nFD=accept(nSocket,(
struct sockaddr *)&saClient,&nLen);
283 fprintf(stderr,
"Incoming accepted on port %d\n",nPort);
293 const char *szCertificateFile;
294 const char *szKeyFile;
300 fprintf(stderr,
"%s <port> <certificate file> <key file>\n",argv[0]);
305 szCertificateFile=argv[2];
320 unsigned char buf[1024];
345 n=select(nFD+1,&rfds,&wfds,NULL,NULL);
349 if(FD_ISSET(nFD,&rfds))
351 n=
read(nFD,buf,
sizeof buf);
354 fprintf(stderr,
"Got EOF on socket\n");
363 if(FD_ISSET(1,&wfds))
388 if(FD_ISSET(nFD,&wfds))
401 if(FD_ISSET(0,&rfds))
403 n=
read(0,buf,
sizeof buf);
406 fprintf(stderr,
"Got EOF on stdin\n");