11 #include <openssl/ssl.h>
54 printf(
"[S] %s %i\n", buff, sock->
sock);
71 printf(
"[C] %s %i\n", buff, sock->
sock);
86 void socktest(
const char *ipaddr,
int tcp,
int ssl) {
87 struct fwsocket *serv, *client, *client2;
88 void *ssl_c = NULL, *ssl_s = NULL, *ssl_c2 = NULL;
89 char *buff =
"client 1";
90 char *buff2 =
"client 2";
94 ssl_s =
sslv3_init(
"certs/cacert.pem",
"certs/server-cert.pem",
"certs/server-key.pem", SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE);
95 ssl_c =
sslv3_init(
"certs/cacert.pem",
"certs/client-cert.pem",
"certs/client-key.pem", SSL_VERIFY_NONE);
96 ssl_c2 =
sslv3_init(
"certs/cacert.pem",
"certs/client-cert.pem",
"certs/client-key.pem", SSL_VERIFY_NONE);
98 ssl_s =
dtlsv1_init(
"certs/cacert.pem",
"certs/server-cert.pem",
"certs/server-key.pem", SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE);
99 ssl_c =
dtlsv1_init(
"certs/cacert.pem",
"certs/client-cert.pem",
"certs/client-key.pem", SSL_VERIFY_NONE);
100 ssl_c2 =
dtlsv1_init(
"certs/cacert.pem",
"certs/client-cert.pem",
"certs/client-key.pem", SSL_VERIFY_NONE);
104 serv =
tcpbind(ipaddr,
"1111", ssl_s, 10);
108 serv =
udpbind(ipaddr,
"1111", ssl_s);
113 if (serv && client && client2) {
140 char *buff =
"client 1";
141 char *buff2 =
"client 2";
142 struct fwsocket *client, *client2, *server;
167 FRAMEWORK_MAIN(
"Socket Client/Server Echo (TCP/TLS/UDP/DTLS)",
"Gregory Hinton Nietsky",
"gregory@distrotech.co.za",
172 printf(
"Requires arguments %s [tcp|tls|udp|dtls|unix_d|unix_s] [ipaddr|socket]\n", argv[0]);
174 printf(
"Requires arguments %s [tcp|tls|udp|dtls] ipaddr\n", argv[0]);
182 if (!strcmp(argv[1],
"udp")) {
184 }
else if (!strcmp(argv[1],
"dtls")) {
186 }
else if (!strcmp(argv[1],
"tcp")) {
188 }
else if (!strcmp(argv[1],
"tls")) {
191 }
else if (!strcmp(argv[1],
"unix_d")) {
193 }
else if (!strcmp(argv[1],
"unix_s")) {
197 printf(
"Invalid Option\n");
void * sslv3_init(const char *cacert, const char *cert, const char *key, int verify)
Create a SSL structure for SSLv3.
int socketread(struct fwsocket *sock, void *buf, int num)
Read from a socket into a buffer.
struct fwsocket * unixsocket_client(const char *sock, int protocol, socketrecv read, void *data)
Create a client thread on the socket.
void server_func(struct fwsocket *sock, void *data)
Server thread data is available.
struct fwsocket * tcpbind(const char *ipaddr, const char *port, void *ssl, int backlog)
Generic server socket.
int socketwrite(struct fwsocket *sock, const void *buf, int num)
Write a buffer to a socket.
void * dtlsv1_init(const char *cacert, const char *cert, const char *key, int verify)
Create a SSL structure for DTLSv1.
void close_socket(struct fwsocket *sock)
Mark the socket for closure and release the reference.
int socketread_d(struct fwsocket *sock, void *buf, int num, union sockstruct *addr)
Read from a socket into a buffer.
DTS Application library API Include file.
FRAMEWORK_MAIN("Socket Client/Server Echo (TCP/TLS/UDP/DTLS)","Gregory Hinton Nietsky","gregory@distrotech.co.za","http://www.distrotech.co.za", 2013,"/var/run/sockettest", FRAMEWORK_FLAG_DAEMONLOCK, NULL)
Initialise the application under the library replacing main()
void socktest(const char *ipaddr, int tcp, int ssl)
Bassed on the options create server and clients.
struct fwsocket * udpconnect(const char *ipaddr, const char *port, void *ssl)
UDP Socket client.
void accept_func(struct fwsocket *sock, void *data)
This function does nothing and is here for completeness.
Create lockfile on daemonize latter.
void socketserver(struct fwsocket *sock, socketrecv connectfunc, socketrecv acceptfunc, threadcleanup cleanup, void *data)
Create a server thread with a socket that has been created with sockbind udpbind or tcpbind...
int socketwrite_d(struct fwsocket *sock, const void *buf, int num, union sockstruct *addr)
Write a buffer to a socket.
void unixsocktest(const char *socket, int protocol)
Same test as for socktest() but for unix domain sockets.
struct fwsocket * udpbind(const char *ipaddr, const char *port, void *ssl)
UDP server socket.
void socketclient(struct fwsocket *sock, void *data, socketrecv read, threadcleanup cleanup)
Create a server thread with a socket that has been created with sockbind udpbind or tcpbind...
void client_func(struct fwsocket *sock, void *data)
client thread data is available.
void daemonize()
Daemonise the application using fork/exit.
struct fwsocket * unixsocket_server(const char *sock, int protocol, int mask, socketrecv read, void *data)
Create and run UNIX server socket thread.
Socket union describing all address types.
struct fwsocket * tcpconnect(const char *ipaddr, const char *port, void *ssl)
TCP Socket client.