The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
pcap.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17#ifdef HAVE_LIBPCAP
18/** Prototypes and constants for PCAP functions
19 *
20 * @file src/lib/util/pcap.h
21 *
22 * @author Arran Cudbard-Bell (a.cudbardb@freeradius.org)
23 * @copyright 2013 Arran Cudbard-Bell (a.cudbardb@freeradius.org)
24 */
25RCSIDH(pcap_h, "$Id: e1fff8508561da438a5f3447a6158f7004d0f5a3 $")
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31#include "pcap.h"
32
33#include <freeradius-devel/build.h>
34#include <freeradius-devel/missing.h>
35#include <freeradius-devel/util/net.h>
36
37#include <pcap.h>
38#include <sys/types.h>
39
40#define SNAPLEN ETHER_HDR_LEN + IP_HDR_LEN + sizeof(udp_header_t) + MAX_RADIUS_LEN
41#define PCAP_BUFFER_DEFAULT (10000)
42/*
43 * It's unclear why this differs between platforms
44 */
45#ifndef __linux__
46# define PCAP_NONBLOCK_TIMEOUT (0)
47#else
48# define PCAP_NONBLOCK_TIMEOUT (-1)
49#endif
50
51#ifndef BIOCIMMEDIATE
52# define BIOCIMMEDIATE (2147762800)
53#endif
54
55/*
56 * Older versions of libpcap don't define this
57 */
58#ifndef PCAP_NETMASK_UNKNOWN
59# define PCAP_NETMASK_UNKNOWN 0
60#endif
61
62typedef enum {
63 PCAP_INVALID = 0,
64 PCAP_INTERFACE_IN,
65 PCAP_FILE_IN,
66 PCAP_STDIO_IN,
67 PCAP_INTERFACE_OUT,
68 PCAP_FILE_OUT,
69 PCAP_STDIO_OUT,
70 PCAP_INTERFACE_IN_OUT
71} fr_pcap_type_t;
72
73/*
74 * Internal pcap structures
75 */
76typedef struct fr_pcap fr_pcap_t;
77struct fr_pcap {
78 char errbuf[PCAP_ERRBUF_SIZE]; //!< Last error on this interface.
79 fr_pcap_type_t type; //!< What type of handle this is.
80 char *name; //!< Name of file or interface.
81 uint8_t ether_addr[ETHER_ADDR_LEN]; //!< The MAC address of the interface
82 int ifindex; //!< ifindex of the name we're listening on.
83
84 bool promiscuous; //!< Whether the interface is in promiscuous mode.
85 //!< Only valid for live capture handles.
86 int buffer_pkts; //!< How big to make the PCAP ring buffer.
87 //!< Actual buffer size is SNAPLEN * buffer.
88 //!< Only valid for live capture handles.
89
90 pcap_t *handle; //!< libpcap handle.
91 pcap_dumper_t *dumper; //!< libpcap dumper handle.
92
93 int link_layer; //!< Link layer type.
94
95 int fd; //!< Selectable file descriptor we feed to select.
96 struct pcap_stat pstats; //!< The last set of pcap stats for this handle.
97
98 fr_pcap_t *next; //!< Next handle in collection.
99};
100
101int fr_pcap_if_link_layer(pcap_if_t *dev);
102fr_pcap_t *fr_pcap_init(TALLOC_CTX *ctx, char const *name, fr_pcap_type_t type);
103int fr_pcap_open(fr_pcap_t *handle);
104int fr_pcap_apply_filter(fr_pcap_t *handle, char const *expression);
105char *fr_pcap_device_names(TALLOC_CTX *ctx, fr_pcap_t *handle, char c);
106int fr_pcap_mac_addr(uint8_t *macaddr, char *ifname);
107bool fr_pcap_link_layer_supported(int link_layer);
108ssize_t fr_pcap_link_layer_offset(uint8_t const *data, size_t len, int link_layer);
109#endif
110
111#ifdef __cplusplus
112}
113#endif
#define RCSIDH(h, id)
Definition build.h:507
long int ssize_t
unsigned char uint8_t
#define ETHER_ADDR_LEN
Definition net.h:64
static char const * name
fr_aka_sim_id_type_t type
static fr_slen_t data
Definition value.h:1340