n2n icon indicating copy to clipboard operation
n2n copied to clipboard

when i killed the edge process on macos, the 1968 port will be used forever, although i can't find any process use it

Open work-chausat opened this issue 4 years ago • 5 comments

if you restart edge again, you will get this error: [n2n.c:58] ERROR: Bind error on local port 1968 [Address already in use]

than you see: sudo netstat -anvp udp |grep 1968 udp4 0 0 *.1968 . 786896 9216 2274 0 0x0080 0x00000204

now, if you kill -9 2274, you will get: -bash: kill: (2274) - No such process

even you unload the kernel ext, the 1968 port will be still there!! /sbin/kextunload /Library/Extensions/tap.kext /sbin/kextunload /Library/Extensions/tun.kext

work-chausat avatar Mar 29 '20 15:03 work-chausat

Has anyone overcame this issue?

yermulnik avatar Jul 13 '20 19:07 yermulnik

Here's the fix:

diff --git a/src/n2n.c b/src/n2n.c
index 86d2dbe..e585cb8 100644
--- a/src/n2n.c
+++ b/src/n2n.c
@@ -48,6 +48,9 @@ SOCKET open_socket(int local_port, int bind_any) {

   sockopt = 1;
   setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, (char *)&sockopt, sizeof(sockopt));
+  #ifdef __APPLE__   // MacOS/X requires an additional call
+    setsockopt(sock_fd, SOL_SOCKET, SO_REUSEPORT, (char *)&sockopt, sizeof(sockopt));
+  #endif

   memset(&local_address, 0, sizeof(local_address));
   local_address.sin_family = AF_INET;

yermulnik avatar Jul 29 '20 15:07 yermulnik

I don't think it's a good idea. Why don't you check the return code of setsockopt() first and report?

lucaderi avatar Jul 29 '20 18:07 lucaderi

That's what google search gives re this kind of issues on MacOS so that this OS needs both SO_REUSEADDR and SO_REUSEPORT in such use cases.

yermulnik avatar Jul 29 '20 19:07 yermulnik

I just download newest n2n pre-built client. https://github.com/lucktu/n2n/blob/master/Mac/n2n_v3_mac_x64_v3.0.0_r1041_by_LomotHo.tar.gz It's also happen in my desktop.

macOS 13.4 on intel chip

Yuzu-io avatar Jul 10 '23 14:07 Yuzu-io