From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id E8B8745469 for ; Wed, 1 Mar 2023 14:45:04 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F3CFD68AC52; Wed, 1 Mar 2023 16:45:00 +0200 (EET) Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A8FBE68ABFF for ; Wed, 1 Mar 2023 16:44:54 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 4545B2404EC; Wed, 1 Mar 2023 15:44:54 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id iSAEtVv0_Wbp; Wed, 1 Mar 2023 15:44:53 +0100 (CET) Received: from lain.khirnov.net (lain.khirnov.net [IPv6:2001:67c:1138:4306::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "lain.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 92102240178; Wed, 1 Mar 2023 15:44:53 +0100 (CET) Received: by lain.khirnov.net (Postfix, from userid 1000) id 75E621601B2; Wed, 1 Mar 2023 15:44:53 +0100 (CET) From: Anton Khirnov To: FFmpeg development discussions and patches In-Reply-To: <20230228154420.4141579-1-jack.wgm@gmail.com> References: <20230228101640.3337990-1-jack.wgm@gmail.com> <20230228154420.4141579-1-jack.wgm@gmail.com> Mail-Followup-To: FFmpeg development discussions and patches , george@nsup.org, jackarain Date: Wed, 01 Mar 2023 15:44:53 +0100 Message-ID: <167768189345.10789.7225800970665443962@lain.khirnov.net> User-Agent: alot/0.8.1 MIME-Version: 1.0 Subject: Re: [FFmpeg-devel] [PATCH] libavformat/tcp: add local_addr/local_port for network option X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: jackarain Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Quoting jackarain (2023-02-28 16:44:20) > -static void customize_fd(void *ctx, int fd) > +static int customize_fd(void *ctx, int fd) > { > TCPContext *s = ctx; > + > + if (s->local_addr || s->local_port) { > + struct addrinfo hints = { 0 }, *ai; > + int ret; > + > + hints.ai_family = AF_UNSPEC; > + hints.ai_socktype = SOCK_STREAM; > + > + ret = getaddrinfo(s->local_addr, s->local_port, &hints, &ai); > + if (ret) { > + av_log(ctx, AV_LOG_ERROR, > + "Failed to getaddrinfo local addr: %s port: %s err: %s\n", > + s->local_addr, s->local_port, gai_strerror(ret)); > + return ret; > + } else { nit: the else clause pointlessly adds an indentation level and serves no useful purpose > + struct addrinfo *cur_ai = ai; > + while (cur_ai) { > + ret = bind(fd, (struct sockaddr *)cur_ai->ai_addr, (int)cur_ai->ai_addrlen); > + if (ret) > + cur_ai = cur_ai->ai_next; > + else > + break; > + } > + freeaddrinfo(ai); > + > + if (ret) { > + av_log(ctx, AV_LOG_ERROR, > + "Failed to bind local addr: %s port: %s err: %s\n", > + s->local_addr, s->local_port, gai_strerror(ret)); > + return ret; > + } > + } > + } > /* Set the socket's send or receive buffer sizes, if specified. > If unspecified or setting fails, system default is used. */ > if (s->recv_buffer_size > 0) { > @@ -97,6 +134,8 @@ static void customize_fd(void *ctx, int fd) > } > } > #endif /* !HAVE_WINSOCK2_H */ > + > + return 0; > } > > /* return non zero if error */ > @@ -129,6 +168,14 @@ static int tcp_open(URLContext *h, const char *uri, int flags) > if (buf == endptr) > s->listen = 1; > } > + if (av_find_info_tag(buf, sizeof(buf), "local_port", p)) { > + av_freep(&s->local_port); > + s->local_port = av_strndup(buf, strlen(buf)); This does memory allocation, so the result should be checked. Also, it av_str_n_dup() gives you no advantages since you call strlen anyway. Just use av_strdup(). Same below. -- Anton Khirnov _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".