From 8bed6ecfeb498d123fc7678456820127ec3b64d4 Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sun, 26 Jan 2020 12:58:56 +0100 Subject: [PATCH] add checks on ports --- main.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 1685f4d1..a9d88ed1 100644 --- a/main.go +++ b/main.go @@ -62,6 +62,27 @@ type program struct { } func newProgram(protocolsStr string, rtspPort int, rtpPort int, rtcpPort int, publishKey string) (*program, error) { + + if rtspPort == 0 { + return nil, fmt.Errorf("rtsp port not provided") + } + + if rtpPort == 0 { + return nil, fmt.Errorf("rtp port not provided") + } + + if rtcpPort == 0 { + return nil, fmt.Errorf("rtcp port not provided") + } + + if (rtpPort % 2) != 0 { + return nil, fmt.Errorf("rtp port must be even") + } + + if rtcpPort != (rtpPort + 1) { + return nil, fmt.Errorf("rtcp port must be rtp port plus 1") + } + protocols := make(map[streamProtocol]struct{}) for _, proto := range strings.Split(protocolsStr, ",") { switch proto { @@ -76,7 +97,7 @@ func newProgram(protocolsStr string, rtspPort int, rtpPort int, rtcpPort int, pu } } if len(protocols) == 0 { - return nil, fmt.Errorf("no protocols supplied") + return nil, fmt.Errorf("no protocols provided") } if publishKey != "" {