From 0a1bf5b3b6a59cc9194a077100b870480d600a7c Mon Sep 17 00:00:00 2001 From: Ludvig Strigeus Date: Wed, 8 Aug 2018 23:58:04 +0200 Subject: [PATCH] Make it print Connection established like on Windows --- network_bsd.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/network_bsd.cpp b/network_bsd.cpp index 72bb353..10ba06c 100644 --- a/network_bsd.cpp +++ b/network_bsd.cpp @@ -866,6 +866,31 @@ void TunsafeBackendBsd::RunLoop() { void InitCpuFeatures(); void Benchmark(); +static const char *print_ip(char buf[kSizeOfAddress], in_addr_t ip) { + snprintf(buf, kSizeOfAddress, "%d.%d.%d.%d", (ip >> 24) & 0xff, (ip >> 16) & 0xff, (ip >> 8) & 0xff, (ip >> 0) & 0xff); + return buf; +} + +static uint32 g_ui_ip; +class MyProcessorDelegate : public ProcessorDelegate { +public: + virtual void OnConnected(in_addr_t my_ip) { + if (my_ip != g_ui_ip) { + if (my_ip) { + char buf[kSizeOfAddress]; + print_ip(buf, my_ip); + RINFO("Connection established. IP %s", buf); + } + g_ui_ip = my_ip; + } + } + virtual void OnDisconnected() { + MyProcessorDelegate::OnConnected(0); + } +}; + +static MyProcessorDelegate my_procdel; + int main(int argc, char **argv) { bool exit_flag = false; @@ -886,7 +911,7 @@ int main(int argc, char **argv) { #endif TunsafeBackendBsd socket_loop; - WireguardProcessor wg(&socket_loop, &socket_loop, NULL); + WireguardProcessor wg(&socket_loop, &socket_loop, &my_procdel); socket_loop.SetProcessor(&wg); if (!ParseWireGuardConfigFile(&wg, argv[1], &exit_flag)) return 1;