#1694557: first skeleton of a plugin for small services (discard, echo, chargen)

master
Stephane Bortzmeyer 17 years ago
parent b612eacdbd
commit bc5c0b1ad6

@ -0,0 +1,5 @@
pkglib_LTLIBRARIES = smallservices.la
smallservices_la_SOURCES = small-services.c
smallservices_la_LDFLAGS = -module

@ -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.

@ -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)

@ -0,0 +1,60 @@
/*
*
* $Id: daytime.c 395 2007-04-04 19:26:19Z bortz $
*/
#define IN_PLUGIN
#include <echoping/echoping.h>
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()
{
}
Loading…
Cancel
Save