2021-04-30 20:10:30 +01:00
|
|
|
#pragma once
|
2021-05-17 19:26:11 +01:00
|
|
|
|
2022-02-27 20:42:40 +00:00
|
|
|
#include "Tfe/NetworkBackend.h"
|
|
|
|
|
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
|
|
|
|
|
2021-05-17 19:48:33 +01:00
|
|
|
#ifdef U2_USE_SLIRP
|
2021-05-17 19:26:11 +01:00
|
|
|
|
2021-04-30 20:10:30 +01:00
|
|
|
#include <memory>
|
|
|
|
#include <vector>
|
|
|
|
#include <queue>
|
|
|
|
|
|
|
|
#include <poll.h>
|
|
|
|
|
|
|
|
struct Slirp;
|
|
|
|
|
2022-02-27 20:42:40 +00:00
|
|
|
class SlirpBackend : public NetworkBackend
|
2021-04-30 20:10:30 +01:00
|
|
|
{
|
|
|
|
public:
|
2022-02-27 20:42:40 +00:00
|
|
|
SlirpBackend();
|
|
|
|
|
|
|
|
void transmit(const int txlength, uint8_t *txframe) override;
|
|
|
|
int receive(const int size, uint8_t * rxframe) override;
|
|
|
|
|
|
|
|
void update(const ULONG nExecutedCycles) override;
|
|
|
|
bool isValid() override;
|
|
|
|
|
2021-04-30 20:10:30 +01:00
|
|
|
void sendToGuest(const uint8_t *pkt, int pkt_len);
|
|
|
|
|
|
|
|
int addPoll(const int fd, const int events);
|
|
|
|
int getREvents(const int idx) const;
|
|
|
|
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
|