/* * UPFRAME - An Extendible Framework for the Reception and Processing of UDP Data * Template for UPFRAME plugin with traffic shaper * Copyright (C) 2003-2004 ETH DDosVax team and Caspar Schlegel * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * */ #include "libread.h" #include #include #include #include #include #include #include "bufferpacket.h" // payload types #include "udppacket.h" #include "log.h" // for the logging #include "libnetflowutil.h" // utility functions for processing netflow #include "getenvs.h" // environment variable handling int ret; bufferPacket_t *rec; struct timespec ts; char *infile; char *restartCommand; int timeout = 60; int logfacility = LOG_TO_STDOUT; char *logfile = NULL; char *path = "/tmp/nerf"; // prototype int process(bufferPacketp_t packet, int result); int process(bufferPacketp_t packet, int result) { // insert function here return 0; } int main(int argc, char **argv) { int ret; whandler_t whandler; getEnvs(NULL, &path); // get environment variable FIFOPATH if (logwriteSetMedium(logfacility, logfile, "skeleton") != 0) { fprintf(stderr, "could not open logfile: %s\n", strerror(errno)); exit(1); } logwrite(LOG_DEBUG, "skeleton started"); while(1) { printf("Announcing..."); while ((ret = readerAnnounce(path, restartCommand, timeout, &whandler, "skeleton")) == ANNOUNCENOMGMT) { // wait until mgmt is available sleep(1); }; if (ret == -1) { exit(-1); // error while announcing } printf(" done.\n"); #ifdef LIMIT /* this function will repeatedly call process and ideally never return. Here the traffic is limited to 1'000'000 Bytes/s in maximum */ if (readerTrafficShaper(1000000, process) == READERR) { #else /* no limiting here... */ if (readerTrafficShaper(0, process) == READERR) { #endif /* readerTrafficShaper only returns in case of an error. */ logwrite(LOG_DEBUG, "TrafficShaper returned with error"); exit(0); } printf("shaper exit\n"); } }