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)  

pcap-rpcap.c File Reference
#include "ftmacros.h"
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <errno.h>
#include "sockutils.h"
#include "pcap-int.h"
#include "rpcap-protocol.h"
#include "pcap-rpcap.h"
Include dependency graph for pcap-rpcap.c:

Go to the source code of this file.

Data Structures

struct  activehosts
 
struct  pcap_rpcap
 

Macros

#define PCAP_STATS_STANDARD   0 /* Used by pcap_stats_rpcap to see if we want standard or extended statistics */
 
#define SOCKADDR_IN_LEN   16 /* length of struct sockaddr_in */
 
#define SOCKADDR_IN6_LEN   28 /* length of struct sockaddr_in6 */
 
#define NEW_BSD_AF_INET_BE   ((SOCKADDR_IN_LEN << 8) | 2)
 
#define NEW_BSD_AF_INET_LE   (SOCKADDR_IN_LEN << 8)
 
#define NEW_BSD_AF_INET6_BSD_BE   ((SOCKADDR_IN6_LEN << 8) | 24) /* NetBSD, OpenBSD, BSD/OS */
 
#define NEW_BSD_AF_INET6_FREEBSD_BE   ((SOCKADDR_IN6_LEN << 8) | 28) /* FreeBSD, DragonFly BSD */
 
#define NEW_BSD_AF_INET6_DARWIN_BE   ((SOCKADDR_IN6_LEN << 8) | 30) /* macOS, iOS, anything else Darwin-based */
 
#define NEW_BSD_AF_INET6_LE   (SOCKADDR_IN6_LEN << 8)
 
#define LINUX_AF_INET6   10
 
#define HPUX_AF_INET6   22
 
#define AIX_AF_INET6   24
 
#define SOLARIS_AF_INET6   26
 
#define PCAP_TEXT_SOURCE_ADAPTER   "Network adapter"
 
#define PCAP_TEXT_SOURCE_ADAPTER_LEN   (sizeof PCAP_TEXT_SOURCE_ADAPTER - 1)
 
#define PCAP_TEXT_SOURCE_ON_REMOTE_HOST   "on remote node"
 
#define PCAP_TEXT_SOURCE_ON_REMOTE_HOST_LEN   (sizeof PCAP_TEXT_SOURCE_ON_REMOTE_HOST - 1)
 

Functions

static struct pcap_statrpcap_stats_rpcap (pcap_t *p, struct pcap_stat *ps, int mode)
 
static int pcap_pack_bpffilter (pcap_t *fp, char *sendbuf, int *sendbufidx, struct bpf_program *prog)
 
static int pcap_createfilter_norpcappkt (pcap_t *fp, struct bpf_program *prog)
 
static int pcap_updatefilter_remote (pcap_t *fp, struct bpf_program *prog)
 
static void pcap_save_current_filter_rpcap (pcap_t *fp, const char *filter)
 
static int pcap_setfilter_rpcap (pcap_t *fp, struct bpf_program *prog)
 
static int pcap_setsampling_remote (pcap_t *fp)
 
static int pcap_startcapture_remote (pcap_t *fp)
 
static int rpcap_recv_msg_header (int sock, void const *, struct rpcap_header *header, char *errbuf)
 
static int rpcap_check_msg_ver (int sock, void const *, uint8 expected_ver, struct rpcap_header *header, char *errbuf)
 
static int rpcap_check_msg_type (int sock, void const *, uint8 request_type, struct rpcap_header *header, uint16 *errcode, char *errbuf)
 
static int rpcap_process_msg_header (int sock, void const *, uint8 ver, uint8 request_type, struct rpcap_header *header, char *errbuf)
 
static int rpcap_recv (int sock, void const *, void *buffer, size_t toread, uint32 *plen, char *errbuf)
 
static void rpcap_msg_err (int sockctrl, void const *, uint32 plen, char *remote_errbuf)
 
static int rpcap_discard (int sock, void const *, uint32 len, char *errbuf)
 
static int rpcap_read_packet_msg (struct pcap_rpcap const *, pcap_t *p, size_t size)
 
static int rpcap_deseraddr (struct rpcap_sockaddr *sockaddrin, struct sockaddr_storage **sockaddrout, char *errbuf)
 
static int pcap_read_nocb_remote (pcap_t *p, struct pcap_pkthdr *pkt_header, u_char **pkt_data)
 
