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

# pcap-remote.c File Reference

`#include <string.h>`
`#include <stdlib.h>`
`#include <stdarg.h>`
`#include <errno.h>`
`#include <pcap.h>`
`#include <pcap-int.h>`
`#include <pcap-remote.h>`
`#include <sockutils.h>`

Go to the source code of this file.

## Defines
#define | PCAP_STATS_STANDARD 0 /*!< Used by pcap_stats_remote to see if we want standard or extended statistics */
#define | PCAP_STATS_EX 1 /*!< Used by pcap_stats_remote to see if we want standard or extended statistics */
## Functions
int | rpcap_checkver (SOCKET sock, struct rpcap_header *header, char *errbuf)
| Checks if the version contained into the message is compatible with the one handled by this implementation.
pcap_stat * | rpcap_stats_remote (pcap_t *p, struct pcap_stat *ps, int mode)
| It retrieves network statistics from the other peer.
int | pcap_pack_bpffilter (pcap_t *fp, char *sendbuf, int *sendbufidx, struct bpf_program *prog)
| Takes a bpf program and sends it to the other host.
int | pcap_createfilter_norpcappkt (pcap_t *fp, struct bpf_program *prog)
| Update the current filter in order not to capture rpcap packets.
int | rpcap_deseraddr (struct sockaddr_storage *sockaddrin, struct sockaddr_storage **sockaddrout, char *errbuf)
| It traslates (i.e. de-serializes) a 'sockaddr_storage' structure from the network byte order to the host byte order.
int | pcap_read_nocb_remote (pcap_t *p, struct pcap_pkthdr **pkt_header, u_char **pkt_data)
| It reads a packet from the network socket. This does not make use of callback (hence the "nocb" string into its name).
int | pcap_read_remote (pcap_t *p, int cnt, pcap_handler callback, u_char *user)
| It reads a packet from the network socket.
void | pcap_close_remote (pcap_t *fp)
| It sends a CLOSE command to the capture server.
int | pcap_stats_remote (pcap_t *p, struct pcap_stat *ps)
| It retrieves network statistics from the other peer.
pcap_stat * | pcap_stats_ex_remote (pcap_t *p)
| It retrieves network statistics from the other peer.
pcap_t * | pcap_opensource_remote (const char *source, struct pcap_rmtauth *auth, char *errbuf)
| It opens a remote adapter by opening an RPCAP connection and so on.
int | pcap_startcapture_remote (pcap_t *fp)
| It starts a remote capture.
int | pcap_updatefilter_remote (pcap_t *fp, struct bpf_program *prog)
| Update a filter on a remote host.
int | pcap_setfilter_remote (pcap_t *fp, struct bpf_program *prog)
| Send a filter to a remote host.
int | pcap_setsampling_remote (pcap_t *p)
| Set sampling parameters in the remote host.
int | rpcap_senderror (SOCKET sock, char *error, unsigned short errcode, char *errbuf)
| It sends a RPCAP error to the other peer.
int | rpcap_sendauth (SOCKET sock, struct pcap_rmtauth *auth, char *errbuf)
| Sends the authentication message.
void | rpcap_createhdr (struct rpcap_header *header, uint8 type, uint16 value, uint32 length)
| Creates a structure of type rpcap_header.
int | rpcap_checkmsg (char *errbuf, SOCKET sock, struct rpcap_header *header, uint8 first,...)
| Checks if the header of the received message is correct.
int | rpcap_remoteact_getsock (const char *host, char *errbuf)
| It returns the socket currently used for this active connection (active mode only).
## Variables
activehosts * | activeHosts
| Keeps a list of all the opened connections in the active mode.

## Detailed Description

This file keeps all the new funtions that are needed for the RPCAP protocol. Almost all the pcap functions need to be modified in order to become compatible with the RPCAP protocol. However, you can find here only the ones that are completely new.

This file keeps also the functions that are 'private', i.e. are needed by the RPCAP protocol but are not exported to the user.

Warning:
  All the RPCAP functions that are allowed to return a buffer containing the error description can return max PCAP_ERRBUF_SIZE characters. However there is no guarantees that the string will be zero-terminated. Best practice is to define the errbuf variable as a char of size 'PCAP_ERRBUF_SIZE+1' and to insert manually a NULL character at the end of the buffer. This will guarantee that no buffer overflows occur even if we use the printf() to show the error on the screen.

Definition in file pcap-remote.c.

## Define Documentation

#define PCAP_STATS_EX 1 /*!< Used by pcap_stats_remote to see if we want standard or extended statistics */

| Used by pcap_stats_remote to see if we want standard or extended statistics Definition at line 66 of file pcap-remote.c. Referenced by pcap_stats_ex_remote().

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

| Used by pcap_stats_remote to see if we want standard or extended statistics Definition at line 65 of file pcap-remote.c. Referenced by pcap_stats_remote(), and rpcap_stats_remote().

## Function Documentation

int pcap_pack_bpffilter | ( | pcap_t * | fp,
|  | char * | sendbuf,
|  | int * | sendbufidx,
|  | struct bpf_program * | prog
| ) |

  | Takes a bpf program and sends it to the other host. This function can be called in two cases: the pcap_startcapture() is called (we have to send the filter along with the 'start capture' command) we want to udpate the filter during a capture (i.e. the pcap_setfilter() is called when the capture is still on) This function serializes the filter into the sending buffer ('sendbuf', passed as a parameter) and return back. It does not send anything on the network. Parameters:
  | fp: | the pcap_t descriptor of the device currently opened.
  | sendbuf: | the buffer on which the serialized data has to copied.
  | sendbufidx: | it is used to return the abounf of bytes copied into the buffer.
  | prog: | the bpf program we have to copy.
Returns: '0' if everything is fine, '-1' otherwise. The error message (if one) is returned into the 'errbuf' field of the pcap_t structure. Definition at line 1289 of file pcap-remote.c. References bpf_program::bf_insns, bpf_program::bf_len, bpf_insn::code, int32, pcap_compile(), PCAP_ERRBUF_SIZE, RPCAP_NETBUF_SIZE, RPCAP_UPDATEFILTER_BPF, sock_bufferize(), and SOCKBUF_CHECKONLY. Referenced by pcap_startcapture_remote(), and pcap_updatefilter_remote().

## Variable Documentation

struct activehosts* activeHosts

| Keeps a list of all the opened connections in the active mode. Definition at line 71 of file pcap-remote.c. Referenced by pcap_close_remote(), pcap_remoteact_accept(), pcap_remoteact_close(), pcap_remoteact_list(), pcap_startcapture_remote(), and rpcap_remoteact_getsock().

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