/* SPDX-License-Identifier: GPL-3.0-only */
#include "n2n.h"

#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>

int tuntap_open(
    tuntap_dev *device,
    char *dev,
    uint8_t address_mode,
    struct n2n_ip_subnet v4subnet,
    const char *device_mac,
    int mtu,
    int metric) {
    (void)address_mode;
    (void)metric;
    if (!device) return -1;
    if (dev) snprintf(device->dev_name, sizeof(device->dev_name), "%s", dev);
    device->ip_addr = v4subnet.net_addr;
    device->mtu = (uint16_t)mtu;
    if (device_mac && device_mac[0]) str2mac(device->mac_addr, device_mac);
    return device->fd;
}

int tuntap_read(tuntap_dev *tuntap, unsigned char *buf, int len) {
    return tuntap && tuntap->fd >= 0 ? (int)read(tuntap->fd, buf, (size_t)len) : -1;
}

int tuntap_write(tuntap_dev *tuntap, unsigned char *buf, int len) {
    return tuntap && tuntap->fd >= 0 ? (int)write(tuntap->fd, buf, (size_t)len) : -1;
}

void tuntap_close(tuntap_dev *tuntap) {
    (void)tuntap;
}

void tuntap_get_address(tuntap_dev *tuntap) {
    (void)tuntap;
}