static int pcap_read_rpcap (pcap_t *p, int cnt, pcap_handler callback, u_char *user)
 
static void pcap_cleanup_rpcap (pcap_t *fp)
 
static int pcap_stats_rpcap (pcap_t *p, struct pcap_stat *ps)
 
static struct activehostsrpcap_remoteact_getsock (const char *host, int *error, char *errbuf)
 
static int rpcap_doauth (int sockctrl, void const *ssl, uint8 *ver, struct pcap_rmtauth *auth, char *errbuf)
 
static int pcap_getnonblock_rpcap (pcap_t *p)
 
static int pcap_setnonblock_rpcap (pcap_t *p, int nonblock)
 
static int rpcap_setup_session (const char *source, struct pcap_rmtauth *auth, int *activep, int *sockctrlp, uint8 *uses_sslp, void const **sslp, int rmt_flags, uint8 *protocol_versionp, char *host, char *port, char *iface, char *errbuf)
 
pcap_tpcap_open_rpcap (const char *source, int snaplen, int flags, int read_timeout, struct pcap_rmtauth *auth, char *errbuf)
 
static void freeaddr (struct pcap_addr *addr)
 
int pcap_findalldevs_ex_remote (const char *source, struct pcap_rmtauth *auth, pcap_if_t **alldevs, char *errbuf)
 
int pcap_remoteact_accept_ex (const char *address, const char *port, const char *hostlist, char *connectinghost, struct pcap_rmtauth *auth, int uses_ssl, char *errbuf)
 
int pcap_remoteact_accept (const char *address, const char *port, const char *hostlist, char *connectinghost, struct pcap_rmtauth *auth, char *errbuf)
 
int pcap_remoteact_close (const char *host, char *errbuf)
 
void pcap_remoteact_cleanup (void)
 
int pcap_remoteact_list (char *hostlist, char sep, int size, char *errbuf)
 

Variables

static struct activehostsactiveHosts
 
static int sockmain
 
static void const * ssl_main
 

Macro Definition Documentation

◆ AIX_AF_INET6

#define AIX_AF_INET6   24

Definition at line 289 of file pcap-rpcap.c.

◆ HPUX_AF_INET6

#define HPUX_AF_INET6   22

Definition at line 288 of file pcap-rpcap.c.

◆ LINUX_AF_INET6

#define LINUX_AF_INET6   10

Definition at line 287 of file pcap-rpcap.c.

◆ NEW_BSD_AF_INET6_BSD_BE

#define NEW_BSD_AF_INET6_BSD_BE   ((SOCKADDR_IN6_LEN << 8) | 24) /* NetBSD, OpenBSD, BSD/OS */

Definition at line 283 of file pcap-rpcap.c.

◆ NEW_BSD_AF_INET6_DARWIN_BE

#define NEW_BSD_AF_INET6_DARWIN_BE   ((SOCKADDR_IN6_LEN << 8) | 30) /* macOS, iOS, anything else Darwin-based */

Definition at line 285 of file pcap-rpcap.c.

◆ NEW_BSD_AF_INET6_FREEBSD_BE

#define NEW_BSD_AF_INET6_FREEBSD_BE   ((SOCKADDR_IN6_LEN << 8) | 28) /* FreeBSD, DragonFly BSD */

Definition at line 284 of file pcap-rpcap.c.

◆ NEW_BSD_AF_INET6_LE

#define NEW_BSD_AF_INET6_LE   (SOCKADDR_IN6_LEN << 8)

Definition at line 286 of file pcap-rpcap.c.

◆ NEW_BSD_AF_INET_BE

#define NEW_BSD_AF_INET_BE   ((SOCKADDR_IN_LEN << 8) | 2)

Definition at line 271 of file pcap-rpcap.c.

◆ NEW_BSD_AF_INET_LE

#define NEW_BSD_AF_INET_LE   (SOCKADDR_IN_LEN << 8)

Definition at line 272 of file pcap-rpcap.c.

◆ PCAP_STATS_STANDARD

#define PCAP_STATS_STANDARD   0 /* Used by pcap_stats_rpcap to see if we want standard or extended statistics */

Definition at line 75 of file pcap-rpcap.c.

◆ PCAP_TEXT_SOURCE_ADAPTER

#define PCAP_TEXT_SOURCE_ADAPTER   "Network adapter"

Definition at line 2462 of file pcap-rpcap.c.

◆ PCAP_TEXT_SOURCE_ADAPTER_LEN

