LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 01-11-2007, 12:59 AM   #1
Peter John
LQ Newbie
 
Registered: Jan 2007
Posts: 29

Rep: Reputation: 15
Problems to bring up a TUN interface


ifconfig tun0 10.0.0.1 255.255.255.0 up
gives error saying

SIOIFADDR tun0 no such device
I have installed the latest RPM.

Peter
 
Old 01-11-2007, 03:24 AM   #2
Peter John
LQ Newbie
 
Registered: Jan 2007
Posts: 29

Original Poster
Rep: Reputation: 15
I have installed an new RPM.. i still face the same problem

[root@localhost root]# modprobe tun
[root@localhost root]# lsmod | grep tun
tun 5696 0 (unused)
[root@localhost root]# ifconfig tun0 10.0.0.1 netmask 255.255.255.0 up
SIOCSIFADDR: No such device
tun0: unknown interface: No such device
SIOCSIFNETMASK: No such device
tun0: unknown interface: No such device
[root@localhost root]# uname -r
2.4.20-8
[root@localhost root]#
 
Old 01-11-2007, 03:51 AM   #3
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
I checked documentation in kernel source, copied an example code and added includes to compile (frankly, I also changed error handling to compile, but it is not so interesting). While the program runs (after it has issued ioctl), tun0 exists. So if you want a program to use tun, this program should call tun_alloc before configuring tun0 interface. This way it will already have its pipe end to get data and tun0 created.

Code:
#include <stdio.h>
#include <sys/ioctl.h>
#include <linux/if.h>
#include <linux/if_tun.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>

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

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

    memset(&ifr, 0, sizeof(ifr));

    /* Flags: IFF_TUN   - TUN device (no Ethernet headers) 
     *        IFF_TAP   - TAP device  
     *
     *        IFF_NO_PI - Do not provide packet information  
     */ 
    ifr.ifr_flags = IFF_TUN; 
    if( *dev )
       strncpy(ifr.ifr_name, dev, IFNAMSIZ);

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

int main()
{
        char ifname[] = "tun0";
        char s[1024];

        tun_alloc(ifname);
        printf("%s\n",ifname);
        scanf("%s",s);
}
 
Old 01-11-2007, 04:10 AM   #4
Peter John
LQ Newbie
 
Registered: Jan 2007
Posts: 29

Original Poster
Rep: Reputation: 15
Am getting compiling errors as
[root@localhost peter]# gcc mytun.c -o tun
In file included from mytun.c:3:
/usr/include/linux/if.h:86: field `ifru_addr' has incomplete type
/usr/include/linux/if.h:87: field `ifru_dstaddr' has incomplete type
/usr/include/linux/if.h:88: field `ifru_broadaddr' has incomplete type
/usr/include/linux/if.h:89: field `ifru_netmask' has incomplete type
/usr/include/linux/if.h:90: field `ifru_hwaddr' has incomplete type
[root@localhost peter]#
 
Old 01-11-2007, 04:21 AM   #5
raskin
Senior Member
 
Registered: Sep 2005
Location: France
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900

Rep: Reputation: 69
Am I right that just that:
Code:
#include <linux/if.h>
int main(){return 0;}
causes an error? And what does
Code:
rpm -qf /usr/include/linux/if.h
say?
 
Old 01-11-2007, 04:41 AM   #6
Peter John
LQ Newbie
 
Registered: Jan 2007
Posts: 29

Original Poster
Rep: Reputation: 15
Got it fixed
 
Old 03-29-2010, 01:55 PM   #7
shayamm.aley
LQ Newbie
 
Registered: Mar 2010
Posts: 1

Rep: Reputation: 0
Facing Same Problem

Hi Peter I am facing same problem how did you fix it?

/usr/include/linux/if.h:165: error: field 'ifru_addr' has incomplete type
/usr/include/linux/if.h:166: error: field 'ifru_dstaddr' has incomplete type
/usr/include/linux/if.h:167: error: field 'ifru_broadaddr' has incomplete type
/usr/include/linux/if.h:168: error: field 'ifru_netmask' has incomplete type
/usr/include/linux/if.h:169: error: field 'ifru_hwaddr' has incomplete type
Hello.c:48:2: warning: no newline at end of file


thanks in advance.
 
Old 08-25-2010, 10:30 AM   #8
mlang
LQ Newbie
 
Registered: Aug 2010
Posts: 1

Rep: Reputation: 0
I fixed it by adding...
#include <sys/socket.h>
before
#include <linux/if_tun.h>
#include <linux/if.h>
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
TUN Interface Peter John Linux - Networking 1 01-09-2007 08:18 PM
Bring up one interface at boot darkarcon2015 Fedora 6 12-17-2006 12:23 AM
What does ifup do to bring up an interface? crazyjimbo Linux - Networking 1 07-04-2006 01:00 AM
tun interface does not exist in slackware 10.1 with kernel 2.6.11.10 antken Linux - Networking 1 05-29-2005 09:10 PM
pppd: how to bring up an interface? J_Szucs Linux - Networking 2 08-08-2004 08:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 10:04 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration