mirror of
https://github.com/aler9/gortsplib
synced 2025-10-05 15:16:51 +08:00
fix parsing of transport headers with empty source (https://github.com/aler9/rtsp-simple-server/issues/986)
This commit is contained in:
@@ -144,25 +144,29 @@ func (h *Transport) Read(v base.HeaderValue) error {
|
||||
h.Delivery = &v
|
||||
|
||||
case "source":
|
||||
ip := net.ParseIP(v)
|
||||
if ip == nil {
|
||||
addrs, err := net.LookupHost(v)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid source (%v)", v)
|
||||
}
|
||||
ip = net.ParseIP(addrs[0])
|
||||
if v != "" {
|
||||
ip := net.ParseIP(v)
|
||||
if ip == nil {
|
||||
return fmt.Errorf("invalid source (%v)", v)
|
||||
addrs, err := net.LookupHost(v)
|
||||
if err != nil {
|
||||
return fmt.Errorf("invalid source (%v)", v)
|
||||
}
|
||||
ip = net.ParseIP(addrs[0])
|
||||
if ip == nil {
|
||||
return fmt.Errorf("invalid source (%v)", v)
|
||||
}
|
||||
}
|
||||
h.Source = &ip
|
||||
}
|
||||
h.Source = &ip
|
||||
|
||||
case "destination":
|
||||
ip := net.ParseIP(v)
|
||||
if ip == nil {
|
||||
return fmt.Errorf("invalid destination (%v)", v)
|
||||
if v != "" {
|
||||
ip := net.ParseIP(v)
|
||||
if ip == nil {
|
||||
return fmt.Errorf("invalid destination (%v)", v)
|
||||
}
|
||||
h.Destination = &ip
|
||||
}
|
||||
h.Destination = &ip
|
||||
|
||||
case "interleaved":
|
||||
ports, err := parsePorts(v)
|
||||
|
@@ -198,6 +198,24 @@ var casesTransport = []struct {
|
||||
}(),
|
||||
},
|
||||
},
|
||||
{
|
||||
"empty source",
|
||||
base.HeaderValue{`RTP/AVP/UDP;unicast;source=;client_port=32560-32561;server_port=3046-3047;ssrc=45dcb578`},
|
||||
base.HeaderValue{`RTP/AVP;unicast;client_port=32560-32561;server_port=3046-3047;ssrc=45DCB578`},
|
||||
Transport{
|
||||
Protocol: TransportProtocolUDP,
|
||||
Delivery: func() *TransportDelivery {
|
||||
v := TransportDeliveryUnicast
|
||||
return &v
|
||||
}(),
|
||||
SSRC: func() *uint32 {
|
||||
v := uint32(0x45dcb578)
|
||||
return &v
|
||||
}(),
|
||||
ClientPorts: &[2]int{32560, 32561},
|
||||
ServerPorts: &[2]int{3046, 3047},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
func TestTransportRead(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user