The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
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  */
25 RCSIDH(pcap_h, "$Id: a6333f5f7983f2b88bfe05812748c14601feff75 $")
26 
27 #ifdef __cplusplus
28 extern "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 <stdbool.h>
39 #include <sys/types.h>
40 
41 #define SNAPLEN ETHER_HDR_LEN + IP_HDR_LEN + sizeof(udp_header_t) + MAX_RADIUS_LEN
42 #define PCAP_BUFFER_DEFAULT (10000)
43 /*
44  * It's unclear why this differs between platforms
45  */
46 #ifndef __linux__
47 # define PCAP_NONBLOCK_TIMEOUT (0)
48 #else
49 # define PCAP_NONBLOCK_TIMEOUT (-1)
50 #endif
51 
52 #ifndef BIOCIMMEDIATE
53 # define BIOCIMMEDIATE (2147762800)
54 #endif
55 
56 /*
57  * Older versions of libpcap don't define this
58  */
59 #ifndef PCAP_NETMASK_UNKNOWN
60 # define PCAP_NETMASK_UNKNOWN 0
61 #endif
62 
63 typedef enum {
64  PCAP_INVALID = 0,
65  PCAP_INTERFACE_IN,
66  PCAP_FILE_IN,
67  PCAP_STDIO_IN,
68  PCAP_INTERFACE_OUT,
69  PCAP_FILE_OUT,
70  PCAP_STDIO_OUT,
71  PCAP_INTERFACE_IN_OUT
72 } fr_pcap_type_t;
73 
74 /*
75  * Internal pcap structures
76  */
77 typedef struct fr_pcap fr_pcap_t;
78 struct fr_pcap {
79  char errbuf[PCAP_ERRBUF_SIZE]; //!< Last error on this interface.
80  fr_pcap_type_t type; //!< What type of handle this is.
81  char *name; //!< Name of file or interface.
82  uint8_t ether_addr[ETHER_ADDR_LEN]; //!< The MAC address of the interface
83  int ifindex; //!< ifindex of the name we're listening on.
84 
85  bool promiscuous; //!< Whether the interface is in promiscuous mode.
86  //!< Only valid for live capture handles.
87  int buffer_pkts; //!< How big to make the PCAP ring buffer.
88  //!< Actual buffer size is SNAPLEN * buffer.
89  //!< Only valid for live capture handles.
90 
91  pcap_t *handle; //!< libpcap handle.
92  pcap_dumper_t *dumper; //!< libpcap dumper handle.
93 
94  int link_layer; //!< Link layer type.
95 
96  int fd; //!< Selectable file descriptor we feed to select.
97  struct pcap_stat pstats; //!< The last set of pcap stats for this handle.
98 
99  fr_pcap_t *next; //!< Next handle in collection.
100 };
101 
102 int fr_pcap_if_link_layer(pcap_if_t *dev);
103 fr_pcap_t *fr_pcap_init(TALLOC_CTX *ctx, char const *name, fr_pcap_type_t type);
104 int fr_pcap_open(fr_pcap_t *handle);
105 int fr_pcap_apply_filter(fr_pcap_t *handle, char const *expression);
106 char *fr_pcap_device_names(TALLOC_CTX *ctx, fr_pcap_t *handle, char c);
107 int fr_pcap_mac_addr(uint8_t *macaddr, char *ifname);
108 bool fr_pcap_link_layer_supported(int link_layer);
109 ssize_t fr_pcap_link_layer_offset(uint8_t const *data, size_t len, int link_layer);
110 #endif
111 
112 #ifdef __cplusplus
113 }
114 #endif
#define RCSIDH(h, id)
Definition: build.h:482
next
Definition: dcursor.h:178
long int ssize_t
Definition: merged_model.c:24
unsigned char uint8_t
Definition: merged_model.c:30
#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:1265