Skip to content

Commit

Permalink
Improve SRV handling in dns_windows.odin
Browse files Browse the repository at this point in the history
  • Loading branch information
Kelimion committed Aug 24, 2024
1 parent aa659a6 commit 0a825fc
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions core/net/dns_windows.odin
Original file line number Diff line number Diff line change
Expand Up @@ -128,33 +128,37 @@ _get_dns_records_os :: proc(hostname: string, type: DNS_Record_Type, allocator :
append(&recs, record)

case .SRV:
target := strings.clone(string(r.Data.SRV.pNameTarget)) // The target hostname/address that the service can be found on
priority := int(r.Data.SRV.wPriority)
weight := int(r.Data.SRV.wWeight)
port := int(r.Data.SRV.wPort)

// NOTE(tetra): Srv record name should be of the form '_servicename._protocol.hostname'
// The record name is the name of the record.
// Not to be confused with the _target_ of the record, which is--in combination with the port--what we're looking up
// by making this request in the first place.

// NOTE(Jeroen): Service Name and Protocol Name can probably just be string slices into the record name.
// It's already cloned, after all. I wouldn't put them on the temp allocator like this.
service_name, protocol_name: string

s := base_record.record_name
i := strings.index_byte(s, '.')
if i > -1 {
service_name = s[:i]
s = s[len(service_name) + 1:]
} else {
continue
}

parts := strings.split_n(base_record.record_name, ".", 3, context.temp_allocator)
if len(parts) != 3 {
i = strings.index_byte(s, '.')
if i > -1 {
protocol_name = s[:i]
} else {
continue
}
service_name, protocol_name := parts[0], parts[1]

append(&recs, DNS_Record_SRV {
base = base_record,
target = target,
port = port,
target = strings.clone(string(r.Data.SRV.pNameTarget)), // The target hostname/address that the service can be found on
port = int(r.Data.SRV.wPort),
service_name = service_name,
protocol_name = protocol_name,
priority = priority,
weight = weight,
priority = int(r.Data.SRV.wPriority),
weight = int(r.Data.SRV.wWeight),

})
}
Expand Down

0 comments on commit 0a825fc

Please sign in to comment.