mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Add mDNS/Bonjour/Avahi (.local) support for Windows
This commit is contained in:
@@ -95,6 +95,7 @@ Resolve_Error :: enum u32 {
|
||||
}
|
||||
|
||||
DNS_Error :: enum u32 {
|
||||
None = 0,
|
||||
Invalid_Hostname_Error = 1,
|
||||
Invalid_Hosts_Config_Error,
|
||||
Invalid_Resolv_Config_Error,
|
||||
@@ -147,6 +148,8 @@ IP6_Loopback :: IP6_Address{0, 0, 0, 0, 0, 0, 0, 1}
|
||||
IP4_Any := IP4_Address{}
|
||||
IP6_Any := IP6_Address{}
|
||||
|
||||
IP4_mDNS_Broadcast := Endpoint{address=IP4_Address{224, 0, 0, 251}, port=5353}
|
||||
|
||||
Endpoint :: struct {
|
||||
address: Address,
|
||||
port: int,
|
||||
|
||||
@@ -29,9 +29,14 @@ import win "core:sys/windows"
|
||||
_get_dns_records_os :: proc(hostname: string, type: DNS_Record_Type, allocator := context.allocator) -> (records: []DNS_Record, err: DNS_Error) {
|
||||
context.allocator = allocator
|
||||
|
||||
options := win.DNS_QUERY_OPTIONS{}
|
||||
if strings.has_suffix(hostname, ".local") {
|
||||
options = {.MULTICAST_ONLY, .MULTICAST_WAIT} // 0x00020500
|
||||
}
|
||||
|
||||
host_cstr := strings.clone_to_cstring(hostname, context.temp_allocator)
|
||||
rec: ^win.DNS_RECORD
|
||||
res := win.DnsQuery_UTF8(host_cstr, u16(type), 0, nil, &rec, nil)
|
||||
res := win.DnsQuery_UTF8(host_cstr, u16(type), options, nil, &rec, nil)
|
||||
|
||||
switch u32(res) {
|
||||
case 0:
|
||||
|
||||
@@ -35,6 +35,7 @@ Socket_Option :: enum c.int {
|
||||
Send_Buffer_Size = c.int(linux.Socket_Option.SNDBUF),
|
||||
Receive_Timeout = c.int(linux.Socket_Option.RCVTIMEO),
|
||||
Send_Timeout = c.int(linux.Socket_Option.SNDTIMEO),
|
||||
Broadcast = c.int(linux.Socket_Option.BROADCAST),
|
||||
}
|
||||
|
||||
// Wrappers and unwrappers for system-native types
|
||||
@@ -337,7 +338,8 @@ _set_option :: proc(sock: Any_Socket, option: Socket_Option, value: any, loc :=
|
||||
.Reuse_Address,
|
||||
.Keep_Alive,
|
||||
.Out_Of_Bounds_Data_Inline,
|
||||
.TCP_Nodelay:
|
||||
.TCP_Nodelay,
|
||||
.Broadcast:
|
||||
// TODO: verify whether these are options or not on Linux
|
||||
// .Broadcast, <-- yes
|
||||
// .Conditional_Accept,
|
||||
|
||||
Reference in New Issue
Block a user