2021-04-30 20:10:30 +01:00
|
|
|
#pragma once
|
2021-05-17 19:26:11 +01:00
|
|
|
|
|
|
|
#include "linux/config.h"
|
|
|
|
|
|
|
|
#ifdef SLIRP_FOUND
|
|
|
|
// disable to use libpcap in all cases
|
|
|
|
#define U2_USE_SLIRP
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef U2_SLIRP_FOUND
|
|
|
|
|
2021-04-30 20:10:30 +01:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
#include <queue>
|
|
|
|
|
|
|
|
#include <poll.h>
|
|
|
|
|
|
|
|
struct Slirp;
|
|
|
|
|
|
|
|
class SlirpNet
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
SlirpNet();
|
|
|
|
void sendFromGuest(const uint8_t *pkt, int pkt_len);
|
|
|
|
void sendToGuest(const uint8_t *pkt, int pkt_len);
|
|
|
|
|
|
|
|
void process(const uint32_t timeout);
|
|
|
|
int addPoll(const int fd, const int events);
|
|
|
|
int getREvents(const int idx) const;
|
|
|
|
|
|
|
|
std::queue<std::vector<uint8_t>> & getQueue();
|
2021-05-05 15:02:42 +01:00
|
|
|
void clearQueue();
|
2021-04-30 20:10:30 +01:00
|
|
|
private:
|
2021-05-09 19:49:18 +01:00
|
|
|
|
|
|
|
static constexpr size_t ourQueueSize = 10;
|
|
|
|
|
2021-04-30 20:10:30 +01:00
|
|
|
std::shared_ptr<Slirp> mySlirp;
|
|
|
|
std::vector<pollfd> myFDs;
|
|
|
|
|
|
|
|
std::queue<std::vector<uint8_t>> myQueue;
|
|
|
|
};
|
2021-05-17 19:26:11 +01:00
|
|
|
|
|
|
|
#endif
|