size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...)
{
    int len = strlen(dst);
    va_list vl;
    va_start(vl, fmt);
    len += vsnprintf(dst + len, size > len ? size - len : 0, fmt, vl);
    va_end(vl);
    return len;
}
['static int\nmake_setup_request (AVFormatContext *s, const char *host, int port,\n                    int lower_transport, const char *real_challenge)\n{\n    RTSPState *rt = s->priv_data;\n    int rtx, j, i, err, interleave = 0;\n    RTSPStream *rtsp_st;\n    RTSPMessageHeader reply1, *reply = &reply1;\n    char cmd[2048];\n    const char *trans_pref;\n    if (rt->transport == RTSP_TRANSPORT_RDT)\n        trans_pref = "x-pn-tng";\n    else\n        trans_pref = "RTP/AVP";\n    for(j = RTSP_RTP_PORT_MIN, i = 0; i < rt->nb_rtsp_streams; ++i) {\n        char transport[2048];\n        if (lower_transport == RTSP_LOWER_TRANSPORT_UDP &&\n             rt->server_type == RTSP_SERVER_WMS) {\n            if (i == 0) {\n                for (rtx = 0; rtx < rt->nb_rtsp_streams; rtx++) {\n                    int len = strlen(rt->rtsp_streams[rtx]->control_url);\n                    if (len >= 4 &&\n                        !strcmp(rt->rtsp_streams[rtx]->control_url + len - 4, "/rtx"))\n                        break;\n                }\n                if (rtx == rt->nb_rtsp_streams)\n                    return -1;\n                rtsp_st = rt->rtsp_streams[rtx];\n            } else\n                rtsp_st = rt->rtsp_streams[i > rtx ? i : i - 1];\n        } else\n            rtsp_st = rt->rtsp_streams[i];\n        if (lower_transport == RTSP_LOWER_TRANSPORT_UDP) {\n            char buf[256];\n            if (rt->server_type == RTSP_SERVER_WMS && i > 1) {\n                port = reply->transports[0].client_port_min;\n                goto have_port;\n            }\n            if (RTSP_RTP_PORT_MIN != 0) {\n                while(j <= RTSP_RTP_PORT_MAX) {\n                    snprintf(buf, sizeof(buf), "rtp://%s?localport=%d", host, j);\n                    j += 2;\n                    if (url_open(&rtsp_st->rtp_handle, buf, URL_RDWR) == 0) {\n                        goto rtp_opened;\n                    }\n                }\n            }\n        rtp_opened:\n            port = rtp_get_local_port(rtsp_st->rtp_handle);\n        have_port:\n            snprintf(transport, sizeof(transport) - 1,\n                     "%s/UDP;", trans_pref);\n            if (rt->server_type != RTSP_SERVER_REAL)\n                av_strlcat(transport, "unicast;", sizeof(transport));\n            av_strlcatf(transport, sizeof(transport),\n                     "client_port=%d", port);\n            if (rt->transport == RTSP_TRANSPORT_RTP &&\n                !(rt->server_type == RTSP_SERVER_WMS && i > 0))\n                av_strlcatf(transport, sizeof(transport), "-%d", port + 1);\n        }\n        else if (lower_transport == RTSP_LOWER_TRANSPORT_TCP) {\n            if (rt->server_type == RTSP_SERVER_WMS &&\n                s->streams[rtsp_st->stream_index]->codec->codec_type == CODEC_TYPE_DATA)\n                continue;\n            snprintf(transport, sizeof(transport) - 1,\n                     "%s/TCP;", trans_pref);\n            if (rt->server_type == RTSP_SERVER_WMS)\n                av_strlcat(transport, "unicast;", sizeof(transport));\n            av_strlcatf(transport, sizeof(transport),\n                        "interleaved=%d-%d",\n                        interleave, interleave + 1);\n            interleave += 2;\n        }\n        else if (lower_transport == RTSP_LOWER_TRANSPORT_UDP_MULTICAST) {\n            snprintf(transport, sizeof(transport) - 1,\n                     "%s/UDP;multicast", trans_pref);\n        }\n        if (rt->server_type == RTSP_SERVER_REAL ||\n            rt->server_type == RTSP_SERVER_WMS)\n            av_strlcat(transport, ";mode=play", sizeof(transport));\n        snprintf(cmd, sizeof(cmd),\n                 "SETUP %s RTSP/1.0\\r\\n"\n                 "Transport: %s\\r\\n",\n                 rtsp_st->control_url, transport);\n        if (i == 0 && rt->server_type == RTSP_SERVER_REAL) {\n            char real_res[41], real_csum[9];\n            ff_rdt_calc_response_and_checksum(real_res, real_csum,\n                                              real_challenge);\n            av_strlcatf(cmd, sizeof(cmd),\n                        "If-Match: %s\\r\\n"\n                        "RealChallenge2: %s, sd=%s\\r\\n",\n                        rt->session_id, real_res, real_csum);\n        }\n        rtsp_send_cmd(s, cmd, reply, NULL);\n        if (reply->status_code == 461   && i == 0) {\n            err = 1;\n            goto fail;\n        } else if (reply->status_code != RTSP_STATUS_OK ||\n                   reply->nb_transports != 1) {\n            err = AVERROR_INVALIDDATA;\n            goto fail;\n        }\n        if (i > 0) {\n            if (reply->transports[0].lower_transport != rt->lower_transport ||\n                reply->transports[0].transport != rt->transport) {\n                err = AVERROR_INVALIDDATA;\n                goto fail;\n            }\n        } else {\n            rt->lower_transport = reply->transports[0].lower_transport;\n            rt->transport = reply->transports[0].transport;\n        }\n        if (reply->transports[0].lower_transport != RTSP_LOWER_TRANSPORT_UDP &&\n            (lower_transport == RTSP_LOWER_TRANSPORT_UDP)) {\n            url_close(rtsp_st->rtp_handle);\n            rtsp_st->rtp_handle = NULL;\n        }\n        switch(reply->transports[0].lower_transport) {\n        case RTSP_LOWER_TRANSPORT_TCP:\n            rtsp_st->interleaved_min = reply->transports[0].interleaved_min;\n            rtsp_st->interleaved_max = reply->transports[0].interleaved_max;\n            break;\n        case RTSP_LOWER_TRANSPORT_UDP:\n            {\n                char url[1024];\n                snprintf(url, sizeof(url), "rtp://%s:%d",\n                         host, reply->transports[0].server_port_min);\n                if (!(rt->server_type == RTSP_SERVER_WMS && i > 1) &&\n                    rtp_set_remote_url(rtsp_st->rtp_handle, url) < 0) {\n                    err = AVERROR_INVALIDDATA;\n                    goto fail;\n                }\n            }\n            break;\n        case RTSP_LOWER_TRANSPORT_UDP_MULTICAST:\n            {\n                char url[1024];\n                struct in_addr in;\n                in.s_addr = htonl(reply->transports[0].destination);\n                snprintf(url, sizeof(url), "rtp://%s:%d?ttl=%d",\n                         inet_ntoa(in),\n                         reply->transports[0].port_min,\n                         reply->transports[0].ttl);\n                if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) {\n                    err = AVERROR_INVALIDDATA;\n                    goto fail;\n                }\n            }\n            break;\n        }\n        if ((err = rtsp_open_transport_ctx(s, rtsp_st)))\n            goto fail;\n    }\n    if (rt->server_type == RTSP_SERVER_REAL)\n        rt->need_subscription = 1;\n    return 0;\nfail:\n    for (i=0; i<rt->nb_rtsp_streams; i++) {\n        if (rt->rtsp_streams[i]->rtp_handle) {\n            url_close(rt->rtsp_streams[i]->rtp_handle);\n            rt->rtsp_streams[i]->rtp_handle = NULL;\n        }\n    }\n    return err;\n}', 'size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...)\n{\n    int len = strlen(dst);\n    va_list vl;\n    va_start(vl, fmt);\n    len += vsnprintf(dst + len, size > len ? size - len : 0, fmt, vl);\n    va_end(vl);\n    return len;\n}']