summaryrefslogtreecommitdiffstats
path: root/package/busybox/patches/110-telnetd.patch
blob: e95757ee4ed80ec034ed730c285836cf9bd8ce06 (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
diff -urN busybox-1.00-pre8/networking/telnetd.c busybox-1.00-pre8-openwrt/networking/telnetd.c
--- busybox-1.00-pre8/networking/telnetd.c	2004-02-22 03:45:57.000000000 -0600
+++ busybox-1.00-pre8-openwrt/networking/telnetd.c	2004-03-05 01:32:57.000000000 -0600
@@ -44,6 +44,8 @@
 #include <arpa/telnet.h>
 #include <ctype.h>
 #include <sys/syslog.h>
+#include <net/if.h>
+
 
 #include "busybox.h"
 
@@ -384,11 +386,13 @@
 	int portnbr = 23;
 #endif /* CONFIG_FEATURE_TELNETD_INETD */
 	int c;
+	char *interface_name = NULL;
+	struct ifreq interface;
 	static const char options[] =
 #ifdef CONFIG_FEATURE_TELNETD_INETD
-		"f:l:";
-#else /* CONFIG_EATURE_TELNETD_INETD */
-		"f:l:p:";
+		"i:f:l:";
+#else /* CONFIG_FEATURE_TELNETD_INETD */
+		"i:f:l:p:";
 #endif /* CONFIG_FEATURE_TELNETD_INETD */
 	int maxlen, w, r;
 
@@ -403,6 +407,9 @@
 			case 'f':
 				issuefile = strdup (optarg);
 				break;
+                        case 'i':
+                                interface_name = strdup(optarg);
+                                break;
 			case 'l':
 				loginpath = strdup (optarg);
 				break;
@@ -442,6 +449,13 @@
 	sa.sin_family = AF_INET;
 	sa.sin_port = htons(portnbr);
 
+        /* Set it to listen on the specified interface */
+        if (interface_name) {
+                strncpy(interface.ifr_ifrn.ifrn_name, interface_name, IFNAMSIZ);
+                (void)setsockopt(master_fd, SOL_SOCKET,
+                                SO_BINDTODEVICE, &interface, sizeof(interface));
+        }
+
 	if (bind(master_fd, (struct sockaddr *) &sa, sizeof(sa)) < 0) {
 		bb_perror_msg_and_die("bind");
 	}