* Yes.
*/
*is_ours = 1;
- p = pcap_create_common(ebuf, sizeof (struct pcap_airpcap));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_airpcap);
if (p == NULL)
return (NULL);
{
pcap_t *p;
- p = pcap_create_common(ebuf, sizeof (struct pcap_bpf));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_bpf);
if (p == NULL)
return (NULL);
/* OK, it's probably ours. */
*is_ours = 1;
- p = pcap_create_common(ebuf, sizeof (struct pcap_bt));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_bt);
if (p == NULL)
return (NULL);
#define BT_CONTROL_SIZE 32
#define INTERFACE_NAME "bluetooth-monitor"
+/*
+ * Private data.
+ * Currently contains nothing.
+ */
+struct pcap_bt_monitor {
+ int dummy;
+};
+
/*
* Fields and alignment must match the declaration in the Linux kernel 3.4+.
* See struct hci_mon_hdr in include/net/bluetooth/hci_mon.h.
}
*is_ours = 1;
- p = pcap_create_common(ebuf, 0);
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_bt_monitor);
if (p == NULL)
return NULL;
/* OK, it's probably ours. */
*is_ours = 1;
- p = pcap_create_common(ebuf, sizeof (struct pcap_dag));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_dag);
if (p == NULL)
return NULL;
}
*is_ours = 1;
- p = pcap_create_common(ebuf, sizeof (struct pcap_dbus));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_dbus);
if (p == NULL)
return (NULL);
struct pcap_dlpi *pd;
#endif
- p = pcap_create_common(ebuf, sizeof (struct pcap_dlpi));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_dlpi);
if (p == NULL)
return (NULL);
{
pcap_t *p;
- p = pcap_create_common(ebuf, sizeof (struct pcap_dos));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_dos);
if (p == NULL)
return (NULL);
if (! *is_ours)
return NULL;
//memset will happen
- p = pcap_create_common(ebuf, sizeof(struct pcap_dpdk));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_dpdk);
if (p == NULL)
return NULL;
return NULL;
}
- pcap_t* handle = pcap_create_common(errorBuffer,
- sizeof (struct pcap_haiku));
+ pcap_t* handle = PCAP_CREATE_COMMON(errorBuffer, struct pcap_haiku);
if (handle == NULL) {
snprintf(errorBuffer, PCAP_ERRBUF_SIZE, "malloc: %s", strerror(errno));
close(socket);
#ifndef pcap_int_h
#define pcap_int_h
+#include <stddef.h>
+
#include <signal.h>
#include <pcap/pcap.h>
* by pcap_create routines.
*/
pcap_t *pcap_create_interface(const char *, char *);
-pcap_t *pcap_create_common(char *, size_t);
+
+/*
+ * This wrapper takes an error buffer pointer and a type to use for the
+ * private data, and calls pcap_create_common(), passing it the error
+ * buffer pointer, the size fo the private data type, in bytes, and the
+ * offset of the private data from the beginning of the structure, in
+ * bytes.
+ */
+#define PCAP_CREATE_COMMON(ebuf, type) \
+ pcap_create_common(ebuf, \
+ sizeof (struct { pcap_t __common; type __private; }), \
+ offsetof (struct { pcap_t __common; type __private; }, __private))
+pcap_t *pcap_create_common(char *, size_t, size_t);
int pcap_do_addexit(pcap_t *);
void pcap_add_to_pcaps_to_close(pcap_t *);
void pcap_remove_from_pcaps_to_close(pcap_t *);
* treats the pathname as being in UTF-8, rather than the local
* code page, on Windows.
*/
-pcap_t *pcap_open_offline_common(char *ebuf, size_t size);
+
+/*
+ * This wrapper takes an error buffer pointer and a type to use for the
+ * private data, and calls pcap_create_common(), passing it the error
+ * buffer pointer, the size fo the private data type, in bytes, and the
+ * offset of the private data from the beginning of the structure, in
+ * bytes.
+ */
+#define PCAP_OPEN_OFFLINE_COMMON(ebuf, type) \
+ pcap_open_offline_common(ebuf, \
+ sizeof (struct { pcap_t __common; type __private; }), \
+ offsetof (struct { pcap_t __common; type __private; }, __private))
+pcap_t *pcap_open_offline_common(char *ebuf, size_t total_size,
+ size_t private_data);
bpf_u_int32 pcap_adjust_snapshot(bpf_u_int32 linktype, bpf_u_int32 snaplen);
void sf_cleanup(pcap_t *p);
#ifdef _WIN32
{
pcap_t *p;
- p = pcap_create_common(ebuf, sizeof (struct pcap_dlpi));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_dlpi);
if (p == NULL)
return (NULL);
{
pcap_t *handle;
- handle = pcap_create_common(ebuf, sizeof (struct pcap_linux));
+ handle = PCAP_CREATE_COMMON(ebuf, struct pcap_linux);
if (handle == NULL)
return NULL;
/* OK, it's probably ours. */
*is_ours = 1;
- p = pcap_create_common(ebuf, sizeof (struct pcap_netfilter));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_netfilter);
if (p == NULL)
return (NULL);
*is_ours = (!strncmp(device, "netmap:", 7) || !strncmp(device, "vale", 4));
if (! *is_ours)
return NULL;
- p = pcap_create_common(ebuf, sizeof (struct pcap_netmap));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_netmap);
if (p == NULL)
return (NULL);
p->activate_op = pcap_netmap_activate;
{
pcap_t *p;
- p = pcap_create_common(ebuf, sizeof (struct pcap_nit));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_nit);
if (p == NULL)
return (NULL);
{
pcap_t *p;
- p = pcap_create_common(ebuf, sizeof(struct pcap_win));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_win);
if (p == NULL)
return (NULL);
{
pcap_t *p;
- p = pcap_create_common(ebuf, sizeof (struct pcap_pf));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_pf);
if (p == NULL)
return (NULL);
!strncmp(device, dev_list[i]->name, namelen)) {
*is_ours = 1;
- p = pcap_create_common(ebuf, sizeof (struct pcap_rdmasniff));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_rdmasniff);
if (p) {
p->activate_op = rdmasniff_activate;
priv = p->priv;
struct rpcap_header header; /* header of the RPCAP packet */
struct rpcap_openreply openreply; /* open reply message */
- fp = pcap_create_common(errbuf, sizeof (struct pcap_rpcap));
+ fp = PCAP_CREATE_COMMON(errbuf, struct pcap_rpcap);
if (fp == NULL)
{
return NULL;
/* OK, it's probably ours. */
*is_ours = 1;
- p = pcap_create_common(ebuf, sizeof (struct pcap_septel));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_septel);
if (p == NULL)
return NULL;
int len; /* the current size of the inbound message */
} unit_t;
+/*
+ * Private data.
+ * Currently contains nothing.
+ */
+struct pcap_sita {
+ int dummy;
+};
+
static unit_t units[MAX_CHASSIS+1][MAX_GEOSLOT+1]; /* we use indexes of 1 through 8, but we reserve/waste index 0 */
static fd_set readfds; /* a place to store the file descriptors for the connections to the IOPs */
static int max_fs;
pcap_t *pcap_create_interface(const char *device _U_, char *ebuf) {
pcap_t *p;
- p = pcap_create_common(ebuf, 0);
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_sita);
if (p == NULL)
return (NULL);
/* OK, it's probably ours. */
*is_ours = 1;
- p = pcap_create_common(ebuf, sizeof (struct pcap_snf));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_snf);
if (p == NULL)
return NULL;
ps = p->priv;
{
pcap_t *p;
- p = pcap_create_common(ebuf, sizeof (struct pcap_snit));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_snit);
if (p == NULL)
return (NULL);
{
pcap_t *p;
- p = pcap_create_common(ebuf, sizeof (struct pcap_snoop));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_snoop);
if (p == NULL)
return (NULL);
/* OK, it's probably ours. */
*is_ours = 1;
- p = pcap_create_common(ebuf, sizeof (struct pcap_tc));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_tc);
if (p == NULL)
return NULL;
/* OK, it's probably ours. */
*is_ours = 1;
- p = pcap_create_common(ebuf, sizeof (struct pcap_usb_linux));
+ p = PCAP_CREATE_COMMON(ebuf, struct pcap_usb_linux);
if (p == NULL)
return (NULL);
}
static pcap_t *
-pcap_alloc_pcap_t(char *ebuf, size_t size)
+pcap_alloc_pcap_t(char *ebuf, size_t total_size, size_t private_offset)
{
char *chunk;
pcap_t *p;
/*
- * Allocate a chunk of memory big enough for a pcap_t
- * plus a structure following it of size "size". The
- * structure following it is a private data structure
- * for the routines that handle this pcap_t.
- *
- * The structure following it must be aligned on
- * the appropriate alignment boundary for this platform.
- * We align on an 8-byte boundary as that's probably what
- * at least some platforms do, even with 32-bit integers,
- * and because we can't be sure that some values won't
- * require 8-byte alignment even on platforms with 32-bit
- * integers.
+ * total_size is the size of a structure containing a pcap_t
+ * followed by a private structure.
*/
-#define PCAP_T_ALIGNED_SIZE ((sizeof(pcap_t) + 7U) & ~0x7U)
- chunk = calloc(PCAP_T_ALIGNED_SIZE + size, 1);
+ chunk = calloc(total_size, 1);
if (chunk == NULL) {
pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
errno, "malloc");
#endif /* MSDOS */
#endif /* _WIN32 */
- if (size == 0) {
- /* No private data was requested. */
- p->priv = NULL;
- } else {
- /*
- * Set the pointer to the private data; that's the structure
- * of size "size" following the pcap_t.
- */
- p->priv = (void *)(chunk + PCAP_T_ALIGNED_SIZE);
- }
+ /*
+ * private_offset is the offset, in bytes, of the private
+ * data from the beginning of the structure.
+ *
+ * Set the pointer to the private data; that's private_offset
+ * bytes past the pcap_t.
+ */
+ p->priv = (void *)(chunk + private_offset);
return (p);
}
pcap_t *
-pcap_create_common(char *ebuf, size_t size)
+pcap_create_common(char *ebuf, size_t total_size, size_t private_offset)
{
pcap_t *p;
- p = pcap_alloc_pcap_t(ebuf, size);
+ p = pcap_alloc_pcap_t(ebuf, total_size, private_offset);
if (p == NULL)
return (NULL);
}
pcap_t *
-pcap_open_offline_common(char *ebuf, size_t size)
+pcap_open_offline_common(char *ebuf, size_t total_size, size_t private_offset)
{
pcap_t *p;
- p = pcap_alloc_pcap_t(ebuf, size);
+ p = pcap_alloc_pcap_t(ebuf, total_size, private_offset);
if (p == NULL)
return (NULL);
* OK, this is a good pcap file.
* Allocate a pcap_t for it.
*/
- p = pcap_open_offline_common(errbuf, sizeof (struct pcap_sf));
+ p = PCAP_OPEN_OFFLINE_COMMON(errbuf, struct pcap_sf);
if (p == NULL) {
/* Allocation failed. */
*err = 1;
* OK, this is a good pcapng file.
* Allocate a pcap_t for it.
*/
- p = pcap_open_offline_common(errbuf, sizeof (struct pcap_ng_sf));
+ p = PCAP_OPEN_OFFLINE_COMMON(errbuf, struct pcap_ng_sf);
if (p == NULL) {
/* Allocation failed. */
*err = 1;