aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile6
-rw-r--r--tests/test_socket.c73
2 files changed, 78 insertions, 1 deletions
diff --git a/tests/Makefile b/tests/Makefile
index 1ec30d6a..67353465 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -1,4 +1,4 @@
-all: test_tunnel test_exec test_pcap
+all: test_socket test_tunnel test_exec test_pcap
CFLAGS=-I../include/ -g -Wall
LDFLAGS=-lssh -L../build/libssh/
@@ -8,6 +8,10 @@ test_tunnel: test_tunnel.o authentication.o connection.o
test_exec: test_exec.o authentication.o connection.o
gcc -o $@ $^ $(LDFLAGS)
+test_socket: test_socket.o
+ gcc -o $@ $^ $(LDFLAGS)
+
+
test_pcap: test_pcap.o
gcc -o $@ $^ $(LDFLAGS)
diff --git a/tests/test_socket.c b/tests/test_socket.c
new file mode 100644
index 00000000..b0ca03ed
--- /dev/null
+++ b/tests/test_socket.c
@@ -0,0 +1,73 @@
+/*
+ * This file is part of the SSH Library
+ *
+ * Copyright (c) 2009 by Aris Adamantiadis
+ *
+ * The SSH Library is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or (at your
+ * option) any later version.
+ *
+ * The SSH Library is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
+ * License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with the SSH Library; see the file COPYING. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA 02111-1307, USA.
+ */
+
+/* Simple test for the socket callbacks */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <libssh/libssh.h>
+
+#include <libssh/callbacks.h>
+#include <libssh/socket.h>
+
+static int data_rcv(const void *data, size_t len, void *user){
+ printf("Received data: '");
+ fwrite(data,1,len,stdout);
+ printf("'\n");
+ return len;
+}
+
+static void controlflow(void *user, int code){
+ printf("Control flow: %x\n",code);
+}
+
+static void exception(void *user, int code, int errno_code){
+ printf("Exception: %d (%d)\n",code,errno_code);
+}
+
+static void connected(void *user, int code, int errno_code){
+ printf("Connected: %d (%d)\n",code, errno_code);
+}
+
+struct ssh_socket_callbacks_struct callbacks={
+ data_rcv,
+ controlflow,
+ exception,
+ connected,
+ NULL
+};
+int main(int argc, char **argv){
+ struct socket *s;
+ ssh_session session;
+ ssh_poll_ctx ctx;
+ if(argc < 3){
+ printf("Usage : %s host port\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+ session=ssh_new();
+ s=ssh_socket_new(session);
+ ctx=ssh_poll_ctx_new(2);
+ ssh_socket_set_callbacks(s, &callbacks);
+ ssh_poll_ctx_add_socket(ctx,s);
+
+ return EXIT_SUCCESS;
+}