Andrew Jeffery | cad4730 | 2021-08-20 21:37:57 +0930 | [diff] [blame] | 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 | #include "config.h" |
| 7 | |
Andrew Jeffery | 5ab7825 | 2022-02-17 21:04:59 +1030 | [diff] [blame] | 8 | #include "compiler.h" |
Andrew Jeffery | cad4730 | 2021-08-20 21:37:57 +0930 | [diff] [blame] | 9 | #include "libmctp.h" |
| 10 | |
| 11 | #include <sys/types.h> |
| 12 | |
| 13 | #if HAVE_PCAP |
| 14 | #include <pcap/pcap.h> |
| 15 | #else |
| 16 | typedef void pcap_t; |
| 17 | typedef void pcap_dumper_t; |
| 18 | #endif |
| 19 | |
| 20 | #define CAPTURE_LINKTYPE_FIRST 147 |
| 21 | #define CAPTURE_LINKTYPE_LAST 162 |
| 22 | |
Andrew Jeffery | cad4730 | 2021-08-20 21:37:57 +0930 | [diff] [blame] | 23 | struct capture { |
| 24 | const char *path; |
| 25 | int linktype; |
| 26 | pcap_t *pcap; |
| 27 | pcap_dumper_t *dumper; |
| 28 | }; |
| 29 | |
| 30 | #if HAVE_PCAP |
| 31 | int capture_init(void); |
| 32 | int capture_prepare(struct capture *cap); |
| 33 | void capture_close(struct capture *cap); |
| 34 | void capture_binding(struct mctp_pktbuf *pkt, void *user); |
| 35 | void capture_socket(pcap_dumper_t *dumper, const void *buf, size_t len); |
| 36 | #else |
| 37 | #include <stdio.h> |
| 38 | static inline int |
| 39 | capture_init(void) |
| 40 | { |
| 41 | fprintf(stderr, "libpcap support is disabled, cannot initialise libpcap\n"); |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | static inline int |
| 46 | capture_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 | |
| 53 | static inline void capture_close(struct capture *cap __unused) |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | static inline void |
| 58 | capture_binding(struct mctp_pktbuf *pkt __unused, void *user __unused) |
| 59 | { |
| 60 | } |
| 61 | |
| 62 | static 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 |