From: jackarain <jack.wgm@gmail.com>
To: FFmpeg development discussions and patches
<ffmpeg-devel@ffmpeg.org>,
george@nsup.org, jackarain <jack.wgm@gmail.com>
Subject: Re: [FFmpeg-devel] [PATCH] libavformat/tcp: add local_addr/local_port for network option
Date: Wed, 1 Mar 2023 22:56:16 +0800
Message-ID: <CAKyCUZj__x0y0phH=BJuHvM6VYQ+4=mrSf9ETU3fLWQ4KTpL0Q@mail.gmail.com> (raw)
In-Reply-To: <167768189345.10789.7225800970665443962@lain.khirnov.net>
Ok, thanks.
Anton Khirnov <anton@khirnov.net> 于2023年3月1日周三 22:44写道:
> 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".
next prev parent reply other threads:[~2023-03-01 14:57 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-28 10:16 jack
2023-02-28 10:57 ` Nicolas George
2023-02-28 14:27 ` jackarain
2023-02-28 15:44 ` jackarain
2023-03-01 14:44 ` Anton Khirnov
2023-03-01 14:56 ` jackarain [this message]
2023-03-01 15:07 ` jackarain
2023-03-01 15:44 ` jackarain
2023-03-02 18:47 ` Rémi Denis-Courmont
2023-03-02 18:51 ` Nicolas George
2023-03-03 9:49 ` jackarain
2023-03-30 10:11 ` Anton Khirnov
2023-02-28 14:24 jackarain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAKyCUZj__x0y0phH=BJuHvM6VYQ+4=mrSf9ETU3fLWQ4KTpL0Q@mail.gmail.com' \
--to=jack.wgm@gmail.com \
--cc=ffmpeg-devel@ffmpeg.org \
--cc=george@nsup.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git