Rev 9 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
/*
* Copyright (C) 2015 by Andreas Theofilu. All rights reserved!
*
* All rights reserved. No warranty, explicit or implicit, provided.
*
* NOTICE: All information contained herein is, and remains
* the property of Andreas Theofilu and his suppliers, if any.
* The intellectual and technical concepts contained
* herein are proprietary to Andreas Theofilu and its suppliers and
* may be covered by European and Foreign Patents, patents in process,
* and are protected by trade secret or copyright law.
* Dissemination of this information or reproduction of this material
* is strictly forbidden unless prior written permission is obtained
* from Andreas Theofilu.
*
* Author: Andreas Theofilu <andreas@theosys.at>
*/
#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <csignal>
#include <syslog.h>
#include <cerrno>
#include <unistd.h>
#include <pthread.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/param.h>
#include <pwd.h>
#include <grp.h>
#include "config.h"
struct SOCKETS
{
int sockfd;
int newfd;
char ip[256];
};
void daemon_start (int ignsigcld);
void sig_handler(int sig);
void changeToUser(const char *usr, const char *grp);
void sig_child ();
void *pthr_parser(void *pV_data);
void *pthr_Probe(void * pV_data);
void *processCommands(void *pV_data);
int parseCommand(int s1, char *buf);
struct SOCKETS soc; // The network sockets to be passed to a thread
int main(int argc, char **argv)
{
// First read config file and check if it was ok
config *cfg = new config();
if (!cfg->is_initialized())
{
std::cerr << "Error reading config file! Make sure there is one and that it is readable by root!" << std::endl;
exit (0);
}
CONFIGURE configs = cfg->getConfig();
// Daemonize and run in background
daemon_start(0);
changeToUser(configs.user, configs.group);
// We no longer need the configuration data here, so we remove them.
delete (cfg);
// Now start our Thread
if (pthread_create(&pthr_pars, NULL, pthr_parser, (void *)0) != 0)
{
syslog (LOG_DAEMON,"Create of thread \"pthr_parser\" failed!");
return 1;
}
while (1)
sleep(3600);
return 0;
}