Exemple #1
0
int main(int argc, char** argv){

    char buf[BUFLEN];
    char *dev = calloc(10, 1);

    struct netdev netdev;

    CLEAR(buf);

    tun_init(dev);
    netdev_init(&netdev, "10.0.0.4", "00:0c:29:6d:50:25");

    arp_init();

    while(1) {
        if (tun_read(buf, BUFLEN) < 0) {
            print_error("ERR: Read from tun_fd: %s\n", strerror(errno));
        }

        print_hexdump(buf, BUFLEN);

        struct eth_hdr *hdr = init_eth_hdr(buf);

        handle_frame(&netdev, hdr);
    }
}
Exemple #2
0
void *netdev_rx_loop()
{
    while (running) {
        if (tun_read(netdev.buf, netdev.buflen) < 0) {
            print_error("ERR: Read from tun_fd: %s\n", strerror(errno));
            return NULL;
        }

        struct eth_hdr *hdr = init_eth_hdr(netdev.buf);

        handle_frame(&netdev, hdr);
    }

    return NULL;
}