Giter Site home page Giter Site logo

bk138 / libsshtunnel Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 1.0 89 KB

Simple SSH tunnel library to let your networking app connect to a host running behind a SSH server.

License: BSD 3-Clause "New" or "Revised" License

CMake 5.25% C 94.75%
library ssh ssh-tunnel tunnel

libsshtunnel's Introduction

CI

About

libsshtunnel is a simple SSH tunnel library to let your networking app connect to a host running behind a SSH server.

Example Usage

#include <libsshtunnel.h>

// Callback that handles the SSH server's fingerprint.
// For the example, accepts any fingerprint, but normally
// you would check against saved ones etc.
int ssh_fingerprint_check(void *client,
                          const char *fingerprint,
                          int fingerprint_len,
                          const char *host) {
    return 0;
}

// No extended error checking here for the sake of API showoff.
int main () {
    // Init crypto backend, has to be called only once.
    ssh_tunnel_init();

    // Open a tunnel. This one uses password auth, there also is a variant using the private key.
    ssh_tunnel_t *t = ssh_tunnel_open_with_password("ssh.server.net",       // Hostname of SSH server
                                                    "username",             // SSH user name
                                                    "password",             // SSH user's password
                                                    "localhost",            // Remote service is running directly on SSH server
                                                     26000,                 // Port of remote service
                                                     NULL,                  // You can give an application pointer here that's handed to the callbacks.
                                                     ssh_fingerprint_check, // SSH fingerprint check callback
                                                     NULL);                 // Callback for error reporting, can be omitted
    if(t) {
        // Initial tunnel creation succeeded; you can now let your code connect
        // to the local end of the tunnel:
        // Your client will get connected to the server running on
        // "ssh.server.net", port 26000, as specified above.
        my_client_connect("localhost", ssh_tunnel_get_port(t));

       // Your other logic here...
    }

    // Closes the tunnel and frees memory.
    ssh_tunnel_close(t);

    return 0;
}

Building

libsshtunnel uses CMake, thus it's:

mkdir build
cd build
cmake ..
cmake --build .

License

libsshtunnel is licensed under the BSD 3-Clause License. See COPYING for more information.

libsshtunnel's People

Contributors

bk138 avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

webstorage119

libsshtunnel's Issues

Make it safe to call close from error callback

Right now, calling close from the error callback is explicitly forbidden in the docs because thrd_join() on self will not work.

It could be possible with the following scheme:

  • have a detached thread instead of joinable
  • close sets flag and signals condition variable, thread either terminates itself and waits for cond or is terminated by flag and then does not check cond

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.