2  *    This program is free software; you can redistribute it and/or modify
 
   3  *    it under the terms of the GNU General Public License as published by
 
   4  *    the Free Software Foundation; either version 2 of the License, or
 
   5  *    (at your option) any later version.
 
   7  *    This program is distributed in the hope that it will be useful,
 
   8  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
   9  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
  10  *    GNU General Public License for more details.
 
  12  *    You should have received a copy of the GNU General Public License
 
  13  *    along with this program; if not, write to the Free Software
 
  14  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
  22 * Author : Maxim Mamontov <faust@stg.dp.ua>
 
  27 $Date: 2009/12/13 12:56:07 $
 
  32 #include "stg/plugin.h"
 
  33 #include "stg/module_settings.h"
 
  34 #include "stg/logger.h"
 
  37 #pragma GCC diagnostic push
 
  38 #pragma GCC diagnostic ignored "-Wshadow"
 
  39 #include <jthread.hpp>
 
  40 #pragma GCC diagnostic pop
 
  43 #include <unistd.h> // close
 
  45 #define VERSION "cap_nf v. 0.4"
 
  59 class NF_CAP : public Plugin
 
  64         void            SetTraffcounter(TraffCounter * tc) override { traffCnt = tc; }
 
  65         void            SetSettings(const ModuleSettings & s) override { settings = s; }
 
  66         int             ParseSettings() override;
 
  70         int             Reload(const ModuleSettings & /*ms*/) override { return 0; }
 
  72         bool            IsRunning() override { return m_threadTCP.joinable() || m_threadUDP.joinable(); }
 
  73         const std::string & GetStrError() const override { return errorStr; }
 
  74         std::string     GetVersion() const override { return VERSION; }
 
  75         uint16_t        GetStartPosition() const override { return START_POS; }
 
  76         uint16_t        GetStopPosition() const override { return STOP_POS; }
 
  79         NF_CAP(const NF_CAP & rvalue);
 
  80         NF_CAP & operator=(const NF_CAP & rvalue);
 
  82         TraffCounter * traffCnt;
 
  83         ModuleSettings settings;
 
  84         std::jthread m_threadTCP;
 
  85         std::jthread m_threadUDP;
 
  92         mutable std::string errorStr;
 
  95         void RunUDP(std::stop_token token) noexcept;
 
  96         void RunTCP(std::stop_token token) noexcept;
 
  97         void ParseBuffer(uint8_t * buf, ssize_t size);
 
 101         void CloseTCP() { close(sockTCP); }
 
 102         void CloseUDP() { close(sockUDP); }