#define PCAP_TEXT_SOURCE_ADAPTER_LEN   (sizeof PCAP_TEXT_SOURCE_ADAPTER - 1)

Definition at line 2463 of file pcap-rpcap.c.

◆ PCAP_TEXT_SOURCE_ON_REMOTE_HOST

#define PCAP_TEXT_SOURCE_ON_REMOTE_HOST   "on remote node"

Definition at line 2465 of file pcap-rpcap.c.

◆ PCAP_TEXT_SOURCE_ON_REMOTE_HOST_LEN

#define PCAP_TEXT_SOURCE_ON_REMOTE_HOST_LEN   (sizeof PCAP_TEXT_SOURCE_ON_REMOTE_HOST - 1)

Definition at line 2466 of file pcap-rpcap.c.

◆ SOCKADDR_IN6_LEN

#define SOCKADDR_IN6_LEN   28 /* length of struct sockaddr_in6 */

Definition at line 270 of file pcap-rpcap.c.

◆ SOCKADDR_IN_LEN

#define SOCKADDR_IN_LEN   16 /* length of struct sockaddr_in */
  • Function bodies *

Definition at line 269 of file pcap-rpcap.c.

◆ SOLARIS_AF_INET6

#define SOLARIS_AF_INET6   26

Definition at line 290 of file pcap-rpcap.c.

Function Documentation

◆ freeaddr()

static void freeaddr ( struct pcap_addr addr)
static

◆ pcap_cleanup_rpcap()

◆ pcap_createfilter_norpcappkt()

◆ pcap_findalldevs_ex_remote()

◆ pcap_getnonblock_rpcap()

static int pcap_getnonblock_rpcap ( pcap_t p)
static

Definition at line 2114 of file pcap-rpcap.c.

References pcap::errbuf, PCAP_ERRBUF_SIZE, and snprintf().

Referenced by pcap_open_rpcap().

◆ pcap_open_rpcap()

◆ pcap_pack_bpffilter()

◆ pcap_read_nocb_remote()

◆ pcap_read_rpcap()

static int pcap_read_rpcap ( pcap_t p,
int  cnt,
pcap_handler  callback,
u_char *  user 
)
static

◆ pcap_remoteact_accept()

int pcap_remoteact_accept ( const char *  address,
const char *  port,
const char *  hostlist,
char *  connectinghost,
struct pcap_rmtauth auth,
char *  errbuf 
)

Definition at line 2974 of file pcap-rpcap.c.

References address, hostlist, pcap_remoteact_accept_ex(), and port.

◆ pcap_remoteact_accept_ex()

◆ pcap_remoteact_cleanup()

void pcap_remoteact_cleanup ( void  )

Definition at line 3094 of file pcap-rpcap.c.

References closesocket, sock_cleanup(), sockmain, and ssl_main.

◆ pcap_remoteact_close()

◆ pcap_remoteact_list()

int pcap_remoteact_list ( char *  hostlist,
char  sep,
int  size,
char *  errbuf 
)

◆ pcap_save_current_filter_rpcap()

static void pcap_save_current_filter_rpcap ( pcap_t fp,
const char *  filter 
)
static

◆ pcap_setfilter_rpcap()

static int pcap_setfilter_rpcap ( pcap_t fp,
struct bpf_program prog 
)
static

◆ pcap_setnonblock_rpcap()

static int pcap_setnonblock_rpcap ( pcap_t p,
int  nonblock 
)
static

Definition at line 2122 of file pcap-rpcap.c.

References pcap::errbuf, PCAP_ERRBUF_SIZE, and snprintf().

Referenced by pcap_open_rpcap().

◆ pcap_setsampling_remote()

◆ pcap_startcapture_remote()

static int pcap_startcapture_remote ( pcap_t fp)
static

Definition at line 1057 of file pcap-rpcap.c.

