You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.8 KiB
55 lines
1.8 KiB
#ifndef TEST_VIRTUAL_TUN_H |
|
#define TEST_VIRTUAL_TUN_H |
|
|
|
#include <stdint.h> |
|
#include <stdbool.h> |
|
#include <stddef.h> |
|
#include <sys/types.h> |
|
|
|
#define VIRTUAL_TUN_MAX_PACKET_SIZE 65536 |
|
|
|
struct virtual_tun { |
|
int read_pipe[2]; // [0] = read end, [1] = write end |
|
int write_pipe[2]; // [0] = read end, [1] = write end |
|
char ifname[32]; // Virtual interface name |
|
bool enabled; |
|
void* test_context; // For callbacks |
|
|
|
// Statistics |
|
struct { |
|
size_t packets_sent; |
|
size_t packets_received; |
|
size_t bytes_sent; |
|
size_t bytes_received; |
|
} stats; |
|
}; |
|
|
|
// Create virtual TUN with bidirectional pipes |
|
struct virtual_tun* virtual_tun_create(const char* ifname); |
|
|
|
// Cleanup virtual TUN |
|
void virtual_tun_destroy(struct virtual_tun* vtun); |
|
|
|
// Get file descriptor for reading (simulates TUN device) |
|
int virtual_tun_get_read_fd(struct virtual_tun* vtun); |
|
|
|
// Get file descriptor for writing (simulates TUN device) |
|
int virtual_tun_get_write_fd(struct virtual_tun* vtun); |
|
|
|
// Inject packet into virtual TUN (simulates packet from network) |
|
int virtual_tun_inject_packet(struct virtual_tun* vtun, const uint8_t* packet, size_t len); |
|
|
|
// Read packet from virtual TUN (captures packets going to network) |
|
ssize_t virtual_tun_read_packet(struct virtual_tun* vtun, uint8_t* buffer, size_t max_len); |
|
|
|
// Write packet to virtual TUN (sends packet to network) |
|
ssize_t virtual_tun_write_packet(struct virtual_tun* vtun, const uint8_t* packet, size_t len); |
|
|
|
// Get virtual TUN statistics |
|
void virtual_tun_get_stats(struct virtual_tun* vtun, size_t* packets_sent, size_t* packets_received, |
|
size_t* bytes_sent, size_t* bytes_received); |
|
|
|
// Reset virtual TUN statistics |
|
void virtual_tun_reset_stats(struct virtual_tun* vtun); |
|
|
|
#endif // TEST_VIRTUAL_TUN_H
|