PR #21655 opened by Rost Kurylo (rost.kurylo)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21655
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/21655.patch

Sockets of type SOCK_DGRAM don't support listen(), so it was
impossible to read from "unixgram" sockets in ffmpeg.

To test:

```
ffmpeg -type datagram -listen 1 -i 'unix:/tmp/test' -map 0 -f null -
```

With this change, listen() won't be called on the socket, but semantics similar 
to SOCK_STREAM are preserved (create a socket file, bind to it, receive 
packets).

Signed-off-by: Rost Kurylo <[email protected]>


>From e5fc29385eef58372e86001f80f996ecaeed4687 Mon Sep 17 00:00:00 2001
From: Rost Kurylo <[email protected]>
Date: Wed, 4 Feb 2026 10:07:50 -0800
Subject: [PATCH] avformat/unix: Fix 'operation unsupported' error when reading
 from unixgram sockets

Sockets of type SOCK_DGRAM don't support listen(), so it was
impossible to read from "unixgram" sockets in ffmpeg.

Signed-off-by: Rost Kurylo <[email protected]>
---
 libavformat/unix.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/libavformat/unix.c b/libavformat/unix.c
index 3a0caf96ed..ac6a18c48d 100644
--- a/libavformat/unix.c
+++ b/libavformat/unix.c
@@ -78,11 +78,19 @@ static int unix_open(URLContext *h, const char *filename, 
int flags)
         s->timeout = h->rw_timeout / 1000;
 
     if (s->listen) {
-        ret = ff_listen_bind(fd, (struct sockaddr *)&s->addr,
-                             sizeof(s->addr), s->timeout, h);
-        if (ret < 0)
-            goto fail;
-        fd = ret;
+        if (s->type == SOCK_DGRAM) {
+            ret = bind(fd, (struct sockaddr *)&s->addr, sizeof(s->addr));
+            if (ret) {
+                ret = ff_neterrno();
+                goto fail;
+            }
+        } else {
+            ret = ff_listen_bind(fd, (struct sockaddr *)&s->addr,
+                                sizeof(s->addr), s->timeout, h);
+            if (ret < 0)
+                goto fail;
+            fd = ret;
+        }
     } else {
         ret = ff_listen_connect(fd, (struct sockaddr *)&s->addr,
                                 sizeof(s->addr), s->timeout, h, 0);
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to