Retourner au contenu associé (entrée de forum : Problème avec le Module tun)
Posté par galactikboulay le 01 avril 2005 à 14:04. En réponse au message Problème avec le Module tun. Évalué à 2.
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
[^] # Re: Compilation des modules ?
Posté par galactikboulay . En réponse au message Problème avec le Module tun. Évalué à 2.
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);
}