diff --git a/SRC/contrib/small-services/Makefile.am b/SRC/contrib/small-services/Makefile.am new file mode 100644 index 0000000..1eb64e0 --- /dev/null +++ b/SRC/contrib/small-services/Makefile.am @@ -0,0 +1,5 @@ +pkglib_LTLIBRARIES = smallservices.la +smallservices_la_SOURCES = small-services.c +smallservices_la_LDFLAGS = -module + + diff --git a/SRC/contrib/small-services/README b/SRC/contrib/small-services/README new file mode 100644 index 0000000..7226f5a --- /dev/null +++ b/SRC/contrib/small-services/README @@ -0,0 +1,10 @@ +small-services is an echoping plugin which implements the following +network services: + +* echo (RFC 862) +* discard (RFC 863) +* chargen (RFC 864) + +As of today (2007-12-21), these services are in the main echoping tree +but the idea is to move them to this plugin in the future. See +echoping Feature Request #1694557 at Sourceforge. diff --git a/SRC/contrib/small-services/configure.ac b/SRC/contrib/small-services/configure.ac new file mode 100644 index 0000000..881c282 --- /dev/null +++ b/SRC/contrib/small-services/configure.ac @@ -0,0 +1,9 @@ +dnl $Id: configure.ac 377 2007-03-12 20:48:05Z bortz $ + +AC_INIT(small-services, 0.0-BETA) +AC_PROG_CC(cc gcc) +AC_PROG_LIBTOOL +AM_INIT_AUTOMAKE(foreign) +AC_CONFIG_HEADERS(config.h) + +AC_OUTPUT(Makefile) diff --git a/SRC/contrib/small-services/small-services.c b/SRC/contrib/small-services/small-services.c new file mode 100644 index 0000000..b327200 --- /dev/null +++ b/SRC/contrib/small-services/small-services.c @@ -0,0 +1,60 @@ +/* + * + * $Id: daytime.c 395 2007-04-04 19:26:19Z bortz $ + */ + +#define IN_PLUGIN +#include + +struct addrinfo smallservices_server; +int sockfd; +echoping_options options; + +char * +init(const int argc, const char **argv, echoping_options global_options) +{ + options = global_options; + /* TODO: the service returned must depend on the options */ + return "echo"; +} + +void +start(struct addrinfo *res) +{ + smallservices_server = *res; +} + +int +execute() +{ + int nr; +#define MAX 256 +#define TEST_STRING "test" + char result[MAX]; + if ((sockfd = + socket(smallservices_server.ai_family, smallservices_server.ai_socktype, + smallservices_server.ai_protocol)) < 0) + err_sys("Can't open socket"); + if (connect + (sockfd, smallservices_server.ai_addr, + smallservices_server.ai_addrlen) < 0) + err_sys("Can't connect to server"); + if (write(sockfd, TEST_STRING, strlen(TEST_STRING)) != strlen(TEST_STRING)) + err_sys("Cannot write"); + nr = read(sockfd, result, strlen(TEST_STRING)); + if (nr != strlen(TEST_STRING)) + err_sys("Cannot read (only %i bytes)", nr); /* TODO: the server + * may send the + * result in chunks, + * we should loop */ + if (strcmp(result, TEST_STRING) != 0) + err_sys("Result \"%s\" is different from test string \"%s\"", + result, TEST_STRING); + close(sockfd); + return 1; +} + +void +terminate() +{ +}