Zig
Zig
SSH Tunnel Uncommon Options
See more SSH Tunnel Examples
Demonstrates the UncommonOptions property, which enables optional behavior for uncommon requirements. The default is an empty string; provide a comma-separated list of keywords to enable more than one option. Available keywords are listed in the reference documentation.
Background: This is a catch-all for narrow workarounds that do not warrant their own properties — forcing a specific signature algorithm, disabling the periodic keep-alive, removing weak MACs, bypassing a VPN on Android, and so on. Most applications never set it. When you do, it is usually to satisfy a particular server's quirk or a specific security requirement, and the exact keyword matters, so consult the documented list rather than guessing.
Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// Demonstrates the SshTunnel.UncommonOptions property, which enables optional behavior for
// uncommon requirements. The default is an empty string, appropriate for most applications.
// Provide a comma-separated list of keywords to enable more than one option.
const tunnel = try chilkat.SshTunnel.init();
defer tunnel.deinit();
// For example, disable the periodic keep-alive ignore message and remove weak MAC algorithms
// from those offered. Available keywords are listed in the reference documentation.
tunnel.setUncommonOptions("NoKeepAliveIgnoreMsg,no-weak-mac-algs");
tunnel.setDestHostname("db.internal.example.com");
tunnel.setDestPort(5432);
const ssh_port = 22;
tunnel.connect("ssh.example.com", ssh_port) catch {
std.debug.print("{s}\n", .{try tunnel.getLastErrorText(alloc)});
return;
};
// Normally you would not hard-code the password in source. You should instead obtain it
// from an interactive prompt, environment variable, or a secrets vault.
const password = "mySshPassword";
tunnel.authenticatePw("mySshLogin", password) catch {
std.debug.print("{s}\n", .{try tunnel.getLastErrorText(alloc)});
return;
};
const listen_port = 1080;
tunnel.beginAccepting(listen_port) catch {
std.debug.print("{s}\n", .{try tunnel.getLastErrorText(alloc)});
return;
};
std.debug.print("Tunnel established.\n", .{});
const wait_for_thread_exit = true;
tunnel.closeTunnel(wait_for_thread_exit) catch {
std.debug.print("{s}\n", .{try tunnel.getLastErrorText(alloc)});
return;
};
}