1 /* 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 #ifdef HAVE_CONFIG_H
7 #include "config.h"
8 #endif
9
10 #include "compiler.h"
11 #include "libmctp.h"
12
13 #include <sys/types.h>
14
15 #if HAVE_PCAP
16 #include <pcap/pcap.h>
17
18 #else
19 typedef void pcap_t;
20 typedef void pcap_dumper_t;
21 #endif
22
23 #define CAPTURE_LINKTYPE_LINUX_SLL2 276
24
25 struct capture {
26 const char *path;
27 pcap_t *pcap;
28 pcap_dumper_t *dumper;
29 };
30
31 #if HAVE_PCAP
32 int capture_init(void);
33 int capture_prepare(struct capture *cap);
34 void capture_close(struct capture *cap);
35 void capture_binding(struct mctp_pktbuf *pkt, bool outgoing, void *user);
36 void capture_socket(pcap_dumper_t *dumper, const void *buf, size_t len,
37 bool outgoing, int eid);
38 #else
39 #include <stdio.h>
capture_init(void)40 static inline int capture_init(void)
41 {
42 fprintf(stderr,
43 "libpcap support is disabled, cannot initialise libpcap\n");
44 return 0;
45 }
46
capture_prepare(struct capture * cap)47 static inline int capture_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
capture_close(struct capture * cap __unused)54 static inline void capture_close(struct capture *cap __unused)
55 {
56 }
57
capture_binding(struct mctp_pktbuf * pkt __unused,bool outgoing __unused,void * user __unused)58 static inline void capture_binding(struct mctp_pktbuf *pkt __unused,
59 bool outgoing __unused, void *user __unused)
60 {
61 }
62
capture_socket(pcap_dumper_t * dumper __unused,const void * buf __unused,size_t len __unused,bool outgoing __unused,int eid __unused)63 static inline void capture_socket(pcap_dumper_t *dumper __unused,
64 const void *buf __unused, size_t len __unused,
65 bool outgoing __unused, int eid __unused)
66 {
67 }
68 #endif
69 #endif
70