Skip to content

Commit 5cade0d

Browse files
committed
libtailscale: make header compatible with c++
1 parent b0e2f4a commit 5cade0d

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

tailscale.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ int tailscale_set_logfd(tailscale sd, int fd) {
8989
return TsnetSetLogFD(sd, fd);
9090
}
9191

92-
int tailscale_loopback(tailscale sd, char* addr_out, size_t addrlen, char proxy_cred_out[static 33], char local_api_cred_out[static 33]) {
92+
int tailscale_loopback(tailscale sd, char* addr_out, size_t addrlen, char* proxy_cred_out, char* local_api_cred_out) {
9393
return TsnetLoopback(sd, addr_out, addrlen, proxy_cred_out, local_api_cred_out);
9494
}
9595

tailscale.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,10 @@ func TsnetLoopback(sd C.int, addrOut *C.char, addrLen C.size_t, proxyOut *C.char
403403
panic("loopback_api passed nil addr_out")
404404
} else if addrLen == 0 {
405405
panic("loopback_api passed addrlen of 0")
406+
} else if proxyOut == nil {
407+
panic("loopback_api passed nil proxy_cred_out")
408+
} else if localOut == nil {
409+
panic("loopback_api passed nil local_api_cred_out")
406410
}
407411

408412
// Start out NUL-termianted to cover error conditions.

tailscale.h

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414

1515
#include <stddef.h>
1616

17+
#ifndef TAILSCALE_H
18+
#define TAILSCALE_H
19+
20+
#ifdef __cplusplus
21+
extern "C" {
22+
#endif
23+
24+
1725
// tailscale is a handle onto a Tailscale server.
1826
typedef int tailscale;
1927

@@ -133,8 +141,15 @@ extern int tailscale_accept(tailscale_listener listener, tailscale_conn* conn_ou
133141
// "Sec-Tailscale: localapi" HTTP header and passing local_api_cred as
134142
// the basic auth password.
135143
//
144+
// The pointers proxy_cred_out and local_api_cred_out must be non-NIL
145+
// and point to arrays that can hold 33 bytes. The first 32 bytes are
146+
// the credential and the final byte is a NUL terminator.
147+
//
148+
// If tailscale_loopback returns, then addr_our, proxy_cred_out,
149+
// and local_api_cred_out are all NUL-terminated.
150+
//
136151
// Returns zero on success or -1 on error, call tailscale_errmsg for details.
137-
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]);
152+
extern int tailscale_loopback(tailscale sd, char* addr_out, size_t addrlen, char* proxy_cred_out, char* local_api_cred_out);
138153

139154
// tailscale_errmsg writes the details of the last error to buf.
140155
//
@@ -145,3 +160,10 @@ extern int tailscale_loopback(tailscale sd, char* addr_out, size_t addrlen, char
145160
// EBADF - sd is not a valid tailscale
146161
// ERANGE - insufficient storage for buf
147162
extern int tailscale_errmsg(tailscale sd, char* buf, size_t buflen);
163+
164+
165+
#ifdef __cplusplus
166+
}
167+
#endif
168+
169+
#endif

0 commit comments

Comments
 (0)