libtailscale: make header compatible with c++

This commit is contained in:
David Crawshaw
2023-03-18 17:18:36 -07:00
committed by David Crawshaw
parent b0e2f4a4e4
commit 5cade0d40d
3 changed files with 28 additions and 2 deletions
+1 -1
View File
@@ -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);
}
+4
View File
@@ -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.
+23 -1
View File
@@ -14,6 +14,14 @@
#include <stddef.h>
#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