blob: 90feb6678ab720f1853f29f874f2fcbe214a800e [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
8#include "libmctp.h"
9
10#include <sys/types.h>
11
12#if HAVE_PCAP
13#include <pcap/pcap.h>
14#else
15typedef void pcap_t;
16typedef void pcap_dumper_t;
17#endif
18
19#define CAPTURE_LINKTYPE_FIRST 147
20#define CAPTURE_LINKTYPE_LAST 162
21
22#define __unused __attribute__((unused))
23
24struct capture {
25 const char *path;
26 int linktype;
27 pcap_t *pcap;
28 pcap_dumper_t *dumper;
29};
30
31#if HAVE_PCAP
32int capture_init(void);
33int capture_prepare(struct capture *cap);
34void capture_close(struct capture *cap);
35void capture_binding(struct mctp_pktbuf *pkt, void *user);
36void capture_socket(pcap_dumper_t *dumper, const void *buf, size_t len);
37#else
38#include <stdio.h>
39static inline int
40capture_init(void)
41{
42 fprintf(stderr, "libpcap support is disabled, cannot initialise libpcap\n");
43 return 0;
44}
45
46static inline int
47capture_prepare(struct capture *cap)
48{
49 fprintf(stderr, "libpcap support is disabled, cannot capture to %s\n",
50 cap->path);
51 return 0;
52}
53
54static inline void capture_close(struct capture *cap __unused)
55{
56}
57
58static inline void
59capture_binding(struct mctp_pktbuf *pkt __unused, void *user __unused)
60{
61}
62
63static inline void capture_socket(pcap_dumper_t *dumper __unused,
64 const void *buf __unused,
65 size_t len __unused)
66{
67}
68#endif
69#endif