mirror of
https://github.com/aler9/gortsplib
synced 2025-09-27 03:25:52 +08:00
move host resolution from headers to client/server (#883)
This commit is contained in:
57
client.go
57
client.go
@@ -1867,8 +1867,17 @@ func (c *Client) doSetup(
|
||||
}
|
||||
|
||||
var remoteIP net.IP
|
||||
if thRes.Source != nil {
|
||||
remoteIP = *thRes.Source
|
||||
if thRes.Source2 != nil {
|
||||
if ip := net.ParseIP(*thRes.Source2); ip != nil {
|
||||
remoteIP = ip
|
||||
} else {
|
||||
var addr *net.UDPAddr
|
||||
addr, err = net.ResolveUDPAddr("udp", *thRes.Source2)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to solve source host: %w", err)
|
||||
}
|
||||
remoteIP = addr.IP
|
||||
}
|
||||
} else {
|
||||
remoteIP = c.nconn.RemoteAddr().(*net.TCPAddr).IP
|
||||
}
|
||||
@@ -1902,21 +1911,41 @@ func (c *Client) doSetup(
|
||||
return nil, liberrors.ErrClientTransportHeaderInvalidDelivery{}
|
||||
}
|
||||
|
||||
if thRes.Ports == nil {
|
||||
return nil, liberrors.ErrClientTransportHeaderNoPorts{}
|
||||
}
|
||||
|
||||
if thRes.Destination == nil {
|
||||
return nil, liberrors.ErrClientTransportHeaderNoDestination{}
|
||||
}
|
||||
|
||||
var remoteIP net.IP
|
||||
if thRes.Source != nil {
|
||||
remoteIP = *thRes.Source
|
||||
if thRes.Source2 != nil {
|
||||
if ip := net.ParseIP(*thRes.Source2); ip != nil {
|
||||
remoteIP = ip
|
||||
} else {
|
||||
var addr *net.UDPAddr
|
||||
addr, err = net.ResolveUDPAddr("udp", *thRes.Source2)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to solve source host: %w", err)
|
||||
}
|
||||
remoteIP = addr.IP
|
||||
}
|
||||
} else {
|
||||
remoteIP = c.nconn.RemoteAddr().(*net.TCPAddr).IP
|
||||
}
|
||||
|
||||
var destIP net.IP
|
||||
if thRes.Destination2 == nil {
|
||||
return nil, liberrors.ErrClientTransportHeaderNoDestination{}
|
||||
}
|
||||
if ip := net.ParseIP(*thRes.Destination2); ip != nil {
|
||||
destIP = ip
|
||||
} else {
|
||||
var addr *net.UDPAddr
|
||||
addr, err = net.ResolveUDPAddr("udp", *thRes.Destination2)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to solve destination host: %w", err)
|
||||
}
|
||||
destIP = addr.IP
|
||||
}
|
||||
|
||||
if thRes.Ports == nil {
|
||||
return nil, liberrors.ErrClientTransportHeaderNoPorts{}
|
||||
}
|
||||
|
||||
var intf *net.Interface
|
||||
intf, err = interfaceOfConn(c.nconn)
|
||||
if err != nil {
|
||||
@@ -1927,8 +1956,8 @@ func (c *Client) doSetup(
|
||||
c,
|
||||
true,
|
||||
intf,
|
||||
net.JoinHostPort(thRes.Destination.String(), strconv.FormatInt(int64(thRes.Ports[0]), 10)),
|
||||
net.JoinHostPort(thRes.Destination.String(), strconv.FormatInt(int64(thRes.Ports[1]), 10)),
|
||||
net.JoinHostPort(destIP.String(), strconv.FormatInt(int64(thRes.Ports[0]), 10)),
|
||||
net.JoinHostPort(destIP.String(), strconv.FormatInt(int64(thRes.Ports[1]), 10)),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Reference in New Issue
Block a user