Add support to httpuClient for specific port

This commit is contained in:
Remco Ritskes
2024-10-23 11:56:44 +02:00
committed by John Beisley
parent 538e53587e
commit 5a65ac4683

View File

@@ -69,13 +69,20 @@ func NewHTTPUClient() (*HTTPUClient, error) {
}
// NewHTTPUClientAddr creates a new HTTPUClient which will broadcast packets
// from the specified address, opening up a new UDP socket for the purpose
// from the specified address, opening up a new UDP socket for the purpose on a random port
func NewHTTPUClientAddr(addr string) (*HTTPUClient, error) {
ip := net.ParseIP(addr)
if ip == nil {
return nil, errors.New("Invalid listening address")
}
conn, err := net.ListenPacket("udp", ip.String()+":0")
return NewHTTPUClientAddrWithPort(ip.String() + ":0")
}
// NewHTTPUClientAddrWithPort creates a new HTTPUClient which will broadcast packets
// from the specified address, opening up a new UDP socket for the purpose on a specific port
func NewHTTPUClientAddrWithPort(addr string) (*HTTPUClient, error) {
conn, err := net.ListenPacket("udp", addr)
if err != nil {
return nil, err
}