References accept(), activeHosts, bpf_program::bf_len, pcap::bp, pcap::buffer, pcap::bufsize, rpcap_startcapreply::bufsize, pcap::cc, pcap_rpcap::ctrl_ssl, pcap_rpcap::data_ssl, pcap::errbuf, errno, error(), pcap::fcode, rpcap_startcapreq::flags, getpeername(), getsockname(), getsockopt(), activehosts::host, INVALID_SOCKET, activehosts::next, pcap::opt, PCAP_BUF_SIZE, pcap_close(), pcap_createfilter_norpcappkt(), PCAP_ERRBUF_SIZE, pcap_fmt_errmsg_for_errno(), pcap_freecode(), PCAP_OPENFLAG_DATATX_UDP, PCAP_OPENFLAG_NOCAPTURE_RPCAP, PCAP_OPENFLAG_PROMISCUOUS, pcap_pack_bpffilter(), pcap_setsampling_remote(), pcap_updatefilter_remote(), rpcap_header::plen, rpcap_startcapreq::portdata, rpcap_startcapreply::portdata, pcap::priv, pcap_rpcap::protocol_version, rpcap_startcapreq::read_timeout, pcap_rpcap::rmt_capstarted, pcap_rpcap::rmt_flags, pcap_rpcap::rmt_sockctrl, pcap_rpcap::rmt_sockdata, rpcap_createhdr(), rpcap_discard(), RPCAP_MSG_STARTCAP_REQ, RPCAP_NETBUF_SIZE, rpcap_process_msg_header(), rpcap_recv(), RPCAP_STARTCAPREQ_FLAG_DGRAM, RPCAP_STARTCAPREQ_FLAG_PROMISC, RPCAP_STARTCAPREQ_FLAG_SERVEROPEN, setsockopt(), rpcap_startcapreq::snaplen, pcap::snapshot, snprintf(), sock_bufferize(), sock_close(), sock_geterror(), sock_initaddress(), sock_open(), sock_send(), SOCKBUF_CHECKONLY, activehosts::sockctrl, SOCKET, SOCKOPEN_CLIENT, SOCKOPEN_SERVER, sscanf(), pcap_opt::timeout, and pcap_rpcap::uses_ssl.

Referenced by pcap_read_rpcap().

◆ pcap_stats_rpcap()

static int pcap_stats_rpcap ( pcap_t p,
struct pcap_stat ps 
)
static

Definition at line 821 of file pcap-rpcap.c.

References PCAP_STATS_STANDARD, and rpcap_stats_rpcap().

Referenced by pcap_open_rpcap().

◆ pcap_updatefilter_remote()

◆ rpcap_check_msg_type()

static int rpcap_check_msg_type ( int  sock,
void const *  ssl,
uint8  request_type,
struct rpcap_header header,
uint16 errcode,
char *  errbuf 
)
static

◆ rpcap_check_msg_ver()

static int rpcap_check_msg_ver ( int  sock,
void const *  ssl,
uint8  expected_ver,
struct rpcap_header header,
char *  errbuf 
)
static

◆ rpcap_deseraddr()

◆ rpcap_discard()

◆ rpcap_doauth()

◆ rpcap_msg_err()

static void rpcap_msg_err ( int  sockctrl,
void const *  ssl,
uint32  plen,
char *  remote_errbuf 
)
static

◆ rpcap_process_msg_header()

static int rpcap_process_msg_header ( int  sock,
void const *  ssl,
uint8  ver,
uint8  request_type,
struct rpcap_header header,
char *  errbuf 
)
static

◆ rpcap_read_packet_msg()

static int rpcap_read_packet_msg ( struct pcap_rpcap const *  rp,
pcap_t p,
size_t  size 
)
static

Definition at line 3423 of file pcap-rpcap.c.

Referenced by pcap_read_nocb_remote().

◆ rpcap_recv()

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

◆ rpcap_recv_msg_header()

static int rpcap_recv_msg_header ( int  sock,
void const *  ssl,
struct rpcap_header header,
char *  errbuf 
)
static

◆ rpcap_remoteact_getsock()

static struct activehosts* rpcap_remoteact_getsock ( const char *  host,
int *  error,
char *  errbuf 
)
static

◆ rpcap_setup_session()

static int rpcap_setup_session ( const char *  source,
struct pcap_rmtauth auth,
int *  activep,
int *  sockctrlp,
uint8 uses_sslp,
void const **  sslp,
int  rmt_flags,
uint8 protocol_versionp,
char *  host,
char *  port,
char *  iface,
char *  errbuf 
)
static

◆ rpcap_stats_rpcap()

Variable Documentation

◆ activeHosts

◆ sockmain

int sockmain
static

Definition at line 108 of file pcap-rpcap.c.

Referenced by pcap_remoteact_accept_ex(), and pcap_remoteact_cleanup().

◆ ssl_main

void const* ssl_main
static

Definition at line 109 of file pcap-rpcap.c.

Referenced by pcap_open_rpcap(), and pcap_remoteact_cleanup().