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)  

daemon.c File Reference
#include "ftmacros.h"
#include "varattrs.h"
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>
#include <sys/time.h>
#include <sys/types.h>
#include <pwd.h>
#include <pcap.h>
#include "fmtutils.h"
#include "sockutils.h"
#include "portability.h"
#include "rpcap-protocol.h"
#include "daemon.h"
#include "log.h"
Include dependency graph for daemon.c:

Go to the source code of this file.

Data Structures

struct  daemon_slpars
 
struct  session
 
struct  tls_record_header
 
struct  tls_alert
 

Macros

#define RPCAP_TIMEOUT_INIT   90
 
#define RPCAP_TIMEOUT_RUNTIME   180
 
#define RPCAP_SUSPEND_WRONGAUTH   1
 
#define TLS_RECORD_HEADER_LEN   5
 
#define TLS_RECORD_TYPE_ALERT   21
 
#define TLS_RECORD_TYPE_HANDSHAKE   22
 
#define TLS_ALERT_LEN   2
 
#define TLS_ALERT_LEVEL_FATAL   2
 
#define TLS_ALERT_HANDSHAKE_FAILURE   40
 
#define UINT16_MAX   65535U
 
#define UINT32_MAX   4294967295U
 
#define CHECK_AND_INCREASE_REPLY_LEN(itemlen)
 
#define RPCAP_BPF_MAXINSNS   8192
 

Functions

static int daemon_msg_err (int sockctrl, void const *, uint32 plen)
 
static int daemon_msg_auth_req (struct daemon_slpars *pars, uint32 plen)
 
static int daemon_AuthUserPwd (char *username, char *password, char *errbuf)
 
static int daemon_msg_findallif_req (uint8 ver, struct daemon_slpars *pars, uint32 plen)
 
static int daemon_msg_open_req (uint8 ver, struct daemon_slpars *pars, uint32 plen, char *source, size_t sourcelen)
 
static int daemon_msg_startcap_req (uint8 ver, struct daemon_slpars *pars, uint32 plen, char *source, struct session **sessionp, struct rpcap_sampling *samp_param, int uses_ssl)
 
static int daemon_msg_endcap_req (uint8 ver, struct daemon_slpars *pars, struct session *session)
 
static int daemon_msg_updatefilter_req (uint8 ver, struct daemon_slpars *pars, struct session *session, uint32 plen)
 
static int daemon_unpackapplyfilter (int sockctrl, void const *, struct session *session, uint32 *plenp, char *errbuf)
 
static int daemon_msg_stats_req (uint8 ver, struct daemon_slpars *pars, struct session *session, uint32 plen, struct pcap_stat *stats, unsigned int svrcapt)
 
static int daemon_msg_setsampling_req (uint8 ver, struct daemon_slpars *pars, uint32 plen, struct rpcap_sampling *samp_param)
 Received the sampling parameters from remote host and it stores in the pcap_t structure. More...
 
static void daemon_seraddr (struct sockaddr_storage *sockaddrin, struct rpcap_sockaddr *sockaddrout)
 It serializes a network address. More...
 
static void * daemon_thrdatamain (void *ptr)
 
static void noop_handler (int sign)
 
static int rpcapd_recv_msg_header (int sock, void const *, struct rpcap_header *headerp)
 
static int rpcapd_recv (int sock, void const *, char *buffer, size_t toread, uint32 *plen, char *errmsgbuf)
 
static int rpcapd_discard (int sock, void const *, uint32 len)
 
static void session_close (struct session *)
 
static int is_url (const char *source)
 
int daemon_serviceloop (int sockctrl, int isactive, char *passiveClients, int nullAuthAllowed, int uses_ssl)
 
void sleep_secs (int secs)
 Suspends a thread for secs seconds. More...
 

Macro Definition Documentation

◆ CHECK_AND_INCREASE_REPLY_LEN

#define CHECK_AND_INCREASE_REPLY_LEN (   itemlen)
Value:
if (replylen > UINT32_MAX - (itemlen)) { \
pcap_strlcpy(errmsgbuf, "Reply length doesn't fit in 32 bits", \
sizeof (errmsgbuf)); \
goto error; \
} \
replylen += (uint32)(itemlen)
static void error(const char *,...)
#define UINT32_MAX
Definition: daemon.c:210
unsigned int uint32

Definition at line 1587 of file daemon.c.

◆ RPCAP_BPF_MAXINSNS

#define RPCAP_BPF_MAXINSNS   8192

Definition at line 2306 of file daemon.c.

◆ RPCAP_SUSPEND_WRONGAUTH

#define RPCAP_SUSPEND_WRONGAUTH   1

Definition at line 93 of file daemon.c.

◆ RPCAP_TIMEOUT_INIT

#define RPCAP_TIMEOUT_INIT   90

Definition at line 78 of file daemon.c.

◆ RPCAP_TIMEOUT_RUNTIME

#define RPCAP_TIMEOUT_RUNTIME   180

Definition at line 86 of file daemon.c.

◆ TLS_ALERT_HANDSHAKE_FAILURE

#define TLS_ALERT_HANDSHAKE_FAILURE   40

Definition at line 198 of file daemon.c.

◆ TLS_ALERT_LEN

#define TLS_ALERT_LEN   2

Definition at line 195 of file daemon.c.

◆ TLS_ALERT_LEVEL_FATAL

#define TLS_ALERT_LEVEL_FATAL   2

Definition at line 197 of file daemon.c.

◆ TLS_RECORD_HEADER_LEN

#define TLS_RECORD_HEADER_LEN   5

Definition at line 182 of file daemon.c.

◆ TLS_RECORD_TYPE_ALERT

#define TLS_RECORD_TYPE_ALERT   21

Definition at line 184 of file daemon.c.

◆ TLS_RECORD_TYPE_HANDSHAKE

#define TLS_RECORD_TYPE_HANDSHAKE   22

Definition at line 185 of file daemon.c.

◆ UINT16_MAX

#define UINT16_MAX   65535U

Definition at line 206 of file daemon.c.

◆ UINT32_MAX

#define UINT32_MAX   4294967295U

Definition at line 210 of file daemon.c.

Function Documentation

◆ daemon_AuthUserPwd()

static int daemon_AuthUserPwd ( char *  username,
char *  password,
char *  errbuf 
)
static

◆ daemon_msg_auth_req()

◆ daemon_msg_endcap_req()

static int daemon_msg_endcap_req ( uint8  ver,
struct daemon_slpars pars,
struct session session 
)
static

◆ daemon_msg_err()

static int daemon_msg_err ( int  sockctrl,
void const *  ssl,
uint32  plen 
)
static

◆ daemon_msg_findallif_req()

◆ daemon_msg_open_req()

◆ daemon_msg_setsampling_req()

static int daemon_msg_setsampling_req ( uint8  ver,
struct daemon_slpars pars,
uint32  plen,
struct rpcap_sampling samp_param 
)
static

◆ daemon_msg_startcap_req()

◆ daemon_msg_stats_req()

◆ daemon_msg_updatefilter_req()

◆ daemon_seraddr()

static void daemon_seraddr ( struct sockaddr_storage *  sockaddrin,
struct rpcap_sockaddr sockaddrout 
)
static

It serializes a network address.

It accepts a 'sockaddr_storage' structure as input, and it converts it appropriately into a format that can be used to be sent on the network. Basically, it applies all the hton() conversion required to the input variable.

Parameters
sockaddrina 'sockaddr_storage' pointer to the variable that has to be serialized. This variable can be both a 'sockaddr_in' and 'sockaddr_in6'.
sockaddroutan 'rpcap_sockaddr' pointer to the variable that will contain the serialized data. This variable has to be allocated by the user.
Warning
This function supports only AF_INET and AF_INET6 address families.

Definition at line 2813 of file daemon.c.

References rpcap_sockaddr_in::addr, rpcap_sockaddr_in6::addr, rpcap_sockaddr_in::family, rpcap_sockaddr_in6::family, rpcap_sockaddr_in6::flowinfo, rpcap_sockaddr_in::port, rpcap_sockaddr_in6::port, RPCAP_AF_INET, RPCAP_AF_INET6, rpcap_sockaddr_in6::scope_id, and rpcap_sockaddr_in::zero.

Referenced by daemon_msg_findallif_req().

◆ daemon_serviceloop()

int daemon_serviceloop ( int  sockctrl,
int  isactive,
char *  passiveClients,
int  nullAuthAllowed,
int  uses_ssl 
)

Definition at line 214 of file daemon.c.

References tls_alert::alert_description, tls_alert::alert_level, daemon_msg_auth_req(), daemon_msg_endcap_req(), daemon_msg_err(), daemon_msg_findallif_req(), daemon_msg_open_req(), daemon_msg_setsampling_req(), daemon_msg_startcap_req(), daemon_msg_stats_req(), daemon_msg_updatefilter_req(), session::fp, getpeername(), daemon_slpars::isactive, LOGPRIO_DEBUG, LOGPRIO_ERROR, LOGPRIO_INFO, noop_handler(), nullAuthAllowed, daemon_slpars::nullAuthAllowed, PCAP_BUF_SIZE, PCAP_ERR_ENDCAPTURE, PCAP_ERR_HOSTNOAUTH, PCAP_ERR_INITTIMEOUT, PCAP_ERR_NETW, PCAP_ERR_STARTCAPTURE, PCAP_ERR_TLS_REQUIRED, PCAP_ERR_UPDATEFILTER, PCAP_ERR_WRONGMSG, PCAP_ERR_WRONGVER, PCAP_ERRBUF_SIZE, pcap_stats(), rpcap_header::plen, pcap_stat::ps_drop, pcap_stat::ps_ifdrop, pcap_stat::ps_recv, RPCAP_HOSTLIST_SEP, RPCAP_MSG_AUTH_REPLY, RPCAP_MSG_AUTH_REQ, RPCAP_MSG_CLOSE, RPCAP_MSG_ENDCAP_REPLY, RPCAP_MSG_ENDCAP_REQ, RPCAP_MSG_ERROR, RPCAP_MSG_FINDALLIF_REPLY, RPCAP_MSG_FINDALLIF_REQ, RPCAP_MSG_OPEN_REPLY, RPCAP_MSG_OPEN_REQ, RPCAP_MSG_PACKET, RPCAP_MSG_SETSAMPLING_REPLY, RPCAP_MSG_SETSAMPLING_REQ, RPCAP_MSG_STARTCAP_REPLY, RPCAP_MSG_STARTCAP_REQ, RPCAP_MSG_STATS_REPLY, RPCAP_MSG_STATS_REQ, rpcap_msg_type_string(), RPCAP_MSG_UPDATEFILTER_REPLY, RPCAP_MSG_UPDATEFILTER_REQ, rpcap_senderror(), RPCAP_TIMEOUT_INIT, RPCAP_TIMEOUT_RUNTIME, RPCAP_VERSION_IS_SUPPORTED, rpcapd_discard(), rpcapd_log(), rpcapd_recv_msg_header(), select(), session_close(), snprintf(), sock_check_hostlist(), sock_close(), SOCK_EOF_ISNT_ERROR, sock_geterror(), SOCK_MSG_PEEK, SOCK_RECEIVEALL_YES, sock_recv(), sock_send(), daemon_slpars::sockctrl, session::sockdata, daemon_slpars::ssl, SSL, TLS_ALERT_HANDSHAKE_FAILURE, TLS_ALERT_LEN, TLS_ALERT_LEVEL_FATAL, TLS_RECORD_HEADER_LEN, TLS_RECORD_TYPE_ALERT, TLS_RECORD_TYPE_HANDSHAKE, session::TotCapt, rpcap_header::type, uses_ssl, and rpcap_header::ver.

Referenced by accept_connection(), main(), and main_active().

◆ daemon_thrdatamain()

◆ daemon_unpackapplyfilter()

◆ is_url()

static int is_url ( const char *  source)
static

Definition at line 3061 of file daemon.c.

Referenced by daemon_msg_open_req().

◆ noop_handler()

static void noop_handler ( int  sign)
static

Definition at line 2792 of file daemon.c.

Referenced by daemon_serviceloop().

◆ rpcapd_discard()

◆ rpcapd_recv()

static int rpcapd_recv ( int  sock,
void const *  ssl,
char *  buffer,
size_t  toread,
uint32 plen,
char *  errmsgbuf 
)
static

◆ rpcapd_recv_msg_header()

static int rpcapd_recv_msg_header ( int  sock,
void const *  ssl,
struct rpcap_header headerp 
)
static

◆ session_close()

◆ sleep_secs()

void sleep_secs ( int  secs)

Suspends a thread for secs seconds.

Definition at line 2860 of file daemon.c.

Referenced by daemon_msg_auth_req(), and main_active().