libpcap  1.10.1
About: libpcap is a packet filter library used by tools like tcpdump.
  Fossies Dox: libpcap-1.10.1.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

rpcapd.c File Reference
#include "ftmacros.h"
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <pcap.h>
#include <signal.h>
#include "fmtutils.h"
#include "sockutils.h"
#include "varattrs.h"
#include "portability.h"
#include "rpcapd.h"
#include "config_params.h"
#include "fileconf.h"
#include "rpcap-protocol.h"
#include "daemon.h"
#include "log.h"
#include <fcntl.h>
#include <unistd.h>
#include <sys/wait.h>
Include dependency graph for rpcapd.c:

Go to the source code of this file.

Data Structures

struct  listen_sock
 

Macros

#define RPCAP_ACTIVE_WAIT   30 /* Waiting time between two attempts to open a connection, in active mode (default: 30 sec) */
 
#define SSL_CLOPTS   ""
 
#define CLOPTS   "b:dDhip:4l:na:s:f:v" SSL_CLOPTS
 

Functions

static void * main_active (void *ptr)
 'true' main of the program in case the active mode is turned on. More...
 
static void main_terminate (int sign)
 
static void main_reread_config (int sign)
 
static void accept_connections (void)
 
static void accept_connection (int listen_sock)
 
static void main_reap_children (int sign)
 
static void printusage (FILE *f)
 Prints the usage screen if it is launched in console mode. More...
 
int main (int argc, char *argv[])
 Program main. More...
 
void main_startup (void)
 

Variables

char hostlist [64000+1]
 Keeps the list of the hosts that are allowed to connect to this server. More...
 
struct active_pars activelist [10]
 Keeps the list of the hosts (host, port) on which I want to connect to (active mode) More...
 
int nullAuthAllowed
 '1' if we permit NULL authentication, '0' otherwise More...
 
static struct listen_socklisten_socks
 sockets on which we listen More...
 
char loadfile [2048+1]
 Name of the file from which we have to load the configuration. More...
 
static int passivemode = 1
 '1' if we want to run in passive mode as well More...
 
static struct addrinfo mainhints
 temporary struct to keep settings needed to open the new socket More...
 
static char address [2048+1]
 keeps the network address (either numeric or literal) to bind to More...
 
static char port [2048+1]
 keeps the network port to bind to More...
 
static volatile sig_atomic_t shutdown_server
 '1' if the server is to shut down More...
 
static volatile sig_atomic_t reread_config
 '1' if the server is to re-read its configuration More...
 
static int uses_ssl
 '1' to use TLS over the data socket More...
 
char * optarg
 

Macro Definition Documentation

◆ CLOPTS

#define CLOPTS   "b:dDhip:4l:na:s:f:v" SSL_CLOPTS

◆ RPCAP_ACTIVE_WAIT

#define RPCAP_ACTIVE_WAIT   30 /* Waiting time between two attempts to open a connection, in active mode (default: 30 sec) */

Definition at line 116 of file rpcapd.c.

◆ SSL_CLOPTS

#define SSL_CLOPTS   ""

Function Documentation

◆ accept_connection()

static void accept_connection ( int  listen_sock)
static

◆ accept_connections()

◆ main()

◆ main_active()

static void * main_active ( void *  ptr)
static

'true' main of the program in case the active mode is turned on.

This function loops forever trying to connect to the remote host, until the daemon is turned down.

Parameters
ptrit keeps the 'activepars' parameters. It is a 'void *' just because the thread APIs want this format.

Definition at line 1325 of file rpcapd.c.

References active_pars::address, active_pars::ai_family, daemon_serviceloop(), hostlist, INVALID_SOCKET, LOGPRIO_DEBUG, LOGPRIO_ERROR, nullAuthAllowed, PCAP_ERRBUF_SIZE, active_pars::port, RPCAP_ACTIVE_WAIT, rpcapd_log(), sleep_secs(), snprintf(), sock_close(), sock_initaddress(), sock_open(), SOCKET, SOCKOPEN_CLIENT, and uses_ssl.

Referenced by main_startup().

◆ main_reap_children()

static void main_reap_children ( int  sign)
static

Definition at line 830 of file rpcapd.c.

References LOGPRIO_DEBUG, and rpcapd_log().

Referenced by main().

◆ main_reread_config()

static void main_reread_config ( int  sign)
static

Definition at line 820 of file rpcapd.c.

References reread_config.

Referenced by main().

◆ main_startup()

◆ main_terminate()

static void main_terminate ( int  sign)
static

Definition at line 810 of file rpcapd.c.

References shutdown_server.

Referenced by main().

◆ printusage()

static void printusage ( FILE *  f)
static

Prints the usage screen if it is launched in console mode.

Definition at line 121 of file rpcapd.c.

References pcap_lib_version(), PROGRAM_NAME, RPCAP_DEFAULT_NETPORT, and RPCAP_DEFAULT_NETPORT_ACTIVE.

Referenced by main().

Variable Documentation

◆ activelist

struct active_pars activelist[10]

Keeps the list of the hosts (host, port) on which I want to connect to (active mode)

Definition at line 80 of file rpcapd.c.

Referenced by fileconf_read(), fileconf_save(), main(), and main_startup().

◆ address

char address[2048+1]
static

keeps the network address (either numeric or literal) to bind to

Definition at line 87 of file rpcapd.c.

Referenced by daemon_msg_findallif_req(), fileconf_read(), fileconf_save(), main(), main_startup(), pcap_remoteact_accept(), pcap_remoteact_accept_ex(), sock_getascii_addrport(), sock_getmyinfo(), and sock_present2network().

◆ hostlist

char hostlist[64000+1]

Keeps the list of the hosts that are allowed to connect to this server.

Definition at line 80 of file rpcapd.c.

Referenced by accept_connection(), fileconf_read(), fileconf_save(), main(), main_active(), pcap_remoteact_accept(), pcap_remoteact_accept_ex(), pcap_remoteact_list(), and sock_check_hostlist().

◆ listen_socks

struct listen_sock* listen_socks
static

sockets on which we listen

Definition at line 83 of file rpcapd.c.

Referenced by accept_connections(), and main_startup().

◆ loadfile

char loadfile[2048+1]

Name of the file from which we have to load the configuration.

Definition at line 84 of file rpcapd.c.

Referenced by fileconf_read(), and main().

◆ mainhints

struct addrinfo mainhints
static

temporary struct to keep settings needed to open the new socket

Definition at line 85 of file rpcapd.c.

Referenced by main(), and main_startup().

◆ nullAuthAllowed

int nullAuthAllowed

'1' if we permit NULL authentication, '0' otherwise

Definition at line 82 of file rpcapd.c.

Referenced by accept_connection(), daemon_serviceloop(), fileconf_read(), fileconf_save(), main(), and main_active().

◆ optarg

char* optarg
extern

Definition at line 48 of file getopt.c.

Referenced by getopt(), and main().

◆ passivemode

int passivemode = 1
static

'1' if we want to run in passive mode as well

Definition at line 85 of file rpcapd.c.

Referenced by main(), and main_startup().

◆ port

◆ reread_config

volatile sig_atomic_t reread_config
static

'1' if the server is to re-read its configuration

Definition at line 93 of file rpcapd.c.

Referenced by accept_connections(), and main_reread_config().

◆ shutdown_server

volatile sig_atomic_t shutdown_server
static

'1' if the server is to shut down

Definition at line 92 of file rpcapd.c.

Referenced by accept_connections(), and main_terminate().

◆ uses_ssl

int uses_ssl
static

'1' to use TLS over the data socket

Definition at line 94 of file rpcapd.c.

Referenced by accept_connection(), daemon_msg_startcap_req(), daemon_serviceloop(), main(), main_active(), pcap_findalldevs_ex_remote(), and pcap_remoteact_accept_ex().