diff --git a/wireguard-go-bridge/api-ios.go b/wireguard-go-bridge/api-ios.go index d6eccd8..0f80384 100644 --- a/wireguard-go-bridge/api-ios.go +++ b/wireguard-go-bridge/api-ios.go @@ -7,9 +7,9 @@ package main // #include // #include -// static void callLogger(void *func, int level, const char *msg) +// static void callLogger(void *func, void *ctx, int level, const char *msg) // { -// ((void(*)(int, const char *))func)(level, msg); +// ((void(*)(void *, int, const char *))func)(ctx, level, msg); // } import "C" @@ -30,6 +30,7 @@ import ( ) var loggerFunc unsafe.Pointer +var loggerCtx unsafe.Pointer var versionString *C.char type CLogger struct { @@ -41,7 +42,7 @@ func (l *CLogger) Write(p []byte) (int, error) { return 0, errors.New("No logger initialized") } message := C.CString(string(p)) - C.callLogger(loggerFunc, l.level, message) + C.callLogger(loggerFunc, loggerCtx, l.level, message) C.free(unsafe.Pointer(message)) return len(p), nil } @@ -66,7 +67,7 @@ func init() { n := runtime.Stack(buf, true) buf[n] = 0 if uintptr(loggerFunc) != 0 { - C.callLogger(loggerFunc, 0, (*C.char)(unsafe.Pointer(&buf[0]))) + C.callLogger(loggerFunc, loggerCtx, 0, (*C.char)(unsafe.Pointer(&buf[0]))) } } } @@ -79,7 +80,8 @@ func wgEnableRoaming(enabled bool) { } //export wgSetLogger -func wgSetLogger(loggerFn uintptr) { +func wgSetLogger(context, loggerFn uintptr) { + loggerCtx = unsafe.Pointer(context) loggerFunc = unsafe.Pointer(loggerFn) } diff --git a/wireguard-go-bridge/wireguard.h b/wireguard-go-bridge/wireguard.h index 5c30ee9..18bf6bd 100644 --- a/wireguard-go-bridge/wireguard.h +++ b/wireguard-go-bridge/wireguard.h @@ -10,9 +10,9 @@ #include #include -typedef void(*logger_fn_t)(int level, const char *msg); +typedef void(*logger_fn_t)(void *context, int level, const char *msg); extern void wgEnableRoaming(bool enabled); -extern void wgSetLogger(logger_fn_t logger_fn); +extern void wgSetLogger(void *context, logger_fn_t logger_fn); extern int wgTurnOn(const char *settings, int32_t tun_fd); extern void wgTurnOff(int handle); extern int64_t wgSetConfig(int handle, const char *settings);