blob: e97d5471c0684c36e9c90f1152f924171d295c89 [file] [log] [blame]
Andrew Jefferycad47302021-08-20 21:37:57 +09301/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
2
3#ifndef _UTILS_MCTP_CAPTURE_H
4#define _UTILS_MCTP_CAPTURE_H
5
6#include "config.h"
7
Andrew Jeffery5ab78252022-02-17 21:04:59 +10308#include "compiler.h"
Andrew Jefferycad47302021-08-20 21:37:57 +09309#include "libmctp.h"
10
11#include <sys/types.h>
12
13#if HAVE_PCAP
14#include <pcap/pcap.h>
15#else
16typedef void pcap_t;
17typedef void pcap_dumper_t;
18#endif
19
20#define CAPTURE_LINKTYPE_FIRST 147
21#define CAPTURE_LINKTYPE_LAST 162
22
Andrew Jefferycad47302021-08-20 21:37:57 +093023struct capture {
24 const char *path;
25 int linktype;
26 pcap_t *pcap;
27 pcap_dumper_t *dumper;
28};
29
30#if HAVE_PCAP
31int capture_init(void);
32int capture_prepare(struct capture *cap);
33void capture_close(struct capture *cap);
34void capture_binding(struct mctp_pktbuf *pkt, void *user);
35void capture_socket(pcap_dumper_t *dumper, const void *buf, size_t len);
36#else
37#include <stdio.h>
38static inline int
39capture_init(void)
40{
41 fprintf(stderr, "libpcap support is disabled, cannot initialise libpcap\n");
42 return 0;
43}
44
45static inline int
46capture_prepare(struct capture *cap)
47{
48 fprintf(stderr, "libpcap support is disabled, cannot capture to %s\n",
49 cap->path);
50 return 0;
51}
52
53static inline void capture_close(struct capture *cap __unused)
54{
55}
56
57static inline void
58capture_binding(struct mctp_pktbuf *pkt __unused, void *user __unused)
59{
60}
61
62static inline void capture_socket(pcap_dumper_t *dumper __unused,
63 const void *buf __unused,
64 size_t len __unused)
65{
66}
67#endif
68#endif