src/vsl_test_sshd.c

Go to the documentation of this file.
00001 /*
00002  * Copyright 2006, Internet2
00003  * Legal conditions are in file LICENSE
00004  * (MD5 = c434f2e53b8089d8b4d0172c7ce07360).
00005  */
00006 
00007 /**
00008  * @file   vsl_test_sshd.c
00009  * @author Nikolaus Rath
00010  * @brief  Test server for SSH Starting Mode
00011  *
00012  **/
00013 
00014 
00015 #include "vfer_api.h"
00016 #include "vsl_api.h"
00017 #include "vsl.h"
00018 #include "vsl_util.h"
00019 #include <stdio.h>
00020 
00021 /**
00022  * main
00023  */
00024 int main (int argc, char** argv) {
00025 
00026     FILE* fp;
00027     if ( argc == 2 ) {
00028         if ( (fp = fopen(argv[1], "w")) == NULL) {
00029             fprintf(stderr, "cannot open %s for writing: %s!\n",
00030                     argv[1], strerror(errno));
00031             exit(VSL_PERM);
00032         }
00033         vsl_debug(fp, NULL);
00034     }
00035 
00036    /* Init socket */
00037     vsl_sock ssock;
00038     vfer_fd vfd;
00039     int ret;
00040     if ( (ret = vsl_init()) != 0) {
00041         fprintf(stderr, "cannot init vsl: %s!\n", vsl_errortext(ret));
00042         exit(VSL_TEMP);
00043     }
00044     if ( (vfd = vfer_socket(SOCK_DGRAM)) < 0) {
00045         fprintf(stderr, "vfer_socket failed: %s!\n", vfer_errortext(vfd));
00046         exit(VSL_TEMP);
00047     }
00048     if ( (ret = vsl_socket(&ssock, vfd)) != 0) {
00049         fprintf(stderr, "vsl_socket failed: %s!\n", vsl_errortext(ret));
00050         exit(VSL_TEMP);
00051     }
00052 
00053     /* Connect */
00054     if ( (ret = vsl_accept_ssh(&ssock)) != 0) {
00055         fprintf(stderr, "vsl_accept_ssh failed: %s!\n", vsl_errortext(ret));
00056         exit(VSL_TEMP);
00057     }
00058     set_blocking(&ssock, true);
00059 
00060 
00061     // Read and Write until disconnected
00062     int maxlen = vsl_max_frame_size(&ssock);
00063     char buf[maxlen];
00064     ssize_t buflen;
00065     do {
00066         if ( (buflen=vsl_recv(&ssock, buf, maxlen)) <= 0)
00067             LOGFAIL(1, "vsl_recv returned %d: %s", buflen, vsl_errortext(buflen));
00068         if ( (ret=vsl_send(&ssock, buf, buflen)) != buflen )
00069             LOGFAIL(1, "vsl_send returned %d: %s", ret, vsl_errortext(ret));
00070     } while(1);
00071 }
00072 
00073 
00074 /*
00075  * Local Variables:
00076  * compile-command: "cd ..; make vsl_tests"
00077  * compilation-search-path: ("..")
00078  * End:
00079  */

Generated on Tue Aug 8 16:07:20 2006 for VFER by  doxygen 1.4.7