summarylogtreecommitdiffstats
path: root/bind_iface.patch
blob: 0b0abe7b7e3ad9529ae61d3f757add7958514b3a (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
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
From 8f8670c02e1df91343985b4ed59bb55135fae966 Mon Sep 17 00:00:00 2001
From: tytan652 <tytan652@tytanium.xyz>
Date: Thu, 11 Feb 2021 14:29:08 +0100
Subject: [PATCH 1/5] 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 70e42f7ee636..7c5346c07a42 100644
--- a/plugins/obs-outputs/librtmp/rtmp.c
+++ b/plugins/obs-outputs/librtmp/rtmp.c
@@ -874,13 +874,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 5020120ee3ee..8a6f64375ffb 100644
--- a/plugins/obs-outputs/librtmp/rtmp.h
+++ b/plugins/obs-outputs/librtmp/rtmp.h
@@ -423,6 +423,7 @@ extern "C"
         void*   m_customSendParam;
         CUSTOMSEND m_customSendFunc;
 
+        AVal m_bindInterface;
         RTMP_BINDINFO m_bindIP;
 
         uint8_t m_bSendChunkSizeInfo;

From 6326cc5bb4256556e545c1f7c6679a422883d364 Mon Sep 17 00:00:00 2001
From: tytan652 <tytan652@tytanium.xyz>
Date: Thu, 11 Feb 2021 14:47:45 +0100
Subject: [PATCH 2/5] 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 | 36 +++++++++++++++++++++++++++++++
 plugins/obs-outputs/rtmp-stream.h |  2 ++
 4 files changed, 85 insertions(+)

diff --git a/plugins/obs-outputs/net-if.c b/plugins/obs-outputs/net-if.c
index 40891ef3d233..206394ff175c 100644
--- a/plugins/obs-outputs/net-if.c
+++ b/plugins/obs-outputs/net-if.c
@@ -134,6 +134,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 757ee00e8278..6b045666cfba 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 e2223a8690fb..5e5235afe67d 100644
--- a/plugins/obs-outputs/rtmp-stream.c
+++ b/plugins/obs-outputs/rtmp-stream.c
@@ -122,6 +122,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);
@@ -1039,6 +1040,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,
@@ -1081,6 +1093,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;
@@ -1152,6 +1165,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);
 
@@ -1540,12 +1556,32 @@ 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};
+	obs_property_t *p_iface;
+#endif
 	struct netif_saddr_data addrs = {0};
 	obs_property_t *p;
 
 	obs_properties_add_int(props, OPT_DROP_THRESHOLD,
 			       obs_module_text("RTMPStream.DropThreshold"), 200,
 			       10000, 100);
+#ifdef __linux__
+	p_iface = 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_iface, 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_iface, 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 bca991909d42..474faab3ee7a 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 a6631eaf77dfa5be1bbab8dee0005504f81f53d4 Mon Sep 17 00:00:00 2001
From: tytan652 <tytan652@tytanium.xyz>
Date: Thu, 11 Feb 2021 14:51:42 +0100
Subject: [PATCH 3/5] 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         | 42 ++++++++++++++++++++++++++++
 6 files changed, 73 insertions(+), 5 deletions(-)

diff --git a/UI/data/locale/en-US.ini b/UI/data/locale/en-US.ini
index 8a2413c65c99..3cba5cbfcb27 100644
--- a/UI/data/locale/en-US.ini
+++ b/UI/data/locale/en-US.ini
@@ -1039,6 +1039,7 @@ Basic.Settings.Advanced.StreamDelay.Duration="Duration"
 Basic.Settings.Advanced.StreamDelay.Preserve="Preserve cutoff point (increase delay) when reconnecting"
 Basic.Settings.Advanced.StreamDelay.MemoryUsage="Estimated Memory Usage: %1 MB"
 Basic.Settings.Advanced.Network="Network"
+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 87da1c95bb01..cad29dc04283 100644
--- a/UI/forms/OBSBasicSettings.ui
+++ b/UI/forms/OBSBasicSettings.ui
@@ -5443,6 +5443,19 @@
                     <number>2</number>
                    </property>
                    <item row="0" 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="0" column="1">
+                    <widget class="QComboBox" name="bindToInterface"/>
+                   </item>
+                   <item row="1" column="0">
                     <widget class="QLabel" name="label_27">
                      <property name="text">
                       <string>Basic.Settings.Advanced.Network.BindToIP</string>
@@ -5452,17 +5465,17 @@
                      </property>
                     </widget>
                    </item>
-                   <item row="0" column="1">
+                   <item row="1" column="1">
                     <widget class="QComboBox" name="bindToIP"/>
                    </item>
-                   <item row="2" column="1">
+                   <item row="3" column="1">
                     <widget class="QCheckBox" name="enableNewSocketLoop">
                      <property name="text">
                       <string>Basic.Settings.Advanced.Network.EnableNewSocketLoop</string>
                      </property>
                     </widget>
                    </item>
-                   <item row="3" column="1">
+                   <item row="4" column="1">
                     <widget class="QCheckBox" name="enableLowLatencyMode">
                      <property name="enabled">
                       <bool>false</bool>
@@ -5472,7 +5485,7 @@
                      </property>
                     </widget>
                    </item>
-                   <item row="2" column="0">
+                   <item row="3" column="0">
                     <spacer name="horizontalSpacer_7">
                      <property name="orientation">
                       <enum>Qt::Horizontal</enum>
@@ -5485,7 +5498,7 @@
                      </property>
                     </spacer>
                    </item>
-                   <item row="1" column="1">
+                   <item row="2" column="1">
                     <widget class="QCheckBox" name="dynBitrate">
                      <property name="toolTip">
                       <string>Basic.Settings.Output.DynamicBitrate.TT</string>
@@ -5827,6 +5840,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 4208efe67940..1ac13e60209e 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 d4351f7f6e55..9ad3a294aa63 100644
--- a/UI/window-basic-main-outputs.cpp
+++ b/UI/window-basic-main-outputs.cpp
@@ -882,6 +882,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",
@@ -892,6 +894,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);
@@ -1771,6 +1774,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",
@@ -1781,6 +1786,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 fa172ce5ef41..ed8fead412c6 100644
--- a/UI/window-basic-main.cpp
+++ b/UI/window-basic-main.cpp
@@ -1436,6 +1436,8 @@ bool OBSBasic::InitBasicConfigDefaults()
 	config_set_default_uint(basicConfig, "Output", "RetryDelay", 10);
 	config_set_default_uint(basicConfig, "Output", "MaxRetries", 20);
 
+	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 02eb3ca071b6..c01497a1f8c6 100644
--- a/UI/window-basic-settings.cpp
+++ b/UI/window-basic-settings.cpp
@@ -552,6 +552,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);
@@ -667,6 +670,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,
@@ -813,10 +823,29 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
 	connect(ui->listWidget, SIGNAL(currentRowChanged(int)), this,
 		SLOT(SimpleRecordingEncoderChanged()));
 
+	// Get Bind to interfaces Interfaces (Linux only)
 	// Get Bind to IP Addresses
 	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 = {};
+#endif
 	obs_property_t *p = obs_properties_get(ppts, "bind_ip");
 
+#ifdef __linux__
+	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);
+		}
+	}
+#endif
+
 	size_t count = obs_property_list_item_count(p);
 	for (size_t i = 0; i < count; i++) {
 		const char *name = obs_property_list_item_name(p, i);
@@ -2517,6 +2546,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",
@@ -2568,6 +2601,12 @@ void OBSBasicSettings::LoadAdvancedSettings()
 	SetComboByName(ui->colorSpace, videoColorSpace);
 	SetComboByValue(ui->colorRange, videoColorRange);
 
+#ifdef __linux__
+	if (!SetComboByValue(ui->bindToInterface, bindInterface))
+		SetInvalidValue(ui->bindToInterface, bindInterface,
+				bindInterface);
+#endif
+
 	if (!SetComboByValue(ui->bindToIP, bindIP))
 		SetInvalidValue(ui->bindToIP, bindIP, bindIP);
 
@@ -3299,6 +3338,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");

From 8dae0ab3bedcd9ac5f843ff2ef8c9a0a37f1e20b Mon Sep 17 00:00:00 2001
From: tytan652 <tytan652@tytanium.xyz>
Date: Thu, 11 Feb 2021 14:53:55 +0100
Subject: [PATCH 4/5] UI,obs-outputs: Rename bind IP property variables

---
 UI/window-basic-settings.cpp      | 10 +++++-----
 plugins/obs-outputs/rtmp-stream.c | 15 ++++++++-------
 2 files changed, 13 insertions(+), 12 deletions(-)

diff --git a/UI/window-basic-settings.cpp b/UI/window-basic-settings.cpp
index c01497a1f8c6..c8712e6cb627 100644
--- a/UI/window-basic-settings.cpp
+++ b/UI/window-basic-settings.cpp
@@ -830,7 +830,7 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
 	obs_property_t *p_iface = obs_properties_get(ppts, "bind_interface");
 	QStringList dedup_iface = {};
 #endif
-	obs_property_t *p = obs_properties_get(ppts, "bind_ip");
+	obs_property_t *p_addr = obs_properties_get(ppts, "bind_ip");
 
 #ifdef __linux__
 	size_t count_iface = obs_property_list_item_count(p_iface);
@@ -846,10 +846,10 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
 	}
 #endif
 
-	size_t count = obs_property_list_item_count(p);
-	for (size_t i = 0; i < count; i++) {
-		const char *name = obs_property_list_item_name(p, i);
-		const char *val = obs_property_list_item_string(p, i);
+	size_t count_addr = obs_property_list_item_count(p_addr);
+	for (size_t i = 0; i < count_addr; i++) {
+		const char *name = obs_property_list_item_name(p_addr, i);
+		const char *val = obs_property_list_item_string(p_addr, i);
 
 		ui->bindToIP->addItem(QT_UTF8(name), val);
 	}
diff --git a/plugins/obs-outputs/rtmp-stream.c b/plugins/obs-outputs/rtmp-stream.c
index 5e5235afe67d..834af5e0c02c 100644
--- a/plugins/obs-outputs/rtmp-stream.c
+++ b/plugins/obs-outputs/rtmp-stream.c
@@ -1561,7 +1561,7 @@ static obs_properties_t *rtmp_stream_properties(void *unused)
 	obs_property_t *p_iface;
 #endif
 	struct netif_saddr_data addrs = {0};
-	obs_property_t *p;
+	obs_property_t *p_addr;
 
 	obs_properties_add_int(props, OPT_DROP_THRESHOLD,
 			       obs_module_text("RTMPStream.DropThreshold"), 200,
@@ -1583,17 +1583,18 @@ static obs_properties_t *rtmp_stream_properties(void *unused)
 	netif_siface_data_free(&ifaces);
 #endif
 
-	p = obs_properties_add_list(props, OPT_BIND_IP,
-				    obs_module_text("RTMPStream.BindIP"),
-				    OBS_COMBO_TYPE_LIST,
-				    OBS_COMBO_FORMAT_STRING);
+	p_addr = obs_properties_add_list(props, OPT_BIND_IP,
+					 obs_module_text("RTMPStream.BindIP"),
+					 OBS_COMBO_TYPE_LIST,
+					 OBS_COMBO_FORMAT_STRING);
 
-	obs_property_list_add_string(p, obs_module_text("Default"), "default");
+	obs_property_list_add_string(p_addr, obs_module_text("Default"),
+				     "default");
 
 	netif_get_addrs(&addrs);
 	for (size_t i = 0; i < addrs.addrs.num; i++) {
 		struct netif_saddr_item item = addrs.addrs.array[i];
-		obs_property_list_add_string(p, item.name, item.addr);
+		obs_property_list_add_string(p_addr, item.name, item.addr);
 	}
 	netif_saddr_data_free(&addrs);
 

From bbbafbe6ccc0b0add51dceeb7afceca6447b653a Mon Sep 17 00:00:00 2001
From: tytan652 <tytan652@tytanium.xyz>
Date: Mon, 15 Feb 2021 11:37:56 +0100
Subject: [PATCH 5/5] UI: Disable bind IP if no iface selected on Linux

---
 UI/window-basic-settings.cpp | 54 ++++++++++++++++++++++++++++++++----
 UI/window-basic-settings.hpp |  3 ++
 2 files changed, 51 insertions(+), 6 deletions(-)

diff --git a/UI/window-basic-settings.cpp b/UI/window-basic-settings.cpp
index c8712e6cb627..0509f1af00d9 100644
--- a/UI/window-basic-settings.cpp
+++ b/UI/window-basic-settings.cpp
@@ -822,17 +822,22 @@ 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()));
+
+	ui->bindToIP->setEnabled(false);
+#endif
 
 	// Get Bind to interfaces Interfaces (Linux only)
-	// Get Bind to IP Addresses
+	// 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 = {};
-#endif
-	obs_property_t *p_addr = obs_properties_get(ppts, "bind_ip");
 
-#ifdef __linux__
+	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);
@@ -844,7 +849,11 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
 			ui->bindToInterface->addItem(QT_UTF8(name), val);
 		}
 	}
-#endif
+
+	UpdateAddrList();
+	ui->bindToInterface->blockSignals(false);
+#else
+	obs_property_t *p_addr = obs_properties_get(ppts, "bind_ip");
 
 	size_t count_addr = obs_property_list_item_count(p_addr);
 	for (size_t i = 0; i < count_addr; i++) {
@@ -853,7 +862,7 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent)
 
 		ui->bindToIP->addItem(QT_UTF8(name), val);
 	}
-
+#endif
 	obs_properties_destroy(ppts);
 
 	InitStreamPage();
@@ -5217,3 +5226,36 @@ void OBSBasicSettings::RecreateOutputResolutionWidget()
 	ui->outputResolution->lineEdit()->setValidator(
 		ui->baseResolution->lineEdit()->validator());
 }
+
+#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_addr = obs_properties_get(ppts, "bind_ip");
+
+	size_t count_addr = obs_property_list_item_count(p_addr);
+	for (size_t i = 0; i < count_addr; i++) {
+		const char *name = obs_property_list_item_name(p_addr, i);
+		const char *val = obs_property_list_item_string(p_addr, 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 4c66bc210d8c..6bc445d9306e 100644
--- a/UI/window-basic-settings.hpp
+++ b/UI/window-basic-settings.hpp
@@ -409,6 +409,9 @@ private slots:
 	void SetVideoIcon(const QIcon &icon);
 	void SetHotkeysIcon(const QIcon &icon);
 	void SetAdvancedIcon(const QIcon &icon);
+#ifdef __linux__
+	void UpdateAddrList();
+#endif
 
 	void UseStreamKeyAdvClicked();