From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.ffmpeg.org (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id CD2264FDD1 for ; Wed, 2 Jul 2025 16:58:34 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTP id 2914768D3D7; Wed, 2 Jul 2025 19:57:21 +0300 (EEST) Received: from btbn.de (btbn.de [144.76.60.213]) by ffbox0-bg.ffmpeg.org (Postfix) with ESMTPS id 70C0568D20B for ; Wed, 2 Jul 2025 19:57:11 +0300 (EEST) Received: from [authenticated] by btbn.de (Postfix) with ESMTPSA id 5EFFE27FFCCB1; Wed, 02 Jul 2025 18:57:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rothenpieler.org; s=mail; t=1751475428; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JyiaZJAuBqKx13x9VWJJQirVGZWs5hwoxzRvkrX6CJo=; b=ZR+TaxO5jdlJejQJp6wTN7Wf6e7q4Rh0mbJRvNeq9k6dgIYMm3UavzMKWDwYs9K2IaQ4Im 9oFGCW1CUOt3IL8MdbjEpoyo8jp4jdf+gdChmHKbLiuetxEhOgLCKDofafmDFrsp9c287f b8k8ZvPBjL3Qz9hYAckG0izGLTf7HDwDyMkyJ6v98qZ0DOeLVaf4ojtpz4YJuHG+sFlv6a IrcrBx80ta6/Ma/5JWxokA6wAknhA5pGAlk5cBjjyFDlPQgayK4eWMjnp0OHArt6ay7bjR 6PKRQKm7NwXsaZhMbtHQs9WxO6mNu/gOSYTQLjWos/4Y1O2L2f+GH6vNbgiS+A== From: Timo Rothenpieler To: ffmpeg-devel@ffmpeg.org Date: Wed, 2 Jul 2025 18:56:41 +0200 Message-ID: <20250702165655.1325-14-timo@rothenpieler.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250702165655.1325-1-timo@rothenpieler.org> References: <20250702165655.1325-1-timo@rothenpieler.org> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/18] avformat/udp: add function to set remote address directly 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: Timo Rothenpieler 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: --- 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".