Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples in readme #2

Open
maq123 opened this issue May 5, 2016 · 1 comment
Open

Examples in readme #2

maq123 opened this issue May 5, 2016 · 1 comment

Comments

@maq123
Copy link

maq123 commented May 5, 2016

Hi,

trying to use this module, but apparently I suck at nodejs and I can't create working tun tunnel.
Could you please add some more code snippets with the example usage?

Thx.

@Dagrut
Copy link
Contributor

Dagrut commented May 6, 2016

Hi,

I don't have two computers close to hands for now, so I can't test this code, but that should work. On both side, you should have something like :

var tuntap = require('./index.js');

try {
    var tt = tuntap({
        type: 'tun',
        name: 'tun1',
        mtu: 1500,
        addr: '192.168.123.1',
        dest: '192.168.123.2',
        mask: '255.255.255.192',
        ethtype_comp: 'half',
        persist: false,
        up: true,
        running: true,
    });
}
catch(e) {
    console.log('Tuntap creation error: ', e);
    process.exit(0);
}

On the server side, it should be followed by :

var srv = net.createServer({}, function(c) {
    console.log('server connected');

    if(tt) {
        var muxer = tuntap.muxer(1500);
        var demuxer = tuntap.demuxer(1500);
        tt
            .pipe(muxer)
            .pipe(c)
            .pipe(demuxer)
            .pipe(tt);
    }
});
var server = srv.listen(8124, function() {});

And on the client side :

var c = net.connect({host: '192.168.1.42', port: 8124}, function() {
    console.log('client connected');

    if(tt) {
        var muxer = tuntap.muxer(1500);
        var demuxer = tuntap.demuxer(1500);
        tt
            .pipe(muxer)
            .pipe(c)
            .pipe(demuxer)
            .pipe(tt);
    }
});

Of course you should adapt IP addresses & ports to your configuration :-) .
You should also have the proper routes set to have informations sent using the tunnel interfaces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants