From 5cade0d40dec4a24bbc79b4a352032a4e06b10d1 Mon Sep 17 00:00:00 2001 From: David Crawshaw Date: Sat, 18 Mar 2023 17:18:36 -0700 Subject: [PATCH] libtailscale: make header compatible with c++ --- tailscale.c | 2 +- tailscale.go | 4 ++++ tailscale.h | 24 +++++++++++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/tailscale.c b/tailscale.c index eb4a1e6..7a39f50 100644 --- a/tailscale.c +++ b/tailscale.c @@ -89,7 +89,7 @@ int tailscale_set_logfd(tailscale sd, int fd) { return TsnetSetLogFD(sd, fd); } -int tailscale_loopback(tailscale sd, char* addr_out, size_t addrlen, char proxy_cred_out[static 33], char local_api_cred_out[static 33]) { +int tailscale_loopback(tailscale sd, char* addr_out, size_t addrlen, char* proxy_cred_out, char* local_api_cred_out) { return TsnetLoopback(sd, addr_out, addrlen, proxy_cred_out, local_api_cred_out); } diff --git a/tailscale.go b/tailscale.go index a8f35c9..7087ed0 100644 --- a/tailscale.go +++ b/tailscale.go @@ -403,6 +403,10 @@ func TsnetLoopback(sd C.int, addrOut *C.char, addrLen C.size_t, proxyOut *C.char panic("loopback_api passed nil addr_out") } else if addrLen == 0 { panic("loopback_api passed addrlen of 0") + } else if proxyOut == nil { + panic("loopback_api passed nil proxy_cred_out") + } else if localOut == nil { + panic("loopback_api passed nil local_api_cred_out") } // Start out NUL-termianted to cover error conditions. diff --git a/tailscale.h b/tailscale.h index 958ef67..8265698 100644 --- a/tailscale.h +++ b/tailscale.h @@ -14,6 +14,14 @@ #include +#ifndef TAILSCALE_H +#define TAILSCALE_H + +#ifdef __cplusplus +extern "C" { +#endif + + // tailscale is a handle onto a Tailscale server. typedef int tailscale; @@ -133,8 +141,15 @@ extern int tailscale_accept(tailscale_listener listener, tailscale_conn* conn_ou // "Sec-Tailscale: localapi" HTTP header and passing local_api_cred as // the basic auth password. // +// The pointers proxy_cred_out and local_api_cred_out must be non-NIL +// and point to arrays that can hold 33 bytes. The first 32 bytes are +// the credential and the final byte is a NUL terminator. +// +// If tailscale_loopback returns, then addr_our, proxy_cred_out, +// and local_api_cred_out are all NUL-terminated. +// // Returns zero on success or -1 on error, call tailscale_errmsg for details. -extern int tailscale_loopback(tailscale sd, char* addr_out, size_t addrlen, char proxy_cred_out[static 33], char local_api_cred_out[static 33]); +extern int tailscale_loopback(tailscale sd, char* addr_out, size_t addrlen, char* proxy_cred_out, char* local_api_cred_out); // tailscale_errmsg writes the details of the last error to buf. // @@ -145,3 +160,10 @@ extern int tailscale_loopback(tailscale sd, char* addr_out, size_t addrlen, char // EBADF - sd is not a valid tailscale // ERANGE - insufficient storage for buf extern int tailscale_errmsg(tailscale sd, char* buf, size_t buflen); + + +#ifdef __cplusplus +} +#endif + +#endif