ucode: check for errors in ftruncate()
[project/udebug.git] / udebug-pcap.h
1 #ifndef __UDEBUG_PCAP_H
2 #define __UDEBUG_PCAP_H
3
4 #include <libubox/blobmsg.h>
5 #include <libubox/udebug.h>
6
7 struct pcap_context {
8 uint32_t iface_id;
9 void *buf;
10 };
11
12 struct pcap_meta {
13 const char *hw, *os, *app;
14 };
15
16 struct pcap_interface_meta {
17 const char *name;
18 const char *description;
19 uint8_t time_res;
20 uint16_t link_type;
21 };
22
23 struct pcap_dbus_meta {
24 const char *path, *interface, *name;
25 const char *src, *dest;
26 };
27
28 int pcap_init(struct pcap_context *p, struct pcap_meta *meta);
29 int pcap_interface_init(struct pcap_context *p, uint32_t *id,
30 struct pcap_interface_meta *meta);
31 static inline bool
32 pcap_interface_is_valid(struct pcap_context *p, uint32_t idx)
33 {
34 return idx <= p->iface_id;
35 }
36
37 void pcap_packet_init(uint32_t iface, uint64_t timestamp);
38 void pcap_dbus_init_string(const struct udebug_packet_info *meta, const char *val);
39 void pcap_dbus_init_blob(const struct udebug_packet_info *meta, struct blob_attr *val, bool dict);
40 void *pcap_packet_append(const void *data, size_t len);
41 void pcap_packet_done(void);
42
43 int pcap_interface_rbuf_init(struct pcap_context *p, struct udebug_remote_buf *rb);
44 int pcap_snapshot_packet_init(struct udebug *ctx, struct udebug_iter *it);
45
46 void pcap_block_write_file(FILE *f);
47 void *pcap_block_get(size_t *len);
48
49 #endif