summarylogtreecommitdiffstats
path: root/bind_iface.patch
blob: c11e099d593872f94ac49c39241766be639bd995 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
From 187466a01a80cc0d4af9fe13888d0232b39ca999 Mon Sep 17 00:00:00 2001
From: tytan652 <tytan652@tytanium.xyz>
Date: Thu, 11 Feb 2021 14:29:08 +0100
Subject: [PATCH 1/3] librtmp: Add interface binding for Linux

librtmp: Make log message more accurate
---
 plugins/obs-outputs/librtmp/rtmp.c | 19 ++++++++++++++++++-
 plugins/obs-outputs/librtmp/rtmp.h |  1 +
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/plugins/obs-outputs/librtmp/rtmp.c b/plugins/obs-outputs/librtmp/rtmp.c
index 88c7cff7cfb18..d063d268820f8 100644
--- a/plugins/obs-outputs/librtmp/rtmp.c
+++ b/plugins/obs-outputs/librtmp/rtmp.c
@@ -877,13 +877,30 @@ RTMP_Connect0(RTMP *r, struct sockaddr * service, socklen_t addrlen)
 #ifdef SO_NOSIGPIPE
         setsockopt(r->m_sb.sb_socket, SOL_SOCKET, SO_NOSIGPIPE, &(int){ 1 }, sizeof(int));
 #endif
+#endif
+
+#ifdef __linux__
+        if(r->m_bindInterface.av_len)
+        {
+            if (setsockopt(r->m_sb.sb_socket, SOL_SOCKET, SO_BINDTODEVICE,
+                           r->m_bindInterface.av_val,
+                           r->m_bindInterface.av_len) < 0)
+            {
+                int err = GetSockError();
+                RTMP_Log(RTMP_LOGERROR, "%s, failed to bind socket to interface: %s (%d)",
+                         __FUNCTION__, socketerror(err), err);
+                r->last_error_code = err;
+                RTMP_Close(r);
+                return FALSE;
+            }
+        }
 #endif
         if(r->m_bindIP.addrLen)
         {
             if (bind(r->m_sb.sb_socket, (const struct sockaddr *)&r->m_bindIP.addr, r->m_bindIP.addrLen) < 0)
             {
                 int err = GetSockError();
-                RTMP_Log(RTMP_LOGERROR, "%s, failed to bind socket: %s (%d)",
+                RTMP_Log(RTMP_LOGERROR, "%s, failed to bind socket to address: %s (%d)",
                          __FUNCTION__, socketerror(err), err);
                 r->last_error_code = err;
                 RTMP_Close(r);
diff --git a/plugins/obs-outputs/librtmp/rtmp.h b/plugins/obs-outputs/librtmp/rtmp.h
index b1c48e2f3a9f6..a900efbe17a0d 100644
--- a/plugins/obs-outputs/librtmp/rtmp.h
+++ b/plugins/obs-outputs/librtmp/rtmp.h
@@ -420,6 +420,7 @@ extern "C"
         void*   m_customSendParam;
         CUSTOMSEND m_customSendFunc;
 
+        AVal m_bindInterface;
         RTMP_BINDINFO m_bindIP;
 
         uint8_t m_bSendChunkSizeInfo;

From 5da8a83216852445be763a2f06432b2cd07bdfbf Mon Sep 17 00:00:00 2001
From: tytan652 <tytan652@tytanium.xyz>
Date: Thu, 11 Feb 2021 14:47:45 +0100
Subject: [PATCH 2/3] obs-outputs: Add RTMP iface binding for Linux

---
 plugins/obs-outputs/net-if.c      | 32 +++++++++++++++++++++++++++++
 plugins/obs-outputs/net-if.h      | 15 ++++++++++++++
 plugins/obs-outputs/rtmp-stream.c | 34 +++++++++++++++++++++++++++++++
 plugins/obs-outputs/rtmp-stream.h |  2 ++
 4 files changed, 83 insertions(+)

diff --git a/plugins/obs-outputs/net-if.c b/plugins/obs-outputs/net-if.c
index 29bb57d6a42bc..1587be47887b8 100644
--- a/plugins/obs-outputs/net-if.c
+++ b/plugins/obs-outputs/net-if.c
@@ -139,6 +139,38 @@ static inline bool is_loopback(struct ifaddrs *ifa)
 	return n && (strcmp(n, "lo") == 0 || strcmp(n, "lo0") == 0);
 }
 
+#ifdef __linux__
+void netif_get_ifaces(struct netif_siface_data *ifaces)
+{
+	da_init(ifaces->ifaces);
+
+	struct ifaddrs *ifaddr, *ifa;
+	unsigned int family;
+
+	if (getifaddrs(&ifaddr) == -1) {
+		warn("getifaddrs() failed");
+		return;
+	}
+
+	for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next) {
+		if (ifa->ifa_addr == NULL || is_loopback(ifa))
+			continue;
+		family = ifa->ifa_addr->sa_family;
+
+		if ((family == AF_INET) || (family == AF_INET6)) {
+			char *item;
+			char *iface_dup = bstrdup(ifa->ifa_name);
+
+			item = iface_dup;
+
+			da_push_back(ifaces->ifaces, &item);
+		}
+	}
+
+	freeifaddrs(ifaddr);
+}
+#endif
+
 static inline void netif_get_addrs_nix(struct netif_saddr_data *ifaddrs)
 {
 	struct ifaddrs *ifaddr, *ifa;
diff --git a/plugins/obs-outputs/net-if.h b/plugins/obs-outputs/net-if.h
index 757ee00e82781..6b045666cfba6 100644
--- a/plugins/obs-outputs/net-if.h
+++ b/plugins/obs-outputs/net-if.h
@@ -53,6 +53,21 @@
 
 #endif
 
+#ifdef __linux__
+struct netif_siface_data {
+	DARRAY(char *) ifaces;
+};
+
+static inline void netif_siface_data_free(struct netif_siface_data *data)
+{
+	for (size_t i = 0; i < data->ifaces.num; i++)
+		bfree(data->ifaces.array[i]);
+	da_free(data->ifaces);
+}
+
+extern void netif_get_ifaces(struct netif_siface_data *ifaces);
+#endif
+
 struct netif_saddr_item {
 	char *name;
 	char *addr;
diff --git a/plugins/obs-outputs/rtmp-stream.c b/plugins/obs-outputs/rtmp-stream.c
index 5a3773974112c..7e6cc577d52d5 100644
--- a/plugins/obs-outputs/rtmp-stream.c
+++ b/plugins/obs-outputs/rtmp-stream.c
@@ -125,6 +125,7 @@ static void rtmp_stream_destroy(void *data)
 	dstr_free(&stream->username);
 	dstr_free(&stream->password);
 	dstr_free(&stream->encoder_name);
+	dstr_free(&stream->bind_interface);
 	dstr_free(&stream->bind_ip);
 	os_event_destroy(stream->stop_event);
 	os_sem_destroy(stream->send_sem);
@@ -1067,6 +1068,17 @@ static int try_connect(struct rtmp_stream *stream)
 	stream->rtmp.Link.swfUrl = stream->rtmp.Link.tcUrl;
 	stream->rtmp.Link.customConnectEncode = add_connect_data;
 
+	if (dstr_is_empty(&stream->bind_interface) ||
+	    dstr_cmp(&stream->bind_interface, "default") == 0) {
+		memset(&stream->rtmp.m_bindInterface, 0,
+		       sizeof(stream->rtmp.m_bindInterface));
+	} else {
+		set_rtmp_dstr(&stream->rtmp.m_bindInterface,
+			      &stream->bind_interface);
+		info("Binding to interface %s",
+		     stream->rtmp.m_bindInterface.av_val);
+	}
+
 	if (dstr_is_empty(&stream->bind_ip) ||
 	    dstr_cmp(&stream->bind_ip, "default") == 0) {
 		memset(&stream->rtmp.m_bindIP, 0,
@@ -1109,6 +1121,7 @@ static bool init_connect(struct rtmp_stream *stream)
 {
 	obs_service_t *service;
 	obs_data_t *settings;
+	const char *bind_interface;
 	const char *bind_ip;
 	int64_t drop_p;
 	int64_t drop_b;
@@ -1180,6 +1193,9 @@ static bool init_connect(struct rtmp_stream *stream)
 	stream->drop_threshold_usec = 1000 * drop_b;
 	stream->pframe_drop_threshold_usec = 1000 * drop_p;
 
+	bind_interface = obs_data_get_string(settings, OPT_BIND_INTERFACE);
+	dstr_copy(&stream->bind_interface, bind_interface);
+
 	bind_ip = obs_data_get_string(settings, OPT_BIND_IP);
 	dstr_copy(&stream->bind_ip, bind_ip);
 
@@ -1568,6 +1584,9 @@ static obs_properties_t *rtmp_stream_properties(void *unused)
 	UNUSED_PARAMETER(unused);
 
 	obs_properties_t *props = obs_properties_create();
+#ifdef __linux__
+	struct netif_siface_data ifaces = {0};
+#endif
 	struct netif_saddr_data addrs = {0};
 	obs_property_t *p;
 
@@ -1575,6 +1594,21 @@ static obs_properties_t *rtmp_stream_properties(void *unused)
 				   obs_module_text("RTMPStream.DropThreshold"),
 				   200, 10000, 100);
 	obs_property_int_set_suffix(p, " ms");
+#ifdef __linux__
+	p = obs_properties_add_list(props, OPT_BIND_INTERFACE,
+				    obs_module_text("RTMPStream.BindInterface"),
+				    OBS_COMBO_TYPE_LIST,
+				    OBS_COMBO_FORMAT_STRING);
+
+	obs_property_list_add_string(p, obs_module_text("Default"), "default");
+
+	netif_get_ifaces(&ifaces);
+	for (size_t i = 0; i < ifaces.ifaces.num; i++) {
+		char *item = ifaces.ifaces.array[i];
+		obs_property_list_add_string(p, item, item);
+	}
+	netif_siface_data_free(&ifaces);
+#endif
 
 	p = obs_properties_add_list(props, OPT_BIND_IP,
 				    obs_module_text("RTMPStream.BindIP"),
diff --git a/plugins/obs-outputs/rtmp-stream.h b/plugins/obs-outputs/rtmp-stream.h
index bca991909d42a..474faab3ee7a0 100644
--- a/plugins/obs-outputs/rtmp-stream.h
+++ b/plugins/obs-outputs/rtmp-stream.h
@@ -28,6 +28,7 @@
 #define OPT_DROP_THRESHOLD "drop_threshold_ms"
 #define OPT_PFRAME_DROP_THRESHOLD "pframe_drop_threshold_ms"
 #define OPT_MAX_SHUTDOWN_TIME_SEC "max_shutdown_time_sec"
+#define OPT_BIND_INTERFACE "bind_interface"
 #define OPT_BIND_IP "bind_ip"
 #define OPT_NEWSOCKETLOOP_ENABLED "new_socket_loop_enabled"
 #define OPT_LOWLATENCY_ENABLED "low_latency_mode_enabled"
@@ -82,6 +83,7 @@ struct rtmp_stream {
 	struct dstr path, key;
 	struct dstr username, password;
 	struct dstr encoder_name;
+	struct dstr bind_interface;
 	struct dstr bind_ip;
 
 	/* frame drop variables */

From 07802b66747b5275f572bb6c551eb98fdb6d024a Mon Sep 17 00:00:00 2001
From: tytan652 <tytan652@tytanium.xyz>
Date: Thu, 11 Feb 2021 14:51:42 +0100
Subject: [PATCH 3/3] UI: Add interface binding property for Linux

---
 UI/data/locale/en-US.ini             |  1 +
 UI/forms/OBSBasicSettings.ui         | 24 ++++++--
 UI/window-basic-auto-config-test.cpp |  3 +
 UI/window-basic-main-outputs.cpp     |  6 ++
 UI/window-basic-main.cpp             |  2 +
 UI/window-basic-settings.cpp         | 91 +++++++++++++++++++++++++++-
 UI/window-basic-settings.hpp         |  3 +
 7 files changed, 123 insertions(+), 7 deletions(-)

diff --git a/UI/data/locale/en-US.ini b/UI/data/locale/en-US.ini
index 06361584c96cb..8104e3bf47548 100644
--- a/UI/data/locale/en-US.ini
+++ b/UI/data/locale/en-US.ini
@@ -1154,6 +1154,7 @@ Basic.Settings.Advanced.StreamDelay.Preserve="Preserve cutoff point (increase de
 Basic.Settings.Advanced.StreamDelay.MemoryUsage="Estimated Memory Usage: %1 MB"
 Basic.Settings.Advanced.Network="Network"
 Basic.Settings.Advanced.Network.Disabled="The currently selected streaming protocol does not support changing network settings."
+Basic.Settings.Advanced.Network.BindToInterface="Bind to interface"
 Basic.Settings.Advanced.Network.BindToIP="Bind to IP"
 Basic.Settings.Advanced.Network.EnableNewSocketLoop="Enable network optimizations"
 Basic.Settings.Advanced.Network.EnableLowLatencyMode="Enable TCP pacing"
diff --git a/UI/forms/OBSBasicSettings.ui b/UI/forms/OBSBasicSettings.ui
index 4552856e7a88c..4efb6dcfa5a36 100644
--- a/UI/forms/OBSBasicSettings.ui
+++ b/UI/forms/OBSBasicSettings.ui
@@ -7267,6 +7267,19 @@
                     </widget>
                    </item>
                    <item row="1" column="0">
+                    <widget class="QLabel" name="bindToIfaceLabel">
+                     <property name="text">
+                      <string>Basic.Settings.Advanced.Network.BindToInterface</string>
+                     </property>
+                     <property name="buddy">
+                      <cstring>bindToInterface</cstring>
+                     </property>
+                    </widget>
+                   </item>
+                   <item row="1" column="1">
+                    <widget class="QComboBox" name="bindToInterface"/>
+                   </item>
+                   <item row="2" column="0">
                     <widget class="QLabel" name="bindToIPLabel">
                      <property name="text">
                       <string>Basic.Settings.Advanced.Network.BindToIP</string>
@@ -7276,17 +7289,17 @@
                      </property>
                     </widget>
                    </item>
-                   <item row="1" column="1">
+                   <item row="2" column="1">
                     <widget class="QComboBox" name="bindToIP"/>
                    </item>
-                   <item row="3" column="1">
+                   <item row="4" column="1">
                     <widget class="QCheckBox" name="enableNewSocketLoop">
                      <property name="text">
                       <string>Basic.Settings.Advanced.Network.EnableNewSocketLoop</string>
                      </property>
                     </widget>
                    </item>
-                   <item row="4" column="1">
+                   <item row="5" column="1">
                     <widget class="QCheckBox" name="enableLowLatencyMode">
                      <property name="enabled">
                       <bool>false</bool>
@@ -7296,7 +7309,7 @@
                      </property>
                     </widget>
                    </item>
-                   <item row="3" column="0">
+                   <item row="4" column="0">
                     <spacer name="horizontalSpacer_7">
                      <property name="orientation">
                       <enum>Qt::Horizontal</enum>
@@ -7309,7 +7322,7 @@
                      </property>
                     </spacer>
                    </item>
-                   <item row="2" column="1">
+                   <item row="3" column="1">
                     <widget class="QCheckBox" name="dynBitrate">
                      <property name="toolTip">
                       <string>Basic.Settings.Output.DynamicBitrate.TT</string>
@@ -7620,6 +7633,7 @@
   <tabstop>reconnectRetryDelay</tabstop>
   <tabstop>reconnectMaxRetries</tabstop>
   <tabstop>bindToIP</tabstop>
+  <tabstop>bindToInterface</tabstop>
   <tabstop>dynBitrate</tabstop>
   <tabstop>enableNewSocketLoop</tabstop>
   <tabstop>enableLowLatencyMode</tabstop>
diff --git a/UI/window-basic-auto-config-test.cpp b/UI/window-basic-auto-config-test.cpp
index 17b15e33b6f7a..8757a11fff40e 100644
--- a/UI/window-basic-auto-config-test.cpp
+++ b/UI/window-basic-auto-config-test.cpp
@@ -228,6 +228,9 @@ void AutoConfigTestPage::TestBandwidthThread()
 	obs_data_set_int(aencoder_settings, "bitrate", 32);
 
 	OBSBasic *main = reinterpret_cast<OBSBasic *>(App()->GetMainWindow());
+	const char *bind_interface =
+		config_get_string(main->Config(), "Output", "BindInterface");
+	obs_data_set_string(output_settings, "bind_interface", bind_interface);
 	const char *bind_ip =
 		config_get_string(main->Config(), "Output", "BindIP");
 	obs_data_set_string(output_settings, "bind_ip", bind_ip);
diff --git a/UI/window-basic-main-outputs.cpp b/UI/window-basic-main-outputs.cpp
index 39e2ff84f0765..60b66818222bd 100644
--- a/UI/window-basic-main-outputs.cpp
+++ b/UI/window-basic-main-outputs.cpp
@@ -928,6 +928,8 @@ bool SimpleOutput::StartStreaming(obs_service_t *service)
 	int delaySec = config_get_int(main->Config(), "Output", "DelaySec");
 	bool preserveDelay =
 		config_get_bool(main->Config(), "Output", "DelayPreserve");
+	const char *bindInterface =
+		config_get_string(main->Config(), "Output", "BindInterface");
 	const char *bindIP =
 		config_get_string(main->Config(), "Output", "BindIP");
 	bool enableNewSocketLoop = config_get_bool(main->Config(), "Output",
@@ -938,6 +940,7 @@ bool SimpleOutput::StartStreaming(obs_service_t *service)
 		config_get_bool(main->Config(), "Output", "DynamicBitrate");
 
 	OBSDataAutoRelease settings = obs_data_create();
+	obs_data_set_string(settings, "bind_interface", bindInterface);
 	obs_data_set_string(settings, "bind_ip", bindIP);
 	obs_data_set_bool(settings, "new_socket_loop_enabled",
 			  enableNewSocketLoop);
@@ -1827,6 +1830,8 @@ bool AdvancedOutput::StartStreaming(obs_service_t *service)
 	int delaySec = config_get_int(main->Config(), "Output", "DelaySec");
 	bool preserveDelay =
 		config_get_bool(main->Config(), "Output", "DelayPreserve");
+	const char *bindInterface =
+		config_get_string(main->Config(), "Output", "BindInterface");
 	const char *bindIP =
 		config_get_string(main->Config(), "Output", "BindIP");
 	bool enableNewSocketLoop = config_get_bool(main->Config(), "Output",
@@ -1837,6 +1842,7 @@ bool AdvancedOutput::StartStreaming(obs_service_t *service)
 		config_get_bool(main->Config(), "Output", "DynamicBitrate");
 
 	OBSDataAutoRelease settings = obs_data_create();
+	obs_data_set_string(settings, "bind_interface", bindInterface);
 	obs_data_set_string(settings, "bind_ip", bindIP);
 	obs_data_set_bool(settings, "new_socket_loop_enabled",
 			  enableNewSocketLoop);
diff --git a/UI/window-basic-main.cpp b/UI/window-basic-main.cpp
index a726316957259..3354feda8bd01 100644
--- a/UI/window-basic-main.cpp
+++ b/UI/window-basic-main.cpp
@@ -1464,6 +1464,8 @@ bool OBSBasic::InitBasicConfigDefaults()
 	config_set_default_uint(basicConfig, "Output", "RetryDelay", 2);
 	config_set_default_uint(basicConfig, "Output", "MaxRetries", 25);
 
+	config_set_default_string(basicConfig, "Output", "BindInterface",
+				  "default");
 	config_set_default_string(basicConfig, "Output", "BindIP", "default");
 	config_set_default_bool(basicConfig, "Output", "NewSocketLoopEnable",
 				false);
diff --git a/UI/window-basic-settings.cpp b/UI/window-basic-settings.cpp
index 2c4c8a8592191..145f64cbfb0dc 100644
--- a/UI/window-basic-settings.cpp
+++ b/UI/window-basic-settings.cpp
@@ -560,6 +560,9 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
 	HookWidget(ui->reconnectMaxRetries,  SCROLL_CHANGED, ADV_CHANGED);
 	HookWidget(ui->processPriority,      COMBO_CHANGED,  ADV_CHANGED);
 	HookWidget(ui->confirmOnExit,        CHECK_CHANGED,  ADV_CHANGED);
+#ifdef __linux__
+	HookWidget(ui->bindToInterface,      COMBO_CHANGED,  ADV_CHANGED);
+#endif
 	HookWidget(ui->bindToIP,             COMBO_CHANGED,  ADV_CHANGED);
 	HookWidget(ui->enableNewSocketLoop,  CHECK_CHANGED,  ADV_CHANGED);
 	HookWidget(ui->enableLowLatencyMode, CHECK_CHANGED,  ADV_CHANGED);
@@ -674,6 +677,13 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
 	ui->resetOSXVSync = nullptr;
 #endif
 
+#ifndef __linux__
+	delete ui->bindToIfaceLabel;
+	delete ui->bindToInterface;
+	ui->bindToIfaceLabel = nullptr;
+	ui->bindToInterface = nullptr;
+#endif
+
 	connect(ui->streamDelaySec, SIGNAL(valueChanged(int)), this,
 		SLOT(UpdateStreamDelayEstimate()));
 	connect(ui->outputMode, SIGNAL(currentIndexChanged(int)), this,
@@ -825,9 +835,37 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
 		SLOT(AdvReplayBufferChanged()));
 	connect(ui->listWidget, SIGNAL(currentRowChanged(int)), this,
 		SLOT(SimpleRecordingEncoderChanged()));
+#ifdef __linux__
+	connect(ui->bindToInterface, SIGNAL(currentIndexChanged(int)), this,
+		SLOT(UpdateAddrList()));
 
-	// Get Bind to IP Addresses
+	ui->bindToIP->setEnabled(false);
+#endif
+
+	// Get Bind to interfaces Interfaces (Linux only)
+	// Get Bind to IP Addresses (Others)
 	obs_properties_t *ppts = obs_get_output_properties("rtmp_output");
+#ifdef __linux__
+	obs_property_t *p_iface = obs_properties_get(ppts, "bind_interface");
+	QStringList dedup_iface = {};
+
+	ui->bindToInterface->blockSignals(true);
+
+	size_t count_iface = obs_property_list_item_count(p_iface);
+	for (size_t i = 0; i < count_iface; i++) {
+		const char *name = obs_property_list_item_name(p_iface, i);
+		const char *val = obs_property_list_item_string(p_iface, i);
+
+		// Add interfaces without duplicates
+		if (!dedup_iface.contains(QT_UTF8(name))) {
+			dedup_iface.append(QT_UTF8(name));
+			ui->bindToInterface->addItem(QT_UTF8(name), val);
+		}
+	}
+
+	UpdateAddrList();
+	ui->bindToInterface->blockSignals(false);
+#else
 	obs_property_t *p = obs_properties_get(ppts, "bind_ip");
 
 	size_t count = obs_property_list_item_count(p);
@@ -837,7 +875,7 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
 
 		ui->bindToIP->addItem(QT_UTF8(name), val);
 	}
-
+#endif
 	obs_properties_destroy(ppts);
 
 	InitStreamPage();
@@ -2609,6 +2647,10 @@ void OBSBasicSettings::LoadAdvancedSettings()
 						 "FilenameFormatting");
 	bool overwriteIfExists =
 		config_get_bool(main->Config(), "Output", "OverwriteIfExists");
+#ifdef __linux__
+	const char *bindInterface =
+		config_get_string(main->Config(), "Output", "BindInterface");
+#endif
 	const char *bindIP =
 		config_get_string(main->Config(), "Output", "BindIP");
 	const char *rbPrefix = config_get_string(main->Config(), "SimpleOutput",
@@ -2662,6 +2704,12 @@ void OBSBasicSettings::LoadAdvancedSettings()
 	ui->sdrWhiteLevel->setValue(sdrWhiteLevel);
 	ui->hdrNominalPeakLevel->setValue(hdrNominalPeakLevel);
 
+#ifdef __linux__
+	if (!SetComboByValue(ui->bindToInterface, bindInterface))
+		SetInvalidValue(ui->bindToInterface, bindInterface,
+				bindInterface);
+#endif
+
 	if (!SetComboByValue(ui->bindToIP, bindIP))
 		SetInvalidValue(ui->bindToIP, bindIP, bindIP);
 
@@ -3383,6 +3431,9 @@ void OBSBasicSettings::SaveAdvancedSettings()
 	SaveCheckBox(ui->reconnectEnable, "Output", "Reconnect");
 	SaveSpinBox(ui->reconnectRetryDelay, "Output", "RetryDelay");
 	SaveSpinBox(ui->reconnectMaxRetries, "Output", "MaxRetries");
+#ifdef __linux__
+	SaveComboData(ui->bindToInterface, "Output", "BindInterface");
+#endif
 	SaveComboData(ui->bindToIP, "Output", "BindIP");
 	SaveCheckBox(ui->autoRemux, "Video", "AutoRemux");
 	SaveCheckBox(ui->dynBitrate, "Output", "DynamicBitrate");
@@ -5429,5 +5480,41 @@ void OBSBasicSettings::UpdateAdvNetworkGroup()
 #ifdef _WIN32
 	ui->enableNewSocketLoop->setVisible(enabled);
 	ui->enableLowLatencyMode->setVisible(enabled);
+#elif defined(__linux__)
+	ui->bindToIfaceLabel->setVisible(enabled);
+	ui->bindToInterface->setVisible(enabled);
 #endif
 }
+
+#ifdef __linux__
+void OBSBasicSettings::UpdateAddrList()
+{
+	ui->bindToIP->clear();
+
+	// Get Bind to IP Addresses (Linux only)
+	obs_properties_t *ppts = obs_get_output_properties("rtmp_output");
+	obs_property_t *p = obs_properties_get(ppts, "bind_ip");
+
+	size_t count_addr = obs_property_list_item_count(p);
+	for (size_t i = 0; i < count_addr; i++) {
+		const char *name = obs_property_list_item_name(p, i);
+		const char *val = obs_property_list_item_string(p, i);
+
+		//Put only the addresses from the selected interface
+		if (QT_UTF8(name).contains(
+			    ui->bindToInterface->currentText()) ||
+		    QT_UTF8(val).contains("default"))
+			ui->bindToIP->addItem(QT_UTF8(name), val);
+	}
+
+	obs_properties_destroy(ppts);
+
+	if (ui->bindToInterface->currentIndex() > 0) {
+		ui->bindToIP->setEnabled(true);
+	} else {
+		ui->bindToIP->setEnabled(false);
+		if (!SetComboByValue(ui->bindToIP, "default"))
+			SetInvalidValue(ui->bindToIP, "default", "default");
+	}
+}
+#endif
diff --git a/UI/window-basic-settings.hpp b/UI/window-basic-settings.hpp
index 2431cb056241f..da6ed56ac369d 100644
--- a/UI/window-basic-settings.hpp
+++ b/UI/window-basic-settings.hpp
@@ -464,6 +464,9 @@ private slots:
 	void SetHotkeysIcon(const QIcon &icon);
 	void SetAccessibilityIcon(const QIcon &icon);
 	void SetAdvancedIcon(const QIcon &icon);
+#ifdef __linux__
+	void UpdateAddrList();
+#endif
 
 	void UseStreamKeyAdvClicked();