fix windows broadcast packet

This commit is contained in:
2025-09-30 12:49:01 +08:00
parent 52f3756be3
commit 3145d2bff0
1 file changed
+2 -4
@@ -36,13 +36,11 @@ public actual class Socket1 internal actual constructor() {
WSACleanup() WSACleanup()
} }
val reuse = nativeHeap.alloc<IntVar>()
reuse.value = 1
val result = setsockopt( val result = setsockopt(
sock, sock,
SOL_SOCKET, SOL_SOCKET,
SO_REUSEADDR, SO_REUSEADDR,
reuse.ptr.reinterpret<ByteVar>().toKString(), "1",
sizeOf<IntVar>().convert() sizeOf<IntVar>().convert()
) )
if (result != 0) println("setsockopt failed") if (result != 0) println("setsockopt failed")
@@ -66,7 +64,7 @@ public actual class Socket1 internal actual constructor() {
if (!bound) throw IllegalStateException("Socket not bound") if (!bound) throw IllegalStateException("Socket not bound")
val dest = alloc<SOCKADDR_IN>() val dest = alloc<SOCKADDR_IN>()
dest.sin_family = AF_INET.convert() dest.sin_family = AF_INET.convert()
dest.sin_port = 5353u dest.sin_port = htons(5353u)
dest.sin_addr.S_un.S_addr = inet_addr("224.0.0.251") dest.sin_addr.S_un.S_addr = inet_addr("224.0.0.251")
packet.usePinned { pinned -> packet.usePinned { pinned ->
val sent = sendto( val sent = sendto(