How do I send and receive data through a TUN interface?
Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How do I send and receive data through a TUN interface?
Hi all,
I opened a TUN interface and used select to listen on that interface.
I have another program which opens a socket and writes data into
the socket continously. I want all the data written into the socket to
be read by the TUN interface.
As far as i know, the kernal puts the data into the TUN interface which
can be read by the user application.
What should I do to make the kernal pass all the data through the socket
to be written to the TUN interface?
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233
Rep:
i dont have too much experience with TUN interfaces except with automatically created ones by hamachi, however my guess would be that you would treat a tun interface as you would any other interface and simply configure whatever program you need to use that interface to bind to that interface instead of the physical interface or if you want ALL traffic through the TUN interface, set it as your default route instead of your physical interface, if that makes any sense
i'm guessing your interfaces would look something like
lo
-yadayadayada
eth0
-yadayadayada
tun0
-yadayadayada
?
edit: in short what i'm trying to say is if the interface exists, the kernel already IS capable of sending information through it, so it isn't a kernel issue you need to look at but rather a routing issue
Thanks Frieza, After opening the TUN interface, the program is
blocking on the select call. When I did an ifconfig, i get the
following for TUN interface:
tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
UP POINTOPOINT RUNNING NOARP MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:500
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
Is it possible to route packets only from certain applications
to be passed onto the TUN interface?
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233
Rep:
again i can't provide details since i havnt really needed to use this information but
i would look into iptables and ipchains, depending on what programs you are using you might be able to route certain traffic to the appropriate information based on port number,regardless, iptables/ipchains are useful programs that are used to configure how your computer routes network traffic
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.