From: Timo Rothenpieler <timo@rothenpieler.org> To: ffmpeg-devel@ffmpeg.org Cc: Timo Rothenpieler <timo@rothenpieler.org> Subject: [FFmpeg-devel] [PATCH v2 4/8] avformat/udp: add function to set remote address directly Date: Sun, 6 Jul 2025 20:36:25 +0200 Message-ID: <20250706183634.38579-5-timo@rothenpieler.org> (raw) In-Reply-To: <20250706183634.38579-1-timo@rothenpieler.org> --- libavformat/network.h | 1 + libavformat/udp.c | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/libavformat/network.h b/libavformat/network.h index 48bb75a758..5734b664cd 100644 --- a/libavformat/network.h +++ b/libavformat/network.h @@ -339,5 +339,6 @@ int ff_connect_parallel(struct addrinfo *addrs, int timeout_ms_per_address, int (*customize_fd)(void *, int, int), void *customize_ctx); void ff_udp_get_last_recv_addr(URLContext *h, struct sockaddr_storage *addr); +int ff_udp_set_remote_addr(URLContext *h, const struct sockaddr *dest_addr, socklen_t dest_addr_len, int do_connect); #endif /* AVFORMAT_NETWORK_H */ diff --git a/libavformat/udp.c b/libavformat/udp.c index e02eff0f33..3657acb985 100644 --- a/libavformat/udp.c +++ b/libavformat/udp.c @@ -458,6 +458,36 @@ int ff_udp_set_remote_url(URLContext *h, const char *uri) return 0; } +/** + * This function is identical to ff_udp_set_remote_url, except that it takes a sockaddr directly. + */ +int ff_udp_set_remote_addr(URLContext *h, const struct sockaddr *dest_addr, socklen_t dest_addr_len, int do_connect) +{ + UDPContext *s = h->priv_data; + + /* set the destination address */ + if (dest_addr_len < 0 || dest_addr_len > sizeof(s->dest_addr)) + return AVERROR(EIO); + s->dest_addr_len = dest_addr_len; + memcpy(&s->dest_addr, dest_addr, dest_addr_len); + + s->is_multicast = ff_is_multicast_address((struct sockaddr*) &s->dest_addr); + if (do_connect >= 0) { + int was_connected = s->is_connected; + s->is_connected = do_connect; + if (s->is_connected && !was_connected) { + if (connect(s->udp_fd, (struct sockaddr *) &s->dest_addr, + s->dest_addr_len)) { + s->is_connected = 0; + ff_log_net_error(h, AV_LOG_ERROR, "connect"); + return AVERROR(EIO); + } + } + } + + return 0; +} + /** * Return the local port used by the UDP connection * @param h media file context -- 2.49.0 _______________________________________________ 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:[~2025-07-06 18:37 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2025-07-06 18:36 [FFmpeg-devel] [PATCH v2 0/8] WHIP + TLS + UDP fixes and SChannel DTLS support Timo Rothenpieler 2025-07-06 18:36 ` [FFmpeg-devel] [PATCH v2 1/8] avformat/tls: move whip specific init out of generic tls code Timo Rothenpieler 2025-07-07 6:30 ` Jack Lau 2025-07-06 18:36 ` [FFmpeg-devel] [PATCH v2 2/8] avformat/udp: make recv addr of each packet available Timo Rothenpieler 2025-07-06 18:36 ` [FFmpeg-devel] [PATCH v2 3/8] avformat/udp: separate rx and tx fifo Timo Rothenpieler 2025-07-06 18:36 ` Timo Rothenpieler [this message] 2025-07-06 18:36 ` [FFmpeg-devel] [PATCH v2 5/8] avformat/tls: make passing an external socket universal Timo Rothenpieler 2025-07-06 18:36 ` [FFmpeg-devel] [PATCH v2 6/8] avformat/tls_schannel: add DTLS support Timo Rothenpieler 2025-07-06 18:36 ` [FFmpeg-devel] [PATCH v2 7/8] avformat/tls_schannel: add option to load server certificate from store Timo Rothenpieler 2025-07-06 18:36 ` [FFmpeg-devel] [PATCH v2 8/8] avformat/tls_schannel: fix non-blocking write breaking TLS sessions Timo Rothenpieler
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=20250706183634.38579-5-timo@rothenpieler.org \ --to=timo@rothenpieler.org \ --cc=ffmpeg-devel@ffmpeg.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