get the default broadcast network address.

This commit is contained in:
2026-08-03 15:44:21 +02:00
parent cffedd6dbf
commit 1f9208560f
6 changed files with 71 additions and 11 deletions
+21 -7
View File
@@ -9,7 +9,8 @@
(require racket/list
simple-log
racket/string
racket/udp)
racket/udp
"network.rkt")
(provide ssdp-response?
ssdp-response-address
@@ -179,6 +180,7 @@
;; Search for a UPnP search target. The default "ssdp:all" returns all
;; advertised device and service targets. #:interface may be a local IPv4
;; address such as "10.7.3.118" when the machine has multiple interfaces.
;; Without #:interface, the local IPv4 address for the SSDP route is detected.
(define (ssdp-discover [search-target "ssdp:all"]
#:mx [mx 3]
#:timeout [timeout #f]
@@ -186,24 +188,36 @@
#:interface [interface #f]
#:ttl [ttl 2]
#:user-agent [user-agent #f])
(let ([effective-timeout (or timeout (+ mx 1.0))])
(let* ([effective-timeout (or timeout (+ mx 1.0))]
[effective-interface
(or interface
(with-handlers
([exn:fail?
(lambda (exception)
(warn-upnp-ssdp
"Could not determine the UPnP IPv4 address: ~a; using the OS-selected interface"
(exn-message exception))
#f)])
(upnp-default-ipv4-address)))])
(check-discovery-arguments search-target
mx
effective-timeout
repeat
interface
effective-interface
ttl
user-agent)
(dbg-upnp-ssdp "Starting SSDP discovery target=~a mx=~a timeout=~a repeat=~a interface=~a ttl=~a" search-target mx effective-timeout repeat (or interface "default") ttl)
(dbg-upnp-ssdp "Starting SSDP discovery target=~a mx=~a timeout=~a repeat=~a interface=~a ttl=~a" search-target mx effective-timeout repeat (or effective-interface "OS-selected") ttl)
(let ([socket (udp-open-socket ssdp-multicast-address ssdp-multicast-port)]
[request (make-search-request search-target mx user-agent)])
(dynamic-wind
void
(lambda ()
(define started-at (current-inexact-milliseconds))
(udp-bind! socket interface 0)
(dbg-upnp-ssdp "SSDP socket bound to interface ~a" (or interface "default"))
(udp-multicast-set-interface! socket interface)
(udp-bind! socket effective-interface 0)
(dbg-upnp-ssdp
"SSDP socket bound to local interface ~a"
(or effective-interface "OS-selected"))
(udp-multicast-set-interface! socket effective-interface)
(udp-multicast-set-ttl! socket ttl)
(for ([attempt (in-range repeat)])
(dbg-upnp-ssdp "Sending SSDP M-SEARCH attempt ~a of ~a" (add1 attempt) repeat)