diff --git a/doc/protocols.texi b/doc/protocols.texi index 600f470458..29f5c90d81 100644 --- a/doc/protocols.texi +++ b/doc/protocols.texi @@ -251,6 +251,9 @@ Use UDP multicast as lower transport protocol. @item http Use HTTP tunneling as lower transport protocol, which is useful for passing proxies. + +@item filter_src +Accept packets only from negotiated peer address and port. @end table Multiple lower transport protocols may be specified, in that case they are diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c index a38cc42408..b09ebd7642 100644 --- a/libavformat/rtsp.c +++ b/libavformat/rtsp.c @@ -1186,16 +1186,18 @@ static int make_setup_request(AVFormatContext *s, const char *host, int port, break; case RTSP_LOWER_TRANSPORT_UDP: { - char url[1024]; + char url[1024], options[30] = ""; + if (rt->filter_source) + av_strlcpy(options, "?connect=1", sizeof(options)); /* Use source address if specified */ if (reply->transports[0].source[0]) { ff_url_join(url, sizeof(url), "rtp", NULL, reply->transports[0].source, - reply->transports[0].server_port_min, NULL); + reply->transports[0].server_port_min, options); } else { ff_url_join(url, sizeof(url), "rtp", NULL, host, - reply->transports[0].server_port_min, NULL); + reply->transports[0].server_port_min, options); } if (!(rt->server_type == RTSP_SERVER_WMS && i > 1) && rtp_set_remote_url(rtsp_st->rtp_handle, url) < 0) { @@ -1315,6 +1317,8 @@ redirect: } else if(!strcmp(option, "http")) { lower_transport_mask |= (1<< RTSP_LOWER_TRANSPORT_TCP); rt->control_transport = RTSP_MODE_TUNNEL; + } else if (!strcmp(option, "filter_src")) { + rt->filter_source = 1; } else { /* Write options back into the buffer, using memmove instead * of strcpy since the strings may overlap. */ diff --git a/libavformat/rtsp.h b/libavformat/rtsp.h index 628ce370ec..eee07ac0e7 100644 --- a/libavformat/rtsp.h +++ b/libavformat/rtsp.h @@ -309,6 +309,10 @@ typedef struct RTSPState { /** Reusable buffer for receiving packets */ uint8_t* recvbuf; + + /** Filter incoming UDP packets - receive packets only from the right + * source address and port. */ + int filter_source; } RTSPState; /**