1 /* This program is free software; you can redistribute it and/or modify
2    it under the terms of the GNU General Public License as published by
3    the Free Software Foundation; version 2 dated June, 1991.
4 
5    This program is distributed in the hope that it will be useful,
6    but WITHOUT ANY WARRANTY; without even the implied warranty of
7    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
8    GNU General Public License for more details.
9 
10    You should have received a copy of the GNU General Public License
11    along with this program;  if not, write to the Free Software
12    Foundation, Inc., 675 Mass Ave., Cambridge, MA 02139, USA. */
13 
14 #define MG_SOCKLIB_H
15 
16 #include "config.h"
17 #include <sys/types.h>
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <arpa/inet.h>
21 #ifdef HAVE_OPENSSL_SSL_H
22 #include <openssl/ssl.h>
23 #include <openssl/bio.h>
24 #endif
25 
26 #ifdef __QNX__
27 #define O_NDELAY O_NONBLOCK
28 #endif
29 
30 #define SOCKET_DELAY 0
31 #define SOCKET_NDELAY 1
32 
33 #define SOCKET_RESET 0
34 #define SOCKET_SET 1
35 #define HOST_NAMELEN 64
36 
37 typedef struct {
38    struct sockaddr_in sin;	/* sin and sinlen store address and length	*/
39    socklen_t sinlen;				/* information of the server socket			*/
40    int bindflag;			/* used to ensure bind() is only used once	*/
41    int sd;					/* Socket descriptor						*/
42 #ifdef HAVE_OPENSSL_SSL_H
43    SSL *ssl;            /* descriptor for ssl connection */
44    char *sslBufMalloc, *sslBuf;  /* ssl read buffer */
45    unsigned int sslBufSize;      /* its current size */
46 #endif
47 } SOCKET;
48 
49 SOCKET *Sopen(void);
50 int Sclose(SOCKET *);
51 int Sserver(SOCKET *, int, int);
52 int Sclient(SOCKET *, char *, int);
53 size_t Sread(int sd, char *string, int n, int timeout);
54 size_t Swrite(int sd, char *string);
55 #ifdef HAVE_OPENSSL_SSL_H
56 int Sslclient(SOCKET *, char *trustedCaDir);
57 size_t Sslread(SOCKET *s, char *string, int n, int timeout);
58 size_t Sslwrite(SOCKET *s, char *string);
59 #endif
60