Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

# rpcapd.c File Reference

`#include <errno.h>`
`#include <string.h>`
`#include <stdlib.h>`
`#include <pcap.h>`
`#include <signal.h>`
`#include <pthread.h>`
`#include "rpcapd.h"`
`#include "fileconf.h"`
`#include "pcap-remote.h"`
`#include "daemon.h"`
`#include "utils.h"`
`#include "sockutils.h"`
`#include "win32-svc.h"`

Go to the source code of this file.

## Functions
void | main_passive (void *ptr)
| 'true' main of the program.
void | main_active (void *ptr)
| 'true' main of the program in case the active mode is turned on.
void | printusage ()
| Prints the usage screen if it is launched in console mode.
int | main (int argc, char *argv[], char *envp[])
| Program main.
void | main_startup (void)
void | main_cleanup (int sign)
## Variables
char | hostlist [MAX_HOST_LIST+1]
| Keeps the list of the hosts that are allowed to connect to this server.
active_pars | activelist [MAX_ACTIVE_LIST]
| Keeps the list of the hosts (host, port) on which I want to connect to (active mode).
int | nullAuthAllowed
| '1' if we permit NULL authentication, '0' otherwise
SOCKET | sockmain
| keeps the main socket identifier
char | loadfile [MAX_LINE+1]
| Name of the file from which we have to load the configuration.
int | passivemode = 1
| '1' if we want to run in passive mode as well
addrinfo | mainhints
| temporary struct to keep settings needed to open the new socket
char | address [MAX_LINE+1]
| keeps the network address (either numeric or literal) to bind to
char | port [MAX_LINE+1]
| keeps the network port to bind to
char * | optarg

## Function Documentation

int main | ( | int | argc,
|  | char * | argv[],
|  | char * | envp[]
| ) |

| Program main. Definition at line 119 of file rpcapd.c. References activelist, address, fileconf_read(), fileconf_save(), getopt(), hostlist, loadfile, main_cleanup(), main_startup(), mainhints, MAX_ACTIVE_LIST, MAX_LINE, nullAuthAllowed, optarg, passivemode, PCAP_ERRBUF_SIZE, port, printusage(), RPCAP_DEFAULT_NETADDR, RPCAP_DEFAULT_NETPORT, RPCAP_DEFAULT_NETPORT_ACTIVE, RPCAP_HOSTLIST_SEP, snprintf, SOCK_ASSERT, sock_init(), and svc_start().

void main_active | ( | void * | ptr | ) |

  | 'true' main of the program in case the active mode is turned on. It does not have any return value nor parameters. This function loops forever trying to connect to the remote host, until the daemon is turned down. Parameters:
  | ptr: | it keeps the 'activepars' parameters. It is a 'void *' just because pthreads want this format.
Definition at line 646 of file rpcapd.c. References daemon_serviceloop(), nullAuthAllowed, PCAP_ERRBUF_SIZE, pcap_strerror(), pthread_suspend(), RPCAP_ACTIVE_WAIT, snprintf, SOCK_ASSERT, sock_initaddress(), sock_open(), SOCKET, and SOCKOPEN_CLIENT. Referenced by main_startup().

void main_cleanup | ( | int | sign | ) |

| Definition at line 440 of file rpcapd.c. References PROGRAM_NAME, SOCK_ASSERT, sock_cleanup(), and sockmain. Referenced by main().

void main_passive | ( | void * | ptr | ) |

  | 'true' main of the program. It must be in a separate function because: if we're in 'console' mode, we have to put the main thread waiting for a Ctrl+C (in order to be able to stop everything) if we're in daemon mode, the main program must terminate and a new child must be created in order to create the daemon Parameters:
  | ptr: | it keeps the main socket handler (what's called 'sockmain' in the main() ), that represents the socket used in the main connection. It is a 'void *' just because pthreads want this format.
Definition at line 513 of file rpcapd.c. References daemon_serviceloop(), hostlist, nullAuthAllowed, PCAP_ERR_HOSTNOAUTH, PCAP_ERRBUF_SIZE, pcap_strerror(), RPCAP_HOSTLIST_SEP, rpcap_senderror(), snprintf, SOCK_ASSERT, sock_check_hostlist(), sock_close(), sock_geterror(), SOCKET, and sockmain. Referenced by main_startup().

void main_startup | ( | void |  | ) |

| Definition at line 302 of file rpcapd.c. References activelist, address, active_pars::address, active_pars::ai_family, main_active(), main_passive(), mainhints, MAX_ACTIVE_LIST, passivemode, PCAP_ERRBUF_SIZE, port, pthread_suspend(), SOCK_ASSERT, sock_initaddress(), sock_open(), SOCKET, SOCKET_MAXCONN, sockmain, and SOCKOPEN_SERVER. Referenced by main(), and svc_main().

void printusage | ( |  | ) |

| Prints the usage screen if it is launched in console mode. Definition at line 86 of file rpcapd.c. References PROGRAM_NAME, RPCAP_DEFAULT_NETPORT, and RPCAP_DEFAULT_NETPORT_ACTIVE. Referenced by main().

## Variable Documentation

struct active_pars activelist[MAX_ACTIVE_LIST]

| Keeps the list of the hosts (host, port) on which I want to connect to (active mode). Definition at line 60 of file rpcapd.c. Referenced by fileconf_read(), fileconf_save(), main(), and main_startup().

char address[MAX_LINE+1]

| keeps the network address (either numeric or literal) to bind to Definition at line 66 of file rpcapd.c. Referenced by daemon_findalldevs(), fileconf_read(), fileconf_save(), main(), main_startup(), pcap_remoteact_accept(), sock_getascii_addrport(), sock_getmyinfo(), sock_initaddress(), and sock_present2network().

char hostlist[MAX_HOST_LIST+1]

| Keeps the list of the hosts that are allowed to connect to this server. Definition at line 59 of file rpcapd.c. Referenced by fileconf_read(), fileconf_save(), main(), main_passive(), pcap_remoteact_accept(), pcap_remoteact_list(), and sock_check_hostlist().

char loadfile[MAX_LINE+1]

| Name of the file from which we have to load the configuration. Definition at line 63 of file rpcapd.c. Referenced by fileconf_read(), and main().

struct addrinfo mainhints

| temporary struct to keep settings needed to open the new socket Definition at line 65 of file rpcapd.c. Referenced by main(), and main_startup().

int nullAuthAllowed

| '1' if we permit NULL authentication, '0' otherwise Definition at line 61 of file rpcapd.c. Referenced by daemon_checkauth(), fileconf_read(), fileconf_save(), main(), main_active(), and main_passive().

char* optarg

| Definition at line 69 of file rpcapd.c. Referenced by getopt(), and main().

int passivemode = 1

| '1' if we want to run in passive mode as well Definition at line 64 of file rpcapd.c. Referenced by main(), and main_startup().

char port[MAX_LINE+1]

| keeps the network port to bind to Definition at line 67 of file rpcapd.c. Referenced by fileconf_read(), fileconf_save(), gen_port(), gen_portop(), gen_scode(), main(), main_startup(), pcap_createsrcstr(), pcap_findalldevs_ex(), pcap_open(), pcap_open_live(), pcap_parsesrcstr(), pcap_remoteact_accept(), sock_getascii_addrport(), sock_getmyinfo(), and sock_initaddress().

SOCKET sockmain

| keeps the main socket identifier Definition at line 62 of file rpcapd.c.

documentation. Copyright (c) 2002-2003 Politecnico di Torino. All rights reserved.