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 | |
| 8 | #include "libmctp.h" |
| 9 | |
| 10 | #include <sys/types.h> |
| 11 | |
| 12 | #if HAVE_PCAP |
| 13 | #include <pcap/pcap.h> |
| 14 | #else |
| 15 | typedef void pcap_t; |
| 16 | typedef 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 | |
| 24 | struct capture { |
| 25 | const char *path; |
| 26 | int linktype; |
| 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, void *user); |
| 36 | void capture_socket(pcap_dumper_t *dumper, const void *buf, size_t len); |
| 37 | #else |
| 38 | #include <stdio.h> |
| 39 | static inline int |
| 40 | capture_init(void) |
| 41 | { |
| 42 | fprintf(stderr, "libpcap support is disabled, cannot initialise libpcap\n"); |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | static inline int |
| 47 | 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 | |
| 54 | static inline void capture_close(struct capture *cap __unused) |
| 55 | { |
| 56 | } |
| 57 | |
| 58 | static inline void |
| 59 | capture_binding(struct mctp_pktbuf *pkt __unused, void *user __unused) |
| 60 | { |
| 61 | } |
| 62 | |
| 63 | static 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 |