• [^] # Re: Compilation des modules ?

    Posté par . En réponse au message Problème avec le Module tun. Évalué à 2.

    Tu peux essayer le programme suivant ? (ps: je suis désolé pour la longueur du post, j'espère que ça ne gênera personne).

    Normalement il doit t'allouer un device "tun". Je l'ai fait à l'arrache mais ça devrait marcher.



    #include <unistd.h>
    #include <fcntl.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <syslog.h>
    #include <sys/ioctl.h>
    #include <errno.h>

    #include <sys/socket.h>
    #include <linux/if.h>
    #include <linux/if_tun.h>

    int tun_open(char *dev)
    {
    struct ifreq ifr;
    int fd, err;

    printf("Requesting new TUN device...\n");

    if ((fd = open("/dev/net/tun", O_RDWR)) < 0) {
    perror("open");
    return(-1);
    }

    memset(&ifr, 0, sizeof(ifr));
    ifr.ifr_flags = IFF_TUN | IFF_NO_PI;

    if ((err = ioctl(fd, TUNSETIFF, (void *)&ifr)) < 0) {
    close(fd);
    return(err);
    }

    strcpy(dev, ifr.ifr_name);
    return fd;
    }

    int main(void)
    {
    char dev[256];
    int fd;

    *dev = 0;

    if ((fd = tun_open(dev)) == -1) {
    fprintf(stderr,"Unable to obtain tunnel interface.\n");
    return(-1);
    }

    printf("Tunnel device : %s\n",dev);
    sleep(15);

    close(fd);
    return(0);
